gpt4 book ai didi

cakebuild - 如何将字符串数组参数传递给我的 Cake 脚本?

转载 作者:行者123 更新时间:2023-12-05 00:19:31 26 4
gpt4 key购买 nike

我想要一个 Argument<IEnumerable<string>> (或 string[] ,或其他 - 一个可迭代的字符串列表)到我的 Cake 脚本,但我不知道如何从 build.ps1 传递它至 cake.exe .

这是我到目前为止:

在 build.ps1 中:

param(
# ...
[ValidateSet("Bar", "Baz")]
[string[]]$Foo
)

# ...

$fooArg = If ($Foo.Count -gt 0) {"-foo=`(`"{0}`"`)" -f [string]::Join("`",`", $Foo)} Else {""}
Invoke-Expression "$CAKE_EXE ... $fooArg"

在 build.cake 中:
var baz = Argument<IEnumerable<string>>("foo", new string[0]);

但是,当我执行此操作时,出现以下错误:

More than one build script specified.

Could not find a build script to execute.
Either the first argument must the build script's path,
or build script should follow default script name conventions.

Usage: Cake.exe [build-script] [-verbosity=value] [-showdescription] [-dryrun] [..]

Example: Cake.exe Example: Cake.exe build.cake -verbosity=quiet Example: Cake.exe build.cake -showdescription

Options: -verbosity=value Specifies the amount of information to be displayed. (Quiet, Minimal, Normal, Verbose, Diagnostic) -showdescription Shows description about tasks. -dryrun Performs a dry run. -version Displays version information. -help Displays usage information. -experimental Uses the nightly builds of Roslyn script engine.



这样做的正确方法是什么?

最佳答案

解决方案#1(简单):

您可以简单地通过将参数作为字符串接受并将其拆分来解决它:

var foo = Argument("foo", string.Empty).Split(',');

解决方案#2(复杂):

您还可以通过将字符串数组包装在自定义类型中并实现来解决此问题 TypeConverter对于那种类型。包装器和类型转换器都必须
驻留在将通过 #r 加载的 .NET 程序集中或 #addin指示。
[TypeConverter(typeof(StringArrayConverter))]
public class StringArray
{
public string[] Items { get; }
}

public class StringArrayConverter : TypeConverter
{
// Implementation here :)
}

然后您将使用 Argument别名照常使用 StringArray类型。
var foo = Argument<StringArray>("foo", null);

在我看来,这个选项对于获取字符串数组来说有点复杂,所以在 we've added IEnumerable support for arguments 之前你可能想要使用更简单的解决方案。 .

关于cakebuild - 如何将字符串数组参数传递给我的 Cake 脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35727010/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com