Cake MSBuild目标

时间:2018-07-12 12:36:24

标签: c# msbuild cakebuild msbuild-target

我正在尝试使用Cake的内置MSBuild功能来仅构建特定的目标(即Compile)。使用以下示例:https://cakebuild.net/api/Cake.Common.Tools.MSBuild/MSBuildAliases/C240F0FB

var settings = new MSBuildSettings()
{
    Verbosity = Verbosity.Diagnostic,
    ToolVersion = MSBuildToolVersion.VS2017,
    Configuration = "Release",
    PlatformTarget = PlatformTarget.MSIL
};
settings.WithTarget("Compile");

MSBuild("./src/Cake.sln", settings);

但是它似乎可以建立所有目标,而我只想建立一个特定目标,详细信息如下:https://msdn.microsoft.com/en-us/library/ms171486.aspx

1 个答案:

答案 0 :(得分:2)

根据此处的文档:

https://cakebuild.net/api/Cake.Common.Tools.MSBuild/MSBuildSettingsExtensions/01F8DC03

WithTarget扩展方法返回带有修改的MSBuildSettings的相同实例,它不与当前实例交互。结果,您在哪里:

settings.WithTarget("Compile");

实际上什么也没做。但是,如果您这样做:

var settings = new MSBuildSettings()
{
    Verbosity = Verbosity.Diagnostic,
    ToolVersion = MSBuildToolVersion.VS2017,
    Configuration = "Release",
    PlatformTarget = PlatformTarget.MSIL
};

MSBuild("./src/Cake.sln", settings.WithTarget("Compile");

它应该按照您的预期工作。

为帮助解决此类问题,您可以在诊断模式下运行Cake,以查看确切的命令被发送到命令行以执行。您可以在以下相关问题中找到有关此问题的更多信息:

How to enable diagnostic verbosity for Cake