如何使用Cake Builder指定自定义参数? (DotNetCore)

时间:2018-08-22 14:42:39

标签: c# msbuild cakebuild

我有一个Cake自动构建脚本,用于构建各种配置的解决方案。我正在尝试编写将打包解决方案并将其发送到服务器的Web Deploy任务。为了使该过程更具可重复性并且减少麻烦,我选择将程序包存储在C:/ projectName中。

使用cake和DotNetCore,如何指定Web Deploy程序包(zip)输出文件夹?这是我到目前为止的内容:

Task("DeployRelease")
    .Does(() =>
    {
        foreach(var webConfig in config.projConfigs){
            Debug($"Publishing website: {webConfig.WebsiteServer}");

            DotNetCoreMSBuild(csprojPath, new DotNetCoreMSBuildSettings()
                .WithProperty("DeployOnBuild","true")
                .SetConfiguration(config.Configuration)
                .ArgumentCustomization(args=>args.Append($"/OutputPath={webConfig.BuildPath}"));


            var deploySettings = new DeploySettings()
            {
                SourcePath = webConfig.BuildPath,
                SiteName = webConfig.WebsiteName,
                ComputerName = webConfig.WebsiteServer,
                Username = webConfig.DeployUser,
                Password = webConfig.DeployToken
            };
            DeployWebsite(deploySettings);

            Debug($"Completed Web Deploy on: {webConfig.WebsiteServer}");
        }
    }); 

上面的代码应该可以正常工作(至少在解释文档时有效),但是出现以下错误:

  

C:/ Development / {project} / build。{project} .cake(355,40):错误CS1660:无法将lambda表达式转换为类型'ProcessArgumentBuilder',因为它不是委托类型

文档:https://cakebuild.net/api/Cake.Core.Tooling/ToolSettings/50AAB3A8     https://cakebuild.net/api/Cake.Common.Tools.DotNetCore.MSBuild/DotNetCoreMSBuildBuilder/

1 个答案:

答案 0 :(得分:2)

ArgumentCustomization是所有工具设置的属性,因此正确的语法为:

new DotNetCoreMSBuildSettings {
    ArgumentCustomization = args=>args.Append($"/OutputPath={webConfig.BuildPath}")

}.WithProperty("DeployOnBuild","true")
 .SetConfiguration(config.Configuration);