开发者

MSBuild: define subprojects build configuration in BuildEngine

开发者 https://www.devze.com 2023-02-14 04:35 出处:网络
I\'m using BuildEngine as a step to create a one click build environment. The code is the following: Engine engine = new Engine();

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开发者_C百科.

Is there any way to force it to build all dependencies on Release?


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消