c# – csproj PostBuild command to execute a script in repository root directory


I have a monorepo with multiple solutions, we can see it simplified like this:

- monorepo
    |- scripts
    |   |- script1.ps
    |- src
        |- projA
        |   |- projA.csproj
        |- projB

In csproj file, I define a post build target to execute a command, from a script located
in scripts directory at the root of the monorepo:

   <Target Name="PostBuild" AfterTargets="PostBuildEvent">
     <Exec Command="pwsh -NoProfile -ExecutionPolicy RemoteSigned -Command &quot;
      $root = $(git rev-parse --show-toplevel); 
      $scriptPath = [System.IO.Path]::Combine($root, 'scripts', 'script1.ps1');
      &amp; $scriptPath '$(ProjectDir)$(OutDir)' &quot;" />
   </Target>

It fails miserably, but I do not know how to debug this command and I have no clue what is wrong. Any help would be appreciated.

Leave a Reply

Your email address will not be published. Required fields are marked *