简体   繁体   中英

Passing MsBuild Command Line Arguments with BuildEngine

I have the following code to build a project from another C# app:

var buildEngine = new Engine();

buildEngine.RegisterLogger(new ConsoleLogger());

var success = buildEngine.BuildProjectFile(pathToCsProjFile);
if(!success)
{
    Log.LogIt("On Noes! We Broke!");
}
else
{
    Log.LogIt("It Worked!!!!!!");
}

Currently it builds the default configuration (Debug) but I want it to build the release version. If I were invoking MsBuild from the command line I would do something like:

C:\Windows\WinFX\v3.5>msbuild.exe *.proj /ToolsVersion:3.5 /p:Configuration=Release

How do I pass that configuration switch to the build engine?

You'll want to set the property, something like this should do the trick:

var pathToCsProjFile = "";
var buildEngine = new Engine();
var project = new Project(buildEngine);
project.Load(pathToCsProjFile);
project.SetProperty("Configuration", "Release");

var success = project.Build();

Use one of the other overloaded implementations of BuildProjectFile . I believe this one . Create a BuildPropertyGroup and add the properties you want. In this case 'Configuration' = 'Release'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM