在csproj文件中,我定义了一个邮政构建目标以执行命令,从 在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>
未能抱怨
$root is not recognized as a command or executable program
,但我不知道如何调试此命令:
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.
<PropertyGroup>
<!-- Temp var to store Git root dir -->
<GitRoot>Unknown</GitRoot>
</PropertyGroup>
<Target Name="FindGitRoot" BeforeTargets="PostBuild">
<!-- Run Git command and capture output -->
<Exec Command="git rev-parse --show-toplevel" ConsoleToMSBuild="true">
<Output TaskParameter="ConsoleOutput" PropertyName="GitRoot"/>
</Exec>
</Target>
<Target Name="PostBuild" AfterTargets="PostBuildEvent" DependsOnTargets="FindGitRoot">
<!-- <Message Text="Git Root is: $(GitRoot)" Importance="high" /> -->
<!-- Execute script, located in directory from GitRoot var -->
<Exec Command='pwsh -NoProfile -ExecutionPolicy Bypass -File
"$(GitRoot)/scripts/thescript.ps1"
"$(ProjectDir)$(OutDir)manifest.txt"' />
</Target>