I already know how to run arbitrary PowerShell script before building starts.
<Target Name="BeforeBuild">
<Exec Command="powershell.exe -executionpolicy bypass -command "& {.\script.ps1 '$(SolutionDir)'}"" />
<Sleep Delay="3000"/>
</Target>
My problem is that the script I want to run modifies part of a .cs
file. But this script above runs after the code was already copied into memory and when it builds, it uses the content of .cs
file before it was modified.
Is there a way to start buidling process but run PowerShell script earlier, before my code is copied into memory? You could say I want to run a preprocessor that will call an external executable before any compilation process even begins.
If not, is there a way to build the project twice in a row without having to click Build
in my IDE twice? (dirty hack that would fix my issue)
Quick note about <Sleep Delay="5000"/>
. Because my PowerShell script is starting a process that is asynchronous and very short I also added a Delay
task I found posted here: https://stackoverflow.com/a/41213107