2015-05-25 30 views
0

是否有包含爲msbuild調用的原始目標的變量? 基本上在Visual Studio中,我只需要在發佈時調用powershell腳本。帶原始目標的Msbuild變量

更新: 阿列克謝的回答後,我已經試過這樣:

<Target Name="DeployToAzure" AfterTargets="CopyPackageToDropLocation"> 
    <PropertyGroup> 
     <PowerShellExe Condition=" '$(PowerShellExe)'=='' "> 
     %SystemRoot%\sysnative\WindowsPowerShell\v1.0\powershell.exe 
     </PowerShellExe> 
    </PropertyGroup> 
    <Exec Command="$(PowerShellExe) -ExecutionPolicy Unrestricted -noprofile -nologo &quot; &amp; { Write-Output 'Test' } &quot;" /> 
    </Target> 

但執行卡住。我得到這個到輸出窗口(然後永遠掛起):

Task "Exec" 
3>  Task Parameter:Command= 
3>  %SystemRoot%\sysnative\WindowsPowerShell\v1.0\powershell.exe 
3>  -ExecutionPolicy Unrestricted -noprofile -nologo " & { Write-Output 'Test' } " 
3>  
3>  %SystemRoot%\sysnative\WindowsPowerShell\v1.0\powershell.exe 
3>  -ExecutionPolicy Unrestricted -noprofile -nologo " & { Write-Output 'Test' } " 
3>  Windows PowerShell 
3>  Copyright (C) 2013 Microsoft Corporation. All rights reserved. 
+0

你從這個類似嘗試的東西問題: http://stackoverflow.com/questions/5824208/powershell-exit-code-calling-from-msbuild? –

回答

1

不,沒有這樣的變量(據我所知)。但是爲了運行你的powershell腳本 - 你可以創建一個目標,並與其他目標連接 - 例如在你的情況下,它像

<Target Name="RunMyPowershell" AfterTargets="Publish"> 
.. 
</Target> 

您也可以檢測你的腳本,如果它是從的MSBuild或從Visual Studio稱爲 - 看到這篇文章約$(BuildingInsideVisualStudio) https://msdn.microsoft.com/en-us/library/ms171468(en-us).aspx