【问题标题】:how to write cross platform postbuild event in dotnet core如何在 dotnet core 中编写跨平台构建后事件
【发布时间】:2023-05-29 12:42:01
【问题描述】:

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

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

【问题讨论】:

    标签: c# .net-core csproj post-build-event


    【解决方案1】:

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

    在您的 csproj 文件中:

        <ItemGroup>
            <MySourceFiles Include=$(TargetDir)\bin\*.dll"/>
        </ItemGroup>
    
        <Target Name="CopyFiles">
            <Copy
                SourceFiles="@(MySourceFiles)"
                DestinationFolder="$(TargetDir)"
            />
        </Target>
    

    【讨论】: