visual studio 2010 -从命令行构建安装项目(vdproj)时,是否可以设置MSI的版本号?



我需要从命令行构建一个安装项目,并从参数设置构建的msi的版本号。这有可能实现吗?

不,不可能。您必须将. vdproj重写为预构建步骤,或将MSI更新为后构建步骤。工具集

的众多限制之一

我创建了一个vbs脚本,可以完成Christopher在他的回答中建议的内容。您需要在构建.vdproj之前执行此脚本。该脚本将.vdproj文件名作为第一个参数,版本作为第二个参数(**.**)。**格式):

'Function that generates a new GUID
Function CreateGUID
  Dim TypeLib
  Set TypeLib = CreateObject("Scriptlet.TypeLib")
  CreateGUID = Mid(TypeLib.Guid, 2, 36)
End Function
Const ForReading = 1
Const ForWriting = 2
'Read vdproj filename and new version from arguments and generate new Guid
installerFileName = Wscript.Arguments(0)
newProductVersion = Wscript.Arguments(1)
newProductCode = CreateGUID()
newPackageCode = CreateGUID()
'Prepare Regexs
Set productVersionRegex = New RegExp
With productVersionRegex
 .Pattern    = Chr(34) & "ProductVersion" & Chr(34) & " = " & Chr(34) & "8:(.*)" & Chr(34)
 .IgnoreCase = False
End With
Set productCodeRegex = New RegExp
With productCodeRegex
 .Pattern    = Chr(34) & "ProductCode" & Chr(34) & " = " & Chr(34) & "8:{(.*)}" & Chr(34)
 .IgnoreCase = False
End With
Set packageCodeRegex = New RegExp
With packageCodeRegex
 .Pattern    = Chr(34) & "PackageCode" & Chr(34) & " = " & Chr(34) & "8:{(.*)}" & Chr(34)
 .IgnoreCase = False
End With
'Read Text from installer file
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(installerFileName, ForReading)
installerText = objFile.ReadAll
objFile.Close
'Replace ProductVersion
newProductVersionString = Chr(34) & "ProductVersion" & Chr(34) & " = " & Chr(34) & "8:" & newProductVersion & Chr(34)
installerNewText = productVersionRegex.Replace(installerText, newProductVersionString)
'Replace ProductCode Guid
newProductCodeString = Chr(34) & "ProductCode" & Chr(34) & " = " & Chr(34) & "8:{" & newProductCode & "}" & Chr(34)
installerNewText = productCodeRegex.Replace(installerNewText, newProductCodeString)
'Replace UpgradeCode  Guid
newPackageCodeString = Chr(34) & "PackageCode" & Chr(34) & " = " & Chr(34) & "8:{" & newPackageCode & "}" & Chr(34)
installerNewText = packageCodeRegex.Replace(installerNewText, newPackageCodeString)
'Write new Text in installer file
Set objFile = objFSO.OpenTextFile(installerFileName, ForWriting)
objFile.Write installerNewText
objFile.Close

脚本可以这样调用:

cscript script.vbs Installer.vdproj 1.2.5

是的,您可以这样做,您只需要一个工具来更新项目定义文件**.vdproj。* *。以Csproj为例如下:项目定义文件如下所示(您需要打开**。Csproj文件(记事本或其他):

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
   .......
    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>`

"v4.0"是要替换的目标字段,在替换该字段之后,然后触发msbuild来构建您的项目,如"msbuild **.csproj"

相关内容

  • 没有找到相关文章

最新更新