Search code examples
c#msbuildmsbuild-buildengine

MSBuild: define subprojects build configuration in BuildEngine


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?


Solution

  • 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.