Search code examples
c#.net-corecsprojpost-build-event

how to write cross platform postbuild event in dotnet core


I need some help writing a post build event that would work cross platform. The following in my csproj file will work on windows but not Unix. Thanks.

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

Solution

  • For this specific case, it might be easier to use the MSBuild Copy Task.

    In your csproj file:

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

    That being said, Windows will happily accept / as a path separator, even mixing them in the same string.