我想在Visual Studio 2012解决方案中从项目编译单个c ++文件。类似于(Using MSBuild to compile a single cpp file),但使用 Microsoft.Build.Evaluation.Project
对于命令行,我可以使用msbuild <projectfile> /V:q /p:Configuration="<configuration>" /p:Platform=x64 /t:ClCompile /p:SelectedFiles="<files separated by semicolon>"
我尝试了以下代码
Microsoft.Build.Evaluation.Project project;
string projFile = "C:\\ProjDir\\ProjectFile.vcxproj";
Dictionary<string, string> props = new Dictionary<string, string>();
props.Add("Configuration", "_64ReleaseDI");
props.Add("Platform", "x64");
props.Add("SelectedFiles", "CodeFile.cpp");
project = new Microsoft.Build.Evaluation.Project(projFile, props, "4.0");
MyCustomBuildLogger logger = new MyCustomBuildLogger();
bool bOutput = project.Build(new string[] { "ClCompile" }, new MyCustomBuildLogger[] {logger});
TextBox1.Text = logger.Output;
但发现它编译完整的项目和该项目所依赖的其他项目。
请提供实现它的代码段。