fra
fra

Reputation: 3858

Msbuild variable with original target

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.

Upvotes: 0

Views: 213

Answers (1)

Alexey Shcherbak
Alexey Shcherbak

Reputation: 3454

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

Upvotes: 1

Related Questions