3

How to make XCOPY in Visual Studio Post Build Event Command Line support both Linux and Windows? I have a post build event command line in my C# project and can works well on windows, but always failed when build in GitHub CI action, due to GitHub CI is using Linux system. Here is my command line:

set solutionDir=$(SolutionDir)
set splitChar=%solutionDir:~-1%
set fileName=blazor.webassembly.js
set originPath=$(SolutionDir)BuildTools%splitChar%%fileName%
set destinationPath=$(TargetDir)wwwroot%splitChar%_framework%splitChar%%fileName%

echo OriginPath=%originPath%
echo DestinationPath=%destinationPath%
XCOPY %originPath% %destinationPath% /Y
XCOPY command works well on windows, and output:
22>OriginPath=C:\GitRepositories\HackSystem\BuildTools\blazor.webassembly.js
22>DestinationPath=C:\GitRepositories\HackSystem\HackSystem.Web\bin\Debug\net6.0\wwwroot\_framework\blazor.webassembly.js

But when deploy to GitHub CI action, always failed:

/home/runner/work/HackSystem/HackSystem/HackSystem.Web/HackSystem.Web.csproj(51,5): error MSB3073: The command "set solutionDir=/home/runner/work/HackSystem/HackSystem/
/home/runner/work/HackSystem/HackSystem/HackSystem.Web/HackSystem.Web.csproj(51,5): error MSB3073: set splitChar=%solutionDir:~-1%
/home/runner/work/HackSystem/HackSystem/HackSystem.Web/HackSystem.Web.csproj(51,5): error MSB3073: set fileName=blazor.webassembly.js
/home/runner/work/HackSystem/HackSystem/HackSystem.Web/HackSystem.Web.csproj(51,5): error MSB3073: set originPath=/home/runner/work/HackSystem/HackSystem/BuildTools%splitChar%%fileName%
/home/runner/work/HackSystem/HackSystem/HackSystem.Web/HackSystem.Web.csproj(51,5): error MSB3073: set destinationPath=/home/runner/work/HackSystem/HackSystem/HackSystem.Web/bin/Release/net6.0/wwwroot%splitChar%_framework%splitChar%%fileName%
/home/runner/work/HackSystem/HackSystem/HackSystem.Web/HackSystem.Web.csproj(51,5): error MSB3073: 
/home/runner/work/HackSystem/HackSystem/HackSystem.Web/HackSystem.Web.csproj(51,5): error MSB3073: echo OriginPath=%originPath%
/home/runner/work/HackSystem/HackSystem/HackSystem.Web/HackSystem.Web.csproj(51,5): error MSB3073: echo DestinationPath=%destinationPath%
/home/runner/work/HackSystem/HackSystem/HackSystem.Web/HackSystem.Web.csproj(51,5): error MSB3073: XCOPY %originPath% %destinationPath% /Y" exited with code 127.
    1 Warning(s)
    1 Error(s)
CuteLeon
  • 31
  • 3

0 Answers0