title: How to compile single c++ file programmatically using Microsoft.Build.Evaluation.Project
body: <p>I want to compile single c++ file from project in Visual Studio 2012 solution. similar to (<a href="https://stackoverflow.com/questions/4172438/using-msbuild-to-compile-a-single-cpp-file">Using MSBuild to compile a single cpp file</a>) but using <strong>Microsoft.Build.Evaluation.Project</strong></p>
  
  <p>For command line I can use <code>msbuild &lt;projectfile&gt; /V:q /p:Configuration="&lt;configuration&gt;" /p:Platform=x64 /t:ClCompile /p:SelectedFiles="&lt;files separated by semicolon&gt;"</code></p>
  
  <p>I tried following code </p>
  
  <pre><code>Microsoft.Build.Evaluation.Project project;
  string projFile = "C:\\ProjDir\\ProjectFile.vcxproj";
  
  Dictionary&lt;string, string&gt; props = new Dictionary&lt;string, string&gt;();
  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;
  </code></pre>
  
  <p>But found it compile complete project and other projects that this project depend on.</p>
  
  <p>Please provide snippet to achieve it.</p>