蛋糕MSBuild设置属性

6
我有一个批处理文件,我正在尝试使用Cake(C# Make)复制它。它调用MSBuild并传递了一些属性。以下是来自批处理文件的行:
"%MSBuildPath%msbuild.exe" ..\public\projectToBeBuilt.sln /t:Rebuild /p:Configuration=RELEASE;platform=%platform% /maxcpucount:%cpucount% /v:%verboselevel%

这些是我需要设置的属性。我认为应该像这样;
MSBuild(@"..\public\projectToBeBuilt.sln", s=> s.SetConfiguration("Release")
    .UseToolVersion(MSBuildToolVersion.Default)
    .WithProperty("Verbosity", Verbosity)
    .WithProperty("MaxCpuCount", cpuCount)
    .WithProperty("Platform", "x64")
    .WithProperty("OutDir", buildDir));

我在尝试实现这个功能时遇到了问题。我认为问题可能与我指定CPU数量的方式有关。此外,我也找不到设置为“Rebuild”的方法,就像批处理文件那样。

1个回答

10

你遇到了什么样的错误?

如果像在你的批处理示例中那样重新构建,你可以使用WithTarget设置目标,就像这样:

.WithTarget("Rebuild")

关于 CPU 数量,如果我这样设置,我没有问题。

.SetMaxCpuCount(System.Environment.ProcessorCount)

设置平台应该类似于这样

.SetPlatformTarget(PlatformTarget.x64)

设置详细程度会更好。

.SetVerbosity(Verbosity)

因此,完整的命令可能如下所示

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

MSBuild设置的流畅API方法文档位于此处


谢谢!看起来正是我在寻找的。我无法在任何地方找到 .WithTarget() 方法的示例。我的解决方法是创建一个“清理”任务,MSBuild 任务依赖于它。这会清除 bin 文件夹,强制进行全新的构建。我认为这将产生大致相同的结果。我确实发现使用 .SetMaxCpuCount(0) 将使用可用的最大处理器数量。再次感谢您的帮助! - Seth Faulkner
将SetMaxCpuCount设置为0将导致使用代理中可用的CPU数量。 - Miguel

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接