在Windows和Mac上共享Visual Studio的预构建步骤



我看到了另一个问题,这是启发我想做的:在Windows和Mac上共享VS 2022之间的共同构建步骤。

被接受的答案对我来说缺少一件重要的事情:处理参数

在Windows上,因此在Mac上,我有这个,它运行得很好:

$(ProjectDir)GenerateConfig $(ProjectDir) $(ConfigurationName)

这是我的Windows脚本,命名为GenerateConfig.cmd:
ECHO %1
ECHO %2
COPY /Y "%1Configuration%2specific.connectionstring.appsettings.json" "%1specific.connectionstring.appsettings.json"
COPY /Y "%1Configuration%2specific.rtelog.appsettings.json" "%1specific.rtelog.appsettings.json"
COPY /Y "%1Configuration%2specific.deviceconfiguration.appsettings.json" "%1specific.deviceconfiguration.appsettings.json"
COPY /Y "%1Configuration%2appsettings.json" "%1appsettings.json"
DEL  "%1web.config"
if "%2"=="Debug" ( echo "why, Microsoft, why") else (COPY /Y "%1Configuration%2web.config" "%1web.config")

在Mac上,我创建了一个GenerateConfig包含以下内容的文件(不带扩展名):

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"

我用命令"chmod 755…"使它可执行

当我构建项目时,它给了我以下错误:

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.

这个脚本有什么问题?我对以下错误特别感兴趣:

第1行:cp: command not found

感谢您的帮助。

问题的根源是脚本文件格式是带BOM的UTF8。我不得不把它保存为UTF8来解决我的问题。

这个答案使我找到了问题所在。

最新更新