我想把命令行参数注入到我的psake构建脚本中,比如:.\build.ps1 Deploy environment=“Deploy”
但psake会将每个参数都视为任务,并会回答“任务不存在”。
可以在psake中注入命令行参数吗?
build.ps1 -->
Import-Module '.\psake.psm1'
Invoke-psake '.\tasks.ps1' $args
Remove-Module psake发布于 2010-02-10 17:01:34
现在要调用的latest release of psake - supports passing parameters,例如
Invoke-psake .\parameters.ps1 -parameters @{"p1"="v1";"p2"="v2"} 这个特性是刚刚添加的。:)
发布于 2010-02-07 16:42:01
一个全局变量将暂时解决我的问题,并且只有一个对$global:arg_environent的引用,如果我找到更好的方法注入属性,它将很容易更改。
build.ps1
param(
[Parameter(Position=0,Mandatory=0)]
[string]$task,
[Parameter(Position=1,Mandatory=0)]
[string]$environment = 'dev'
)
clear
$global:arg_environent = $environment
Import-Module .\psake.psm1
Invoke-psake tasks.ps1 $task
Remove-Module psaketasks.ps1
properties {
$environment = $global:arg_environent
}
task default -depends Deploy
task Deploy {
echo "Copy stuff to $environment"
}发布于 2010-02-06 21:36:02
我不是专家,但我认为将参数传递给Invoke-Psake是不可能的。查看Psake的最新源代码,Invoke-Psake函数的参数是:
param(
[Parameter(Position=0,Mandatory=0)]
[string]$buildFile = 'default.ps1',
[Parameter(Position=1,Mandatory=0)]
[string[]]$taskList = @(),
[Parameter(Position=2,Mandatory=0)]
[string]$framework = '3.5',
[Parameter(Position=3,Mandatory=0)]
[switch]$docs = $false
)有4个参数,你的构建文件,一个任务列表,.NET框架版本,是否输出你的任务文档。我是powershell和psake的新手,我正在尝试做同样的事情,我正在尝试在我的脚本中做一些类似的事情来实现同样的事情:
properties {
$environment = "default"
}
task PublishForLive -precondition { $environment = "Live"; return $true; } -depends Publish {
}
task PublishForStaging -precondition { $environment = "Staging"; return $true; } -depends Publish {
}
task Publish {
Write-Host "Building and publishing for $environment environment"
#Publish the project...
}然后使用PublishForLive或PublishForStaging调用psake,无论我需要哪一个:
powershell -NoExit -ExecutionPolicy Unrestricted -Command "& {Import-Module .\tools\psake\psake.psm1; Invoke-psake .\psake-common.ps1 PublishForLive }"但它似乎对我不起作用!在任务前提条件中设置$environment变量似乎没有任何效果。还在努力让这件事成功..。
https://stackoverflow.com/questions/2208552
复制相似问题