【问题标题】:How do I specify Custom Arguments with Cake Builder? (DotNetCore)如何使用 Cake Builder 指定自定义参数? (点网核心)
【发布时间】:2018-08-22 23:55:57
【问题描述】:

我有一个 Cake 自动构建脚本,用于构建各种配置的解决方案。我正在尝试编写一个将打包解决方案并将其发送到服务器的 Web 部署任务。为了使该过程更具可重复性且不那么脆弱,我选择将包存储在 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/

【问题讨论】:

    标签: c# msbuild cakebuild


    【解决方案1】:

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

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

    【讨论】:

    • 代码未编译(不确定我是否使用过时的 C# 版本)并且 var buildSettings = new DotNetCoreMSBuildSettings() { ArgumentCustomization = args=>{ args.Append($"/OutputPath={webConfig.BuildPath}"); return args; } }; 抛出 .NET Core CLI:进程返回错误(退出代码 1)。 MSBUILD:错误 MSB1001:未知开关。
    • 糟糕的是,我有一个 ;太多,不应该在 ArgumentCustomization 之后。我已经更新了答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-25
    • 1970-01-01
    • 1970-01-01
    • 2013-03-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多