如何在 dotnet core 中编写跨平台构建后事件

Kev*_*ran 5 c# csproj post-build-event .net-core

我需要一些帮助来编写可以跨平台工作的构建后事件。我的 csproj 文件中的以下内容适用于 Windows,但不适用于 Unix。谢谢。

  <Target Name="PostBuild" AfterTargets="PostBuildEvent">
    <Exec Command="copy /Y &quot;$(TargetDir)bin\*.dll&quot; &quot;$(TargetDir)*.dll&quot;" />
  </Target>
Run Code Online (Sandbox Code Playgroud)

ESG*_*ESG 5

对于这种特定情况,使用MSBuild Copy Task可能会更容易。

在您的 csproj 文件中:

    <ItemGroup>
        <MySourceFiles Include=$(TargetDir)\bin\*.dll"/>
    </ItemGroup>

    <Target Name="CopyFiles">
        <Copy
            SourceFiles="@(MySourceFiles)"
            DestinationFolder="$(TargetDir)"
        />
    </Target>
Run Code Online (Sandbox Code Playgroud)

话虽这么说,Windows 很乐意接受/作为路径分隔符,甚至将它们混合在同一个字符串中。