I have seen this other question that is inspiring what I'm trying to do: Share a common build step between VS 2022 on Windows and Mac.
The accepted answer lack one major thing for me (on Mac): dealing with arguments.
On Windows, and thus on Mac, I have this and it works perfectly fine:
$(ProjectDir)GenerateConfig $(ProjectDir) $(ConfigurationName)
Here is my Windows script, named GenerateConfig.cmd :
ECHO %1
ECHO %2
COPY /Y "%1Configuration\%2\specific.connectionstring.appsettings.json" "%1specific.connectionstring.appsettings.json"
COPY /Y "%1Configuration\%2\specific.rtelog.appsettings.json" "%1specific.rtelog.appsettings.json"
COPY /Y "%1Configuration\%2\specific.deviceconfiguration.appsettings.json" "%1specific.deviceconfiguration.appsettings.json"
COPY /Y "%1Configuration\%2\appsettings.json" "%1appsettings.json"
DEL "%1\web.config"
if "%2"=="Debug" ( echo "why, Microsoft, why") else (COPY /Y "%1Configuration\%2\web.config" "%1\web.config")
On Mac I've created a GenerateConfig file (without extension) with the following content:
cp -f "$1Configuration/$2/specific.connectionstring.appsettings.json" "$1specific.connectionstring.appsettings.json"
cp -f "$1Configuration/$2/specific.rtelog.appsettings.json" "$1specific.rtelog.appsettings.json"
cp -f "$1Configuration/$2/specific.deviceconfiguration.appsettings.json" "$1specific.deviceconfiguration.appsettings.json"
cp -f "$1Configuration/$2/appsettings.json" "$1appsettings.json"
rm "$1web.config"
I make it executable with the command "chmod 755..."
When I build the project, it gaves me the following errors:
Target PreBuild:
/Users/omatrot/Documents/rtetech/SafeProtect.WebAdmin/SafeProtect.WebAdmin.Api/GenerateConfig /Users/omatrot/Documents/rtetech/SafeProtect.WebAdmin/SafeProtect.WebAdmin.Api/ PreProd Debug
/Users/omatrot/Documents/rtetech/SafeProtect.WebAdmin/SafeProtect.WebAdmin.Api/GenerateConfig: line 1: cp: command not found
rm: /Users/omatrot/Documents/rtetech/SafeProtect.WebAdmin/SafeProtect.WebAdmin.Api/web.config: No such file or directory
/Users/omatrot/Documents/rtetech/SafeProtect.WebAdmin/SafeProtect.WebAdmin.Api/SafeProtect.WebAdmin.Api.csproj(167,5): error MSB3073: The command "/Users/omatrot/Documents/rtetech/SafeProtect.WebAdmin/SafeProtect.WebAdmin.Api/GenerateConfig /Users/omatrot/Documents/rtetech/SafeProtect.WebAdmin/SafeProtect.WebAdmin.Api/ PreProd Debug" exited with code 1.
What is wrong with this script? I'm particularly interested in the error:
line 1: cp: command not found
Any Help appreciated.
The source of the problem was that the script file format was UTF8 with BOM. I had to save it to UTF8 to solve my problem.
This answer led me to the problem.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.