Core: How to edit Post-build script which can support windows & Linux

Created on 16 Nov 2018  路  4Comments  路  Source: dotnet/core

General

I have a aspnetcore project need copy some files to other folder after build, post-build script is best idea.
Example:
xcopy $(OutDir)Mocks\* $(ProjectDir)\Mocks\ /Y /D /R /S

But it just work on windows.

Does it support cross-platform?

My build environment is in docker, docker image microsoft/dotnet:2.1.500-sdk.

question

Most helpful comment

@tiayi You can do this with the MSBuild Copy task in a target. Something like this:

<Target Name="CopyMocks" AfterTargets="Build">
  <ItemGroup>
      <MockFile Include="$(OutDir)Mocks\**\*.*" />
  </ItemGroup>
  <Copy 
      SourceFiles="@(MockFile)" 
      DestinationFolder="$(ProjectDir)\Mocks\%(RecursiveDir)" 
      SkipUnchangedFiles="true" />
</Target>

All 4 comments

I think msbuild has copy-file options. Can you use that?
Otherwise you will have to have specific Linux vs. Windows copy code.

@nguerrera @dsplaisted any insights?

@tiayi You can do this with the MSBuild Copy task in a target. Something like this:

<Target Name="CopyMocks" AfterTargets="Build">
  <ItemGroup>
      <MockFile Include="$(OutDir)Mocks\**\*.*" />
  </ItemGroup>
  <Copy 
      SourceFiles="@(MockFile)" 
      DestinationFolder="$(ProjectDir)\Mocks\%(RecursiveDir)" 
      SkipUnchangedFiles="true" />
</Target>

Oh, that's helpful. Thank you.

Seems to be answered, closing.

Was this page helpful?
0 / 5 - 0 ratings