CSPROJPostbuild命令在存储库根目录中执行脚本

问题描述 投票:0回答:1

在csproj文件中,我定义了一个邮政构建目标以执行命令,从 在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>

未能抱怨

$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.

我了解变量未正确分配,或者它没有执行正确的命令,但我不知道如何修复它。任何帮助将不胜感激。
    

即将使命令复杂化以在目标exec中执行,一个可能的解决方案是使用msbuild的功能:

<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 &quot;$(GitRoot)/scripts/thescript.ps1&quot; &quot;$(ProjectDir)$(OutDir)manifest.txt&quot;' /> </Target>
c# visual-studio msbuild csproj
1个回答
0
投票

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.