2012-09-18 171 views
1

如何动态生成Visual Studio解决方案和项目文件? 像./configure脚本一样。可以接受参数。 例如:在MyProject.sln.template动态生成Visual Studio解决方案和项目文件

#if VS_2012 
Microsoft Visual Studio Solution File, Format 12.00 
#elseif VS_2010 
Microsoft Visual Studio Solution File, Format 11.00 
#elseif VS_2008 
Microsoft Visual Studio Solution File, Format 10.00 
#endif 
#if VS_2012 
Project("{12345678-8B4A-11D0-8D11-00A0C91BC942}") = "Project1", "Project1\Project1.vcproj", "{98765432-E41A-4C56-B16F-263D2C6D6475}" 
EndProject 
#endif 

我应该使用什么工具?但我不想使用./configure脚本。 这些工具最好适用于任何类型的文本文件。因为我有其他类型的文件可以生成,不仅仅是解决方案/项目文件。

回答

0

你可以考虑cmake从配置脚本生成工作区/项目。 Cmake实际上非常强大,可以维护与平台无关的构建脚本。但它会适合你的需要。

另一种选择是创建sln/vcproj文件的本土工具。它们最终是XML。可能没有书面文档,但是您可以从现有工作区进行逆向工程。

+0

能CMake的操作的文本文件格式的任何?比如自定义文件格式? – linquize

+1

不,你需要编写一个cmake脚本文件 – gammay

0

我在github上找到了这个解决方案Nager.TemplateBuilder

这个例子创建Windows桌面应用程序有两个包的NuGet

//Configure Project 
var demoProject = new ProjectInfo($"DemoProject", ProjectTemplate.WindowsClassicDesktopWindowsFormsApp); 
demoProject.NugetPackages = new List<string> { "System.ServiceModel.NetTcp", "System.Runtime.Serialization.Xml" }; 

//Configure Solution 
var folder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); 
var solutionInfo = new SolutionInfo("Test", folder); 
solutionInfo.ProjectInfos.Add(demoProject); 

//Start building machine 
var buildingMachine = new SolutionBuildingMachine(); 
buildingMachine.Build(solutionInfo); 
buildingMachine.Dispose(); 
相关问题