I am trying to call a powershell script for local testing
<Target Name="RunPowerShellScript" BeforeTargets="Build" Condition="'$(LocalBuild)' == 'true'">
<Exec LogStandardErrorAsError="true" WorkingDirectory="$(EnlistmentRoot)" Command="pwsh -ExecutionPolicy Bypass -File "$(EnlistmentRoot)\src\helloworld.ps1"" />
</Target>
The current setup isn’t functioning as expected. If I eliminate $(LocalBuild), it operates correctly. However, it’s also invoked in the ADO pipeline, and I prefer not to have it there.
I’ve set LocalBuild to false in the props file and incorporated a target in the build file under build.target.
$(LocalBuild)' == 'true'
Based on your requirement, you can add the msbuild argument:
/p:LocalBuild=falsewhen using Azure DevOps Pipeline.For example:
In this case, you don't need to change the LocalBuild Value in the props file. And the RunPowerShellScript target will skip in Azure DevOps Pipeline.
The msbuild argument will override the value in the props file.
Update:
csproj file sample:
When we run the project on local machine, it will run the PowerShell script.
When we run the project in Azure Pipeline, we can set the msbuild argument:
/p:LocalBuild=false. Then the build target will be skipped.