我正试着从MSBuild移动到psake。
我的存储库结构如下所示:
.build
| buildscript.ps1
.tools
packages
MyProject
MyProject.Testing
MyProject.sln我想在构建之前清理存储库(使用git干净-xdf)。但是我找不到一种方法( .Net类中的expect)来设置git的执行目录。
首先,我搜索了一种在psakes中设置工作目录的方法:
exec { git clean -xdf }
exec { Set-Location $root
git clean -xdf }Set-Location工作,但是在完成exec块之后,位置仍然被设置为$root。
然后我试着:
Start-Process git -Argumentlist "clean -xdf" -WorkingDirectory $root它可以工作,但会保持git打开,并且不会执行未来的任务。
如何在$root中执行git?
发布于 2015-05-23 17:11:52
在我的构建脚本中,我遇到了与您相同的问题。“设置位置”cmdlet不影响Powershell会话的Win32工作目录。
下面是一个示例:
# Start a new PS session at "C:\Windows\system32"
Set-Location C:\temp
"PS Location = $(Get-Location)"
"CurrentDirectory = $([Environment]::CurrentDirectory)"产出如下:
PS Location = C:\temp
CurrentDirectory = C:\Windows\system32您可能需要做的是在调用本机命令(如“git”)之前更改Win32当前目录:
$root = "C:\Temp"
exec {
# remember previous directory so we can restore it at end
$prev = [Environment]::CurrentDirectory
[Environment]::CurrentDirectory = $root
git clean -xdf
# you might need try/finally in case of exceptions...
[Environment]::CurrentDirectory = $prev
}https://stackoverflow.com/questions/30307409
复制相似问题