2012-10-14 132 views
0

我是新来psake,我有这个问题:我有2个psake脚本:替代属性脚本

(1):base_tasks.ps1:

properties{ 

$a = "hello" 

$b = "hi" 

} 

task One{ 
    Write-Host $a 
} 

(2):install.ps1

Include .\base_tasks.ps1 

properties{ 

$a = "Goodbye" 

$b = "Adjeu" 

} 

task default -depends One 

现在,是否有可能重写从文件1的属性和变量?我想使用文件1作为“基本任务”并在install.ps1中使用这些任务并覆盖属性。或者我必须以其他方式做到这一点?我将调用install.ps1并使用install.ps1中的$ a和$ b。

  • DanceAlot
+0

如果不知道这究竟回答您的问题:https://github.com/psake/psake/wiki/How-can-I-override -a-property-defined-in-my-psake-script%3F –

回答

0

source,它看起来像Properties仅仅是一个函数:

function Properties { 
    [CmdletBinding()] 
    param(
     [Parameter(Position=0,Mandatory=1)][scriptblock]$properties 
    ) 
    $psake.context.Peek().properties += $properties 
} 

所以,当你再次调用它,它只会再次添加的属性。然后

的属性转换成变量,像这样:

foreach ($key in $properties.keys) { 
     if (test-path "variable:\$key") { 
      set-item -path "variable:\$key" -value $properties.$key | out-null 
     } 
    } 
+1

哦,好的。我明白,谢谢澄清此事。所以没有办法实现我需要的东西?或者我用错误的方式使用psake :) – Piguy