1

I want to compile single c++ file from project in Visual Studio 2012 solution. similar to (Using MSBuild to compile a single cpp file) but using Microsoft.Build.Evaluation.Project

For command line I can use msbuild <projectfile> /V:q /p:Configuration="<configuration>" /p:Platform=x64 /t:ClCompile /p:SelectedFiles="<files separated by semicolon>"

I tried following code

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;

But found it compile complete project and other projects that this project depend on.

Please provide snippet to achieve it.

Community
  • 1
  • 1
Abhay Joshi
  • 161
  • 1
  • 6

0 Answers0