0

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.

  • you can out `echo` before the problematic lines to see if it will print the command you want to execute. – npocmaka Apr 20 '22 at 15:50
  • I suppose the file `GenerateConfig` on Mac needs additionally the shebang, i.e the first line should be `#!/bin/bash` to inform MAC OS which program to run (`/bin/bash`) to get the script with the executable attribute really executable. – Mofi Apr 21 '22 at 06:26
  • line 1: #!/bin/bash: No such file or directory –  Apr 21 '22 at 07:53

1 Answers1

0

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.