运行位于TFS源代码管理中的Powershell脚本

Mat*_*att 5 tfs tfsbuild powershell-2.0

我正在尝试在构建过程中运行Powershell脚本,但我无法弄清楚如何访问已检入源代码控制(TFS 2010)的ps1文件.存在类似的SO问题,但我实际上不确定它是否正确:

TFS 2010:运行存储在源代码管理中的powershell脚本

我的TFS源代码控制设置如下:

= Project
== BuildScripts
=== MyScript.ps1
== Code
===
Dir1 ==== MySolution.sln

我认为传递类似的东西SourcesDirectory + "\..\..\MyScript.ps1"(告诉Powershell脚本在哪里)会起作用,但我想我已经离开了某个地方.

有人可以帮我弄清楚如何引用ps1文件,并运行它?

Dav*_*haw 4

您需要在构建定义中设置一个工作区,其中包含带有 Powershell 脚本的目录。

所以你的映射可能是这样的:

*Server*                    *Workspace*
$/Project/Code/Dir     -    $(SourcesDir)
Run Code Online (Sandbox Code Playgroud)

您需要添加:

*Server*                    *Workspace*
$/Project/Code/Dir     -    $(SourcesDir)
$/Project/BuildScripts -    $(SourcesDir)/BuildScripts
Run Code Online (Sandbox Code Playgroud)

然后,您的 InvokeProcess 可以传递Path.Combine(SourceDirectory, "BuildScripts", "MyScript.ps1")到 Powershell 命令行。

注意:您还可以将$/Project/Code/Dir工作区设置为$(SourcesDir)/Code.