c# - Cake MSBuild 设置属性

标签 c# makefile msbuild cakebuild

我有一个批处理文件,我想用 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 计数的方式有关。我也找不到任何方法将其设置为重建,就像批处理那样。

最佳答案

你遇到了什么样的错误?

要像在批处理示例中那样重建,您可以像这样使用 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 方法 here .

关于c# - Cake MSBuild 设置属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45015707/

相关文章:

c# - 在 c# 中重新创建 Az.Connect-AzAccount

c++ - mingw32-make : *** No targets. 停止

ubuntu - 如何在 ubuntu 上运行 steamworks 示例

c++ - 错误 : expected class-name before '{' token - can't seem to find any circular includes

msbuild - 是否有用于编辑 MSBuild 项目的用户界面?

c# - 在Elastic/Nest 6+中滚动和分页

c# - 如何协调 LINQ 中的第一条和最后一条记录

c# - Entity Framework 上的延迟加载与急切加载性能

visual-studio - 如何在 Visual Studio 中取消长时间运行的自定义构建工具的构建过程?

cmake - 如何使用 CMake + msbuild 构建所有配置