与Windows和Mac上的Visual Studio之间的参数共享Pre Build步骤
我看过启发我要做的事情:在Windows和Mac上的2022 Vs 2022之间分享一个共同的构建步骤。
公认的答案对我来说缺乏一件事(在Mac上):处理论点。
在Windows上,因此在Mac上,我有此功能,它的工作原理很好:
$(ProjectDir)GenerateConfig $(ProjectDir)$(configurationName)
这是我的Windows脚本,名为 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")
在Mac上,我创建了 genteconfig file(无扩展)使用以下内容:
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:找不到命令
任何帮助。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题的来源是脚本文件格式是带有BOM的UTF8。我必须将其保存到UTF8来解决我的问题。
此答案带我解决了这个问题。
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.