Created
March 16, 2015 19:35
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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