Search code examples
visual-studiocross-platform.net-corefile-copyingbuildconfiguration

Cross platform solution for copying files after compilation


In a .NET Core project, I want to copy some dll's after the project has compiled. I have successfully done that with a simple xcopy operation setup in the scripts -> postcompile section of the project.json file.

I want this copy-operation to be cross-platform, so xcopy is not an option (for Mac/Linux at least). Is there a way to copy the files that works cross platform, or some way to detect the platform so I can branch out and call a cmd script when on Windows and a shell script when on Mac/Linux?


Solution

  • Assuming you are using the project.json build system, this can be done by referencing a script file without the file extension in the "scripts" section.

    "scripts": {
      "postcompile": "copy-assets"
    }
    

    To support cross-plat, you need two script files in the same folder as project.json, copy-assets.cmd and copy-assets.sh. Make sure to chmod +x your .sh file to it can be executed.