Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell psake集执行目录_Powershell_Working Directory_Psake - Fatal编程技术网

Powershell psake集执行目录

Powershell psake集执行目录,powershell,working-directory,psake,Powershell,Working Directory,Psake,我正在尝试从MSBuild迁移到psake 我的存储库结构如下所示: .build | buildscript.ps1 .tools packages MyProject MyProject.Testing MyProject.sln 我想在构建之前清理存储库(使用git clean-xdf)。 但是我找不到一种方法(除了.Net类)来设置git的执行目录 首先,我搜索了一种在psakes exec中设置工作目录的方法: exec { git clean -xdf } exec { Set-

我正在尝试从MSBuild迁移到psake

我的存储库结构如下所示:

.build
 | buildscript.ps1
.tools
packages
MyProject
MyProject.Testing
MyProject.sln
我想在构建之前清理存储库(使用git clean-xdf)。 但是我找不到一种方法(除了.Net类)来设置git的执行目录

首先,我搜索了一种在psakes exec中设置工作目录的方法:

exec { git clean -xdf }
exec { Set-Location $root
       git clean -xdf }
Set Location可以工作,但在exec块完成后,Location仍然设置为$root

然后我试着:

Start-Process git -Argumentlist "clean -xdf" -WorkingDirectory $root
它可以工作,但使git保持打开状态,并且不会执行未来的任务


如何在$root中执行git?

我在psake的构建脚本中遇到了与您相同的问题。“Set-Location”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
}