Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Project hooks
Message
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Titre:
Divers
Thread ID:
01115998
Message ID:
01116545
Vues:
20
Hello Pete,

Not that I am aware of...

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*\"(?<PROJECTRELATIVEPATH>.*)\"\\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.

HTH.
-----
Fabio Vazquez
http://www.fabiovazquez.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform