【问题标题】:Cake MSBuild setting propertiesCake MSBuild 设置属性
【发布时间】:2017-07-10 15:13:33
【问题描述】:

我有一个批处理文件,我想用 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,批处理的方式。

【问题讨论】:

    标签: c# makefile msbuild cakebuild


    【解决方案1】:

    你遇到了什么错误?

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

    【讨论】:

    • 谢谢!这看起来正是我想要的。我在任何地方都找不到 .WithTarget() 方法的示例。我的解决方法是创建 MSBuild 任务所依赖的“清理”任务。这清除了 bin 文件夹,强制重新构建。我认为这会产生大致相同的结果。我确实发现使用 .SetMaxCpuCount(0) 将使用可用的最大处理器数。再次感谢您的帮助!
    • SetMaxCpuCount 为 0 也会导致使用 Agent 中可用的 CPU 数量。
    猜你喜欢
    • 2011-02-08
    • 1970-01-01
    • 2011-01-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-22
    • 1970-01-01
    相关资源
    最近更新 更多