I’ve got a freshly made C++ (.vcxproj) project that I’ve added some files to. Now, I’m attempting to compile it using the following code:
var clogger = new ConsoleLogger(LoggerVerbosity.Diagnostic);
var pc = new ProjectCollection(new Dictionary<string, string>{{"Configuration", "Release"},
{"ToolsVersion", "4.0"}},
new[] { clogger }, ToolsetDefinitionLocations.Registry);
pc.DefaultToolsVersion = "4.0";
pc.LoadProject(projectPath);
var project = new Project(pc);
try
{
Assert.That(project.Build("Release"), Is.True);
}
finally
{
pc.UnregisterAllLoggers();
}
Unfortunately, attempting to compile the project gives me the following error:
Building with tools version "4.0".
MSBUILD : error MSB4057: The target "Rebuild" does not exist in the project.
I’ve tried plenty of targets including not specifying a target at all, and I keep getting the same error. I assume that the Rebuild target really is in the project because msbuild from the command line builds it just fine. What am I missing?
Set your
Projectobject as follows:Build()takes a Target name, not a Property name:So here pass the Rebuild target: