fmvazque@terra.com.br wrote:[color=blue]
> Hi Pete,
>
> It seems that there isn`t a way of doing that by using the classes in
> the MSBUILD API (Microsoft.Build.BuildEngine.Dll).
>
> One of the open-ended issues that Microsoft left in MSBuild is the fact
> that Solution files are *not* valid MSBuild files. So as far as I know
> there is no way to use the MSBuild API to interpret a solution file
> (although you can use it to build an entire solution - Project.Load()
> works with a .sln file).
>
> One suggestion would be to use a a logic that hacks the .sln internal
> structure in order to discover what projects are part of the solution.
> The following code shows a way to do that:
>
>
> const string projectFileLocation = @"C:\MySolution.sln";
> StreamReader sr = File.OpenText(projectFileLocation);
>
> const string
> matchProjectNameRegex =
> "^Project\\(\"(?<PROJECTTYPEGUID>.*)\"\\)\\s*=\\s* \"(?<PROJECTNAME>.*)\"\\s*,\\s*\"(?<PROJECTRELATIV EPATH>.*)\"\\s*,\\s*\"(?<PROJECTGUID>.*)\"$";
>
> List<string> listOfProjects = new List<string>();
>
> string lineText;
> while ( (lineText = sr.ReadLine()) != null)
> {
> if (lineText.StartsWith("Project("))
> {
> Match projectNameMatch = Regex.Match(lineText,
> matchProjectNameRegex);
> if (projectNameMatch.Success)
> {
>
> listOfProjects.Add(projectNameMatch.Groups["PROJECTRELATIVEPATH"].Value);
> }
> }
> }
>
> foreach (string project in listOfProjects)
> {
> ProcessProject(project);
> }
>
> sr.Close();
>
> Notice that the code is trying to find the lines that begin with the
> "Project(" string. Those lines describe a projet existing into the
> solution. After that a regular expression is employed to extract the
> path where the project file is located relative to the solution file.
>
> Regards,
> -----
> Fabio Vazquez [C# MVP]
>
http://www.phidelis.com.br/blogs/fabiovazquez
>[/color]
Hello Fabio, that's what I do at the moment ( although not using regexes
), the method I use is IndexOf(".csproj") parse parse etc..., however
your method is much more elegant, thanks very much