问题
I'm using BuildEngine as a step to create a one click build environment. The code is the following:
Engine engine = new Engine();
FileLogger logger = new FileLogger { Parameters = @"logfile=C:\builds\build.log" };
engine.RegisterLogger(logger);
var project = new Project(engine);
project.Load("Example.csproj");
project.SetProperty("Configuration", "Release");
bool success = project.Build();
And he seems to build project Example with release configuration. But when I look at the build.log, all of the dependencies of Example project were build as debug.
Is there any way to force it to build all dependencies on Release?
回答1:
Set the global properties on the engine:
BuildPropertyGroup bpg = new BuildPropertyGroup ();
bpg.SetProperty ("Configuration", "Release");
engine.GlobalProperties = bpg;
These will override the properties set by the project themselves.
回答2:
Engine class is obsolete.
Use Microsoft.Build.Evaluation.ProjectCollection instead.
It enables to pass global properties as you do when calling msbuild from command line.
I should warn you that msbuild eats a lot memory. I have a bot on a build machine working as a service. When it recieves command to build it creates new process and calles Build(). Sometimes memory usage reaches 2GB (our build is huge). When you call MSBuild from command line it releases memory much more effective.
Try to test 2 implementations - throw API and throw calling MSBuild.exe - in a loop. May be in MSBuild 4.0 MS solved those memory problems.
来源:https://stackoverflow.com/questions/5169841/msbuild-define-subprojects-build-configuration-in-buildengine