1

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?

dcarneiro
  • 7,060
  • 11
  • 51
  • 74
  • Are you sure the dependant projects aren't "hardcoded" to "Debug" in their csproj-file? It should say something like this: Debug – jishi Mar 02 '11 at 15:55
  • Well, if fact they are =) but AFAIK that line only tell the compiler to use Debug configuration if $(Configuration) isn't set. So, is there any way to set $(Configuration) variable or shall I set the default to Release? – dcarneiro Mar 02 '11 at 16:05

2 Answers2

1

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.

Sergio Rykov
  • 4,176
  • 25
  • 23
  • But my project is in framework 3.5. Does ProjectCollection build projects on that framework or only in framework 4? – dcarneiro Mar 02 '11 at 17:47
  • 1
    You can use MSBuild 4.0. It can build your project with framework 3.5. And migration to 4.0 will be much easier when builer works with 4.0. – Sergio Rykov Mar 02 '11 at 17:56
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.

radical
  • 4,364
  • 2
  • 25
  • 27
  • You just forgot to treat the Property as a literal value: bpg.SetProperty("Configuration", configuration, true); despite that, it worked perfectly! – dcarneiro Mar 03 '11 at 10:18