2015-02-06 97 views
1

我想將運行MSBuild的一些舊批處理文件轉換爲PowerShell腳本。研究的Invoke-MSBuild命令,下面的代碼是什麼我趕上了:Powershell MSBuild錯誤

Invoke-MsBuild -Path "C:\path\solution.sln" -MsBuildParameters "/target:Clean;Rebuild /property:Configuration=Release;Platform=""x64"" /fl /flp:verbosity=normal;logfile=C:\path\logfile.log" -KeepBuildLogOnSuccessfulBuilds 

查看日誌文件,當我運行它開始建設有MSBuild的解決方案文件的腳本,但我不斷收到此錯誤:

error MSB8020: The builds tools for v120 (Platform Toolset = 'v120') cannot be found. To build using the v120 build tools, either click the Project menu or right-click the solution, and then select "Update VC++ Projects...". Install v120 to build using the v120 build tools.

我很困惑,因爲我有使用12.0平臺的Visual Studio 2013。我嘗試重新安裝v120構建工具,但沒有任何改變。

+0

您的舊批處理腳本仍然在同一臺計算機上工作嗎?批處理命令是什麼樣的? – sburgess123 2015-02-07 22:59:39

+0

@ sburgess123是舊批處理腳本仍然有效: msbuild.exe C:\ path \ solution.sln/t:Clean;重建/ p:配置=發佈;平臺= x64 – 2015-02-09 19:09:25

+0

@StewC你在哪裏啓動舊批處理文件來自?也就是說,你是從Visual Studio命令提示符啓動它嗎?運行之前你正在運行任何設置嗎? – NextInLine 2015-02-12 05:04:13

回答

1

很可能您的PowerShell環境不包含適當的環境變量(特別是%PATH%或$ env:PowerShell中的路徑)。幸運的是,它很容易確認是這種情況:

  • 打開的Visual Studio 2013命令提示符
  • 運行PowerShell的
  • 運行您Invoke-MsBuild命令

如果它運行使用這些步驟,然後您的解決方案是:

  1. 擺弄PowerShell環境找到你的配置文件(在PowerShell中運行$profile以查找路徑)。例如,可以通過添加行來修改路徑$env:Path = $env:Path + ';another_path;yet_another_path'

  2. 查找由Visual Studio 2013命令提示符調用的批處理文件 - 創建一個調用該批處理文件的批處理文件,然後調用powershell,以便您的powershell在powershell實際運行之前配置環境。

+0

我按照步驟操作,但得到了相同的錯誤 – 2015-02-09 19:09:02

+0

您是否嘗試過運行x86和x64 PowerShell? – NextInLine 2015-02-09 20:56:21

+0

是的,我嘗試了他們兩個 – 2015-02-12 00:47:31