0

Is there a variable containing the original target invoked for msbuild? Basically in Visual Studio I'd need to call a powershell script only on publish.

Update: After Alexey's answer, I've tried this:

<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>

But the execution gets stuck. I get this into the output window (and then hangs forever):

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.
fra
  • 3,488
  • 5
  • 38
  • 61
  • Have you tried something from this similar question: http://stackoverflow.com/questions/5824208/powershell-exit-code-calling-from-msbuild ? – Alexey Shcherbak Jun 05 '15 at 06:36

1 Answers1

1

No, there is no such variable (as far as I know). But to run your powershell script - you can create a target and wire it up with some other target - e.g. in your case it's something like

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

You can also detect in your script if it's called from msbuild or from Visual Studio - see this article about $(BuildingInsideVisualStudio) https://msdn.microsoft.com/en-us/library/ms171468(en-us).aspx

Alexey Shcherbak
  • 3,394
  • 2
  • 27
  • 44