gpt4 book ai didi

windows - 构建后事件适用于一个项目,但不适用于另一个项目

转载 作者:可可西里 更新时间:2023-11-01 10:15:59 24 4
gpt4 key购买 nike

我有 2 个项目,我正在尝试为其创建一个通用的构建后事件批处理文件。

这是 Visual Studio 中的命令:

构建后事件

if $(ConfigurationName) == Release ("$(ProjectDir)PostBuildRelease.bat" "$(TargetDir)" @(VersionNumber) "$(TargetFileName)" "$(TargetName)")

所以我用 4 个参数调用文件 PostBuildRelease.bat:

  • Bin\发布目录
  • 项目版本
  • 带扩展名的文件名
  • 不带扩展名的文件名

项目 1

这与这个批处理脚本完美配合:

CMD

SET parameter=%1 REM Full path to new bin\release\
SET parameter=%2 REM Full Version Number
SET parameter=%3 REM File name + extension
SET parameter=%4 REM File name - extension
SET "productionpath=Z:\Unused\Apps\LyncVdiChecker\"

MOVE %productionpath%%3 %productionpath%"_archive\"%4"."%DATE:~0,2%%DATE:~3,2%%DATE:~6,4%"-"%2
XCOPY %3 %productionpath%

将程序集复制到 Z:\Unused\Apps\LyncVdiChecker\ 并将现有版本复制到同一文件夹中的 _archive。存档版本也有日期和版本号替换文件扩展名。

项目2

这个批处理脚本也可以完美地工作(它做同样的事情,但在不同的文件夹和不同的项目中):

CMD

SET parameter=%1 REM Full path to new bin\release\
SET parameter=%2 REM Full Version Number
SET parameter=%3 REM File name + extension
SET parameter=%4 REM File name - extension
SET "productionpath=Z:\Unused\Apps\IT Support App\"

MOVE "Z:\Unused\Apps\IT Support App\"%3 "Z:\Unused\Apps\IT Support App\_archive\"%4"."%DATE:~0,2%%DATE:~3,2%%DATE:~6,4%"-"%2
XCOPY %3 "Z:\Unused\Apps\IT Support App"

但是,如果我尝试在 Project2 中使用 Project1(更通用的版本)中的相同脚本,即使这 2 个脚本是等效的,我也会出错:

错误

The command "if Release == Release ("C:\Users\Seb.Kotze\Source\Repos\Applications\ITSelfHelp\ITHelp\PostBuildRelease.bat" "C:\Users\Seb.Kotze\Source\Repos\Applications\ITSelfHelp\ITHelp\bin\Release\" 2.0.6100.20905 "IT Self Help.exe" "IT Self Help")" exited with code 4.

输出窗口:

The syntax of the command is incorrect.

Invalid number of parameters

这个错误是相当无用的,所以我尝试注释掉 MOVEXCOPY 两行并重新构建:

删除移动

同样的错误。

输出窗口:

Invalid number of parameters

删除 XCOPY

没有 Visual Studio 错误,但在输出窗口中出现:

The syntax of the command is incorrect.


参数输出

当我回显 Project2 中使用的参数时,一切似乎都井井有条:

"Path\to\Bin\Release"
2.0.6100.21082
"IT Self Help.exe"
"IT Self Help"
Z:\Unused\Apps\IT Support App\

我该如何调试这个问题?我的脚本怎么可能没有任何问题地运行良好,但是当针对不同的项目运行时,没有一个命令被识别?非常感谢任何帮助!

最佳答案

你应该规范化你所有的参数,所以它们不包含外引号。
然后您就可以以可靠的方式使用它们。
语法 set "variable=%~1" 避免了变量本身的外引号。

set "TargetDir=%~1"
set "VersionNumber=%~2"
set "TargetFileName=%~3"
set "TargetName=%~4"
SET "productionpath=Z:\IT Support App\"
set "dateStamp=%DATE:~0,2%%DATE:~3,2%%DATE:~6,4%"

MOVE "Z:\IT App\%TargetFileName%" "Z:\IT App\_archive\%TargetName%.%dateStamp%-%VersionNumber%"
XCOPY "%TargetFileName%" "Z:\IT App"

关于windows - 构建后事件适用于一个项目,但不适用于另一个项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39468188/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com