我需要在每次成功构建时增加安装程序的版本。我添加了一个 VBscript 文件并从预构建事件中调用它。但我无法获得实际结果。我的脚本如下:
set a = wscript.arguments
if a.count = 0 then wscript.quit 1
'read and backup project file
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(a(0))
s = f.ReadAll
f.Close
fbak = a(0) & ".bak"
if fso.fileexists(fbak) then fso.deletefile fbak
fso.movefile a(0), fbak
'find, increment and replace version number
set re = new regexp
re.global = true
re.pattern = "(""ProductVersion"" = ""8:)(\d+(\.\d+)+)"""
set m = re.execute(s)
v = m(0).submatches(1)
v1 = split(v, ".")
v1(ubound(v1)) = v1(ubound(v1)) + 1
vnew = join(v1, ".")
'msgbox v & " --> " & vnew
s = re.replace(s, "$1" & vnew & """")
'replace ProductCode
re.pattern = "(""ProductCode"" = ""8:)(\{.+\})"""
guid = CreateObject("Scriptlet.TypeLib").Guid
guid = left(guid, len(guid) - 2)
s = re.replace(s, "$1" & guid & """")
'replace PackageCode
re.pattern = "(""PackageCode"" = ""8:)(\{.+\})"""
guid = CreateObject("Scriptlet.TypeLib").Guid
guid = left(guid, len(guid) - 2)
s = re.replace(s, "$1" & guid & """")
'write project file
fnew = a(0)
set f = fso.CreateTextfile(fnew, true)
f.write(s)
f.close
我的预构建事件是 C:\Projects\VersionProject\myscript.vbs "$(ProjectDir)VersionProject.Installer.vdproj"。感谢任何帮助。
最佳答案
您需要进入 vdproj 文件并找到格式为“ProductVersion”=“8:1.0.0”的字符串
并将字符串从(比如)1.0.0 更改为 1.0.1。
但是,如果仅此而已,您可能会遇到更新问题。请注意,当您在安装项目中增加 ProductVersion 时,它会提示更改 ProductCode,并且还会更改 MSI 文件的 PackageCode。因此,版本的安全更改涉及所有这些事情。例如,如果您仅更改版本并尝试重新安装 MSI,它将失败并显示“已安装此产品的另一个版本”。如果您不了解这些内容,我建议您熟悉 ProductCode、UpgradeCode、ProductVersion 以及 RemovePreviousVersions 的交互方式,并注意创建的每个新 MSI 都需要一个新的 PackageCode。
关于c# - 安装项目的自动增量版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35403362/