Results 1 to 2 of 2

Thread: [Regex] Reading Visual Studio Solution file

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    [Regex] Reading Visual Studio Solution file

    Hi,


    I need to read a Visual Studio Solution file (.SLN files) to figure out which projects belong to this solution.

    By opening a SLN file in notepad, one can see that the projects are stored like this:
    Code:
    Microsoft Visual Studio Solution File, Format Version 11.00
    # Visual Studio 2010
    Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RadioGadget", "RadioGadget\RadioGadget.csproj", "{AE664C6C-000B-44D9-BAD8-0200D6ABE90D}"
    EndProject
    Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "Vs2010Renderers", "..\Vs2010Renderers\Vs2010Renderers.vbproj", "{B4FB8309-8FDB-44FF-9B38-878C5DEB07D5}"
    EndProject
    Global
       ...
    EndGlobal
    I think the best way to extract the filenames (underlined) is using regular expressions... I just don't know:
    1. The pattern to use, and
    2. How to get it to return just the filenames, when I need to match the surrounding stuff as well...

    Regex is very useful, but I can never get the hang of it...
    I got as far as this:
    vb.net Code:
    1. Dim fileContents As String = File.ReadAllText(Me.SolutionFilePath)
    2.                 Dim regexPattern As String = "Project\(""\{.*?\}""\)"
    3.                 For Each m As Match In Regex.Matches(fileContents, regexPattern)
    4.                     Me.AddProject(m.Value)
    5.                 Next
    Now, the regex pattern is nowhere near complete but it's a start I think... The idea was that it matches this part:
    Code:
    Project("{  ...  }")
    excluding the ... part obviously (which is just some guid I don't care about). Then I need it to match the rest too, and more importantly, I only need it to return the filename that I've underlined in the example. When I simply use 'm.Value' as I am now I think I will get the entire matched string back, right? That gets me nowhere as I'd still need to parse the filename out of that manually... Bit pointless to use regex then...


    Can anyone help? Maybe it is also a good idea to only let it match if the Project is the start of a line, and the next line is only 'EndProject', as it should be.

    Thanks!

  2. #2

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width