如何在每次创建msi期间动态更改wix中的产品版本

时间:2013-03-22 05:36:34

标签: python-2.7 wix wix3.7

我有一个脚本,我将产品的版本号变为变量'PRODUCTVERSION',即

PRODUCTVERSION= subprocess.check_output('svnversion c:\sandbox -n', shell=False)

我想将此变量'PRODUCTVERSION'作为msbuild属性传递给wix。下面是我尝试的代码,但结果却出现错误,

light.exe : error LGHT0001: Illegal characters in path.    

这是我的剧本,

def build(self,projpath):
    PRODUCTVERSION= subprocess.check_output('svnversion c:\sandbox -n', shell=False)
    arg1 = '/t:Rebuild'
    arg2 = '/p:Configuration=Release'
    arg3 = '/p:Platform=x86'
    arg4 = '/p:ProductVersion=%PRODUCTVERSION%'
    p = subprocess.call([self.msbuild,projpath,arg1,arg2,arg3])

我的wix项目中的属性是

<PropertyGroup>
  <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
  <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
  <ProductVersion>$(ProductVersion)</ProductVersion>
  <ProjectGuid>{d559ac98-4dc7-4078-b054-fe0da8363ad0}</ProjectGuid>
  <SchemaVersion>2.0</SchemaVersion>
  <OutputName>myapp.$(ProductVersion)</OutputName>
  <OutputType>Package</OutputType>
  <WixTargetsPath Condition=" '$(WixTargetsPath)' == '' AND '$(MSBuildExtensionsPath32)' != '' ">$(MSBuildExtensionsPath32)\Microsoft\WiX\v3.x\Wix.targets</WixTargetsPath>
  <WixTargetsPath Condition=" '$(WixTargetsPath)' == '' ">$(MSBuildExtensionsPath)\Microsoft\WiX\v3.x\Wix.targets</WixTargetsPath>
  <WixVariables>Version=$(ProductVersion)</WixVariables>
</PropertyGroup>

我想将输出名称显示为'myapp-2.0.PRODUCTVERSION',其中PRODUCTVERSION是我从python脚本获得的版本号。请帮我找到解决方法。

2 个答案:

答案 0 :(得分:2)

documentation表明,对于ProductVersion Light,期望格式为x.x.x.x的内容。

如果你想让你的MSI以版本命名,我总是使用post-build命令来重命名文件,因此......

  <Target Name="AfterBuild">
    <Copy SourceFiles=".\bin\$(Configuration)\$(OutputName).msi" DestinationFiles=".\bin\$(Configuration)\$(OutputName)_v%(myVersionNumer).msi" />
    <Delete Files=".\bin\$(Configuration)\$(OutputName).msi" />
  </Target>

答案 1 :(得分:0)

def build(self,projpath):
    PRODUCTVERSION = subprocess.check_output('svnversion c:\my path\to svn\ -n', shell=False)
    arg1 = '/t:Rebuild'
    arg2 = '/p:Configuration=Release'
    arg3 = '/p:Platform=x86'
    arg4 = '/p:ProductVersion=%s' %(PRODUCTVERSION)
    proc = subprocess.Popen(([self.msbuild,projpath,arg1,arg2,arg3,arg4]), shell=True, 
                    stdout=subprocess.PIPE) 
    while True:
        line = proc.stdout.readline()                        
        wx.Yield()
        if not line: break
    proc.wait() 

并在wixproject中将上述参数作为MSBuild属性传递给后构建,

<Target Name="AfterBuild">
<Copy SourceFiles=".\bin\$(Configuration)\$(OutputName)-$(ProductVersion).msi" DestinationFiles=".\bin\$(Configuration)\$(OutputName)-$(ProductVersion).msi" />
<Delete Files=".\bin\$(Configuration)\$(OutputName).msi" />
</Target>