如何通过 psake 中的属性来数据驱动任务依赖性?

发布于 2024-08-27 08:56:02 字数 834 浏览 10 评论 0原文

在 MSBuild 中,您可以通过将项目组传递到目标来数据驱动目标依赖项,如下所示:

<ItemGroup>
    <FullBuildDependsOn Include="Package;CoreFinalize"
                        Condition="@(FullBuildDependsOn) == ''" />
</ItemGroup>

<Target Name="FullBuild"
        DependsOnTargets="@(FullBuildDependsOn)" />

如果您不覆盖 FullBuildDependsOn 项目组,则 FullBuild 目标默认依赖于 Package 和 CoreFinalize 目标。但是,您可以通过定义自己的 FullBuildDependsOn 项组来覆盖此设置。

我想在 psake 中做同样的事情 - 例如:

properties {
    $FullBuildDependsOn = "Package", "CoreFinalize"
}

task default -depends FullBuild

# this won't work because $FullBuildDependsOn hasn't been defined yet - the "Task" function will see this as a null depends array
task FullBuild -depends $FullBuildDependsOn 

我需要做什么来数据驱动 psake 中的任务依赖关系?

In MSBuild you can data drive target dependencies by passing a item group into a target, like so:

<ItemGroup>
    <FullBuildDependsOn Include="Package;CoreFinalize"
                        Condition="@(FullBuildDependsOn) == ''" />
</ItemGroup>

<Target Name="FullBuild"
        DependsOnTargets="@(FullBuildDependsOn)" />

If you don't override the FullBuildDependsOn item group, the FullBuild target defaults to depending on the Package and CoreFinalize targets. However, you can override this by defining your own FullBuildDependsOn item group.

I'd like to do the same in psake - for example:

properties {
    $FullBuildDependsOn = "Package", "CoreFinalize"
}

task default -depends FullBuild

# this won't work because $FullBuildDependsOn hasn't been defined yet - the "Task" function will see this as a null depends array
task FullBuild -depends $FullBuildDependsOn 

What do I need to do to data drive the task dependencies in psake?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

简单气质女生网名 2024-09-03 08:56:02

好的。我明白你现在想要完成什么。您可以通过常规 PowerShell-fu 来完成此操作。

$FullBuildDependsOn = "Package"
Invoke-psake buildScript.ps1

在 buildScript.ps1 中:

if($FullBuildDependsOn -eq $Null) {
  $FullBuildDependsOn = "Package", "CoreFinalize"
}

properties {
  # Usual build properties here
}

task default -depends FullBuild

task FullBuild -depends $FullBuildDependsOn {}

task Package {}

task CoreFinalize {}

这里的关键是使用普通的 PowerShell 变量而不是使用 psake 属性。 HTH。

OK. I understand what you're trying to accomplish now. You can do this through regular PowerShell-fu.

$FullBuildDependsOn = "Package"
Invoke-psake buildScript.ps1

In buildScript.ps1:

if($FullBuildDependsOn -eq $Null) {
  $FullBuildDependsOn = "Package", "CoreFinalize"
}

properties {
  # Usual build properties here
}

task default -depends FullBuild

task FullBuild -depends $FullBuildDependsOn {}

task Package {}

task CoreFinalize {}

The key here is to use a normal PowerShell variable rather than using a psake property. HTH.

莳間冲淡了誓言ζ 2024-09-03 08:56:02

这不是我们在实现 psake 时考虑过的用例。更改 FullBuild 的依赖项列表对我来说似乎有点奇怪且无法维护。您可以通过传递要从命令行运行的任务列表来完成相同的操作。

./invoke-psake buildScript.ps1 Package, CoreFinalize

或者我错过了什么?

That's not a use-case that we ever considered when implementing psake. Changing FullBuild's list of dependencies seems a bit odd and unmaintainable to me. You can accomplish the same thing by passing in a list of tasks to run from the command line.

./invoke-psake buildScript.ps1 Package, CoreFinalize

Or am I missing something?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文