Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cake MSBuild setting properties

I have a batch file that I am trying to replicate with Cake (C# Make). It makes a call to MSBuild with a few properties. Here is the line from the batch;

"%MSBuildPath%msbuild.exe" ..\public\projectToBeBuilt.sln /t:Rebuild /p:Configuration=RELEASE;platform=%platform% /maxcpucount:%cpucount% /v:%verboselevel%

These are the properties I need to set. I think its something like this;

MSBuild(@"..\public\projectToBeBuilt.sln", s=> s.SetConfiguration("Release")
    .UseToolVersion(MSBuildToolVersion.Default)
    .WithProperty("Verbosity", Verbosity)
    .WithProperty("MaxCpuCount", cpuCount)
    .WithProperty("Platform", "x64")
    .WithProperty("OutDir", buildDir));

I'm having trouble making this work. I think it may be something to do with how I'm designating the cpu count. I also cant find any way to set it to Rebuild, the way the batch does it.

like image 313
Seth Faulkner Avatar asked Jul 10 '17 15:07

Seth Faulkner


1 Answers

What kind of error are you getting?

To rebuild like you do in your batch example you would set target using WithTarget like this

.WithTarget("Rebuild")

Regarding CPU count I have no issue if I set like this

.SetMaxCpuCount(System.Environment.ProcessorCount)

Setting platform would look something like this

.SetPlatformTarget(PlatformTarget.x64)

Setting verbosity would be

.SetVerbosity(Verbosity)

So a complete command could look like

MSBuild(solution, settings =>
    settings.SetConfiguration("Release")
        .UseToolVersion(MSBuildToolVersion.Default)
        .WithTarget("Rebuild")
        .SetMaxCpuCount(cpuCount)
        .SetPlatformTarget(PlatformTarget.x64)
        .SetVerbosity(Verbosity)
        .WithProperty("OutDir", buildDir)
        );

The fluent API methods for the MSBuild settings are documented here.

like image 100
devlead Avatar answered Sep 22 '22 17:09

devlead