Skip to content

Instantly share code, notes, and snippets.

@danmoseley
Created December 20, 2018 22:14
Show Gist options
  • Save danmoseley/038c9a694e91431eb906ce348ea86789 to your computer and use it in GitHub Desktop.
Save danmoseley/038c9a694e91431eb906ce348ea86789 to your computer and use it in GitHub Desktop.
solution generator for corefx
using System;
using System.IO;
using System.Xml.Linq;
using System.Linq;
namespace ConsoleApp20
{
class Program
{
static void Main()
{
string header = @"
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.28416.103
MinimumVisualStudioVersion = 10.0.40219.1";
string globalSections = @"Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal";
string csharpProjectTemplate = @"Project(""{{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}}"") = ""{0}"", ""{1}"", ""{2}""
EndProject";
string rootPath = @"c:\git\corefx\src";
string solutionName = "AllCoreFX";
string solutionPath = Path.Combine(rootPath, solutionName + ".sln");
var projectFiles = Directory.GetFiles(rootPath, "*.csproj", SearchOption.AllDirectories);
using (var stream = File.OpenWrite(solutionPath))
using (var writer = new StreamWriter(stream))
{
writer.WriteLine(header);
var xmlns = XNamespace.Get("http://schemas.microsoft.com/developer/msbuild/2003");
foreach (var projectFile in projectFiles)
{
string name = Path.GetFileNameWithoutExtension(projectFile);
string relativePath = projectFile.Substring(rootPath.Length).TrimStart('\\');
var doc = XDocument.Load(projectFile);
var guidElement = doc.Root.Elements(xmlns + "PropertyGroup")
.Elements(xmlns + "ProjectGuid")
.FirstOrDefault();
string guid = guidElement == null ? Guid.NewGuid().ToString("B") : guidElement.Value;
string entry = string.Format(csharpProjectTemplate, name, relativePath, guid);
writer.WriteLine(entry);
}
writer.WriteLine(globalSections);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment