Skip to content

Instantly share code, notes, and snippets.

@sidwarkd
Created March 16, 2015 19:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sidwarkd/d0fd56507ecdfd8c0b73 to your computer and use it in GitHub Desktop.
Save sidwarkd/d0fd56507ecdfd8c0b73 to your computer and use it in GitHub Desktop.
A super simple way to get the list of project files from a Visual Studio Solution file.
public static void GetProjectFilesFromSolution(string solutionFile)
{
if (File.Exists(solutionFile))
{
string cwd = Directory.GetCurrentDirectory();
Directory.SetCurrentDirectory(Path.GetDirectoryName(solutionFile));
// This is a hack for reading solution files but is better than the almost 100 lines of code
// necessary to load a special MS assembly and parse the file the 'right way'
string[] solutionContents = File.ReadAllLines(solutionFile);
foreach (string line in solutionContents)
{
// It's a project definition line
if (line.StartsWith("Project("))
{
string projFile = line.Split(new char[] { ' ' })[3].Trim(new char[] { '\"', ',' });
// Do something with the file path here
System.Console.WriteLine(Path.GetFullPath(projFile));
}
}
Directory.SetCurrentDirectory(cwd);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment