Ive been tasked with building a solution deployer for our company.
Part of what I want to do requires me to read a solution file and find out all the information about what projects it contains, what their source safe paths are etc
I'm sure someone must have written some sort of .sln reader before now so i was wondering if anyone knew of the existance of one
Thanks
-Kris |
| Kris Mackintosh Friday, July 06, 2007 3:40 PM |
I would propose to use regular expressions to get the information you are after. For example a regular expression like this to get all projects and their information:
(?<project>\("\{(?<prj_id>\x{8}(?:-\x{4}){3}-\x{12})\}"\) = "(?<project_name>\w+)"\, "(?<project_path>[\w\\\.-]+)", "\{(?<another_id>\x{8}(?:-\x{4}){3}-\x{12})"\}(?<project_section>(?# more funny stuff)))
I've not tested it, but it should look something like this. And on (pseudo) code side it should look something like that:
Regex regex = new regex("(?# the funny regex above)"); foreach(Match m in regex.Matches()) { string projectName = m.Result("${project_name}"); string projectId = m.Result("${prj_id)"); string projectPath = m.Result("${project_path}"); // ... }
to handle eventual line breaks you can use this (insert it at all places where a linebreak may occur): (?<line_break>(?:[\x0D\x0A]{1,2}(?![\x0D\x0A])){0,1}) or rely on \n* which is a bad idea in .net
|
| KomplexoR Wednesday, April 23, 2008 3:30 PM |
Open the .sln file in WordPad. |
| JohnWein Friday, July 06, 2007 7:48 PM |
Its simply XML. You can use the XML classes to pull out the information you need. As for using XML, post in the XML and the .NET Framework forum.
|
| Ðãvę Âņđęŕŝőŋ1 Friday, July 06, 2007 8:04 PM |
VS .sln files are not xml, they are plain text so you can read them, but there are not any native objects to objectify them in your code
here's a snippit of a .sln file
Microsoft Visual Studio Solution File, Format Version 9.00 # Visual Studio 2005 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{A6C122FD-7FE5-4F70-B987-10303E990DD5}" ProjectSection(WebsiteProperties) = preProject Debug.AspNetCompiler.Debug = "True" Release.AspNetCompiler.Debug = "False" EndProjectSection ProjectSection(SolutionItems) = preProject Solution Items\SharpControlLibrary.dll = Solution Items\SharpControlLibrary.dll EndProjectSection EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpObjects", "Source\SharpObjects.csproj", "{2FF29CAD-BAC9-412B-B1B5-CE5B504E12FD}" ProjectSection(WebsiteProperties) = preProject Debug.AspNetCompiler.Debug = "True" Release.AspNetCompiler.Debug = "False" EndProjectSection EndProject
|
| Kris Mackintosh Friday, July 06, 2007 10:26 PM |
Maybe I should have been more specific, I want to use code to read a .sln file to see what projects it has so i can programatically retrieve them from source safe. |
| Kris Mackintosh Friday, July 06, 2007 10:28 PM |
I was thinking about the .*proj files, which use XML, so I assumed that .SLN files were the same. My mistake. Though I would assume you could use the same concept that XML does to pull out the information you want.
|
| Ðãvę Âņđęŕŝőŋ1 Saturday, July 07, 2007 12:25 AM |
Just out of interest does anyone know why the .sln files are not in XML. Would sure make working with them a lot easier...(Gotta find a reason to get Linq to Xml in somewhere  |
| M MacPherson Wednesday, April 23, 2008 2:53 PM |
I would propose to use regular expressions to get the information you are after. For example a regular expression like this to get all projects and their information:
(?<project>\("\{(?<prj_id>\x{8}(?:-\x{4}){3}-\x{12})\}"\) = "(?<project_name>\w+)"\, "(?<project_path>[\w\\\.-]+)", "\{(?<another_id>\x{8}(?:-\x{4}){3}-\x{12})"\}(?<project_section>(?# more funny stuff)))
I've not tested it, but it should look something like this. And on (pseudo) code side it should look something like that:
Regex regex = new regex("(?# the funny regex above)"); foreach(Match m in regex.Matches()) { string projectName = m.Result("${project_name}"); string projectId = m.Result("${prj_id)"); string projectPath = m.Result("${project_path}"); // ... }
to handle eventual line breaks you can use this (insert it at all places where a linebreak may occur): (?<line_break>(?:[\x0D\x0A]{1,2}(?![\x0D\x0A])){0,1}) or rely on \n* which is a bad idea in .net
|
| KomplexoR Wednesday, April 23, 2008 3:30 PM |
Thanks KomplexoR. I've already done the work  I was just wondering if anyone knew the design reasons for it not being in XML/why it hasn't been changed/is it likely to be changed? The fact that every version of VS (so far that I am aware of) has converted solution files from previous versions suggests it is not for backwards compatibility. I guess there is not much demand for change and so it sits at the bottom of the pile. |
| M MacPherson Wednesday, April 23, 2008 3:37 PM |