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 "
$root = $(git rev-parse --show-toplevel);
$scriptPath = [System.IO.Path]::Combine($root, 'scripts', 'script1.ps1');
& $scriptPath '$(ProjectDir)$(OutDir)' "" />
</Target>
It fails complaining about $root is not recognized as a command or executable program but I do not know how to debug this command:
error MSB3073: The command "pwsh -NoProfile -ExecutionPolicy RemoteSigned -Command "
error MSB3073: $root = ;
error MSB3073: $scriptPath = [System.IO.Path]::Combine($root, 'scripts', 'writemanifest.ps1');
error MSB3073: & $scriptPath <path> exited with code 255.
I understand variables are not assigned properly, or it does not execute the right command but I have no clue how to fix it. Any help would be appreciated.
Commandattribute? Is thePostBuildtarget not being invoked by MSBuild? Is thecmdshell created by theExectask giving an error on the passedCommand? Is there an error from PowerShell (pwsh)? Is there an error fromgitwhen invoked from PowerShell?