0

我想替换以下 xml 的 <DefineConstants> 节点处的 ProductVersion 值。必须保留该行的剩余部分。例子:

<DefineConstants>XXXXX;ProductVersion=20.323.23;YYYYY</DefineConstants>

<DefineConstants>XXXXX;ProductVersion=21.58.44;YYYYY</DefineConstants>

我试过了,replaceregexp但它改变了剩余的内容。

<replaceregexp file="${basedir}\Installer.wixproj"
     match="ProductVersion=([0-9].*);(.*)"
     replace="ProductVersion=${SpaceVersion};\1"
     byline="true"
/>

你能指导我在这方面做错了什么吗?

XML:

<?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>
      <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
      <ProductVersion>3.5</ProductVersion>
      <ProjectGuid>{6bc0a85b-9c15-41e6-874b-5fe07e5338e6}</ProjectGuid>
      <SchemaVersion>2.0</SchemaVersion>
      <OutputName>Installer</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>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
      <OutputPath>bin\$(Configuration)\</OutputPath>
      <IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath>
      <DefineConstants>Debug;</DefineConstants>
      <WixVariables>
      </WixVariables>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
      <OutputPath>bin\$(Configuration)\</OutputPath>
      <IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath>
      <DefineConstants>SourceDir=$(SolutionDir)XSSE\;ProductVersion=3.3.1.75;ProductName=XSSE;ToolchinShortcut=XSSEToolchinShortcut;ExtensionDir=XSSE;ManifestFileName=extension.vsixmanifest;PkageDefFileName=XSSE.ToolchainProvider.pkgdef;REGKEY=Software\Microsoft\XSSE;</DefineConstants>
      <WixVariables>XYZ=123;</WixVariables>
   </PropertyGroup>
   <ItemGroup>
      <Compile Include="filefragment.wxs" />
      <Compile Include="Product.wxs" />
   </ItemGroup>
   <ItemGroup>
      <WixExtension Include="WixUIExtension">
         <HintPath>$(WixExtDir)\WixUIExtension.dll</HintPath>
         <Name>WixUIExtension</Name>
      </WixExtension>
   </ItemGroup>
   <Import Project="$(WixTargetsPath)" /> 

4

2 回答 2

1

我认为没有必要在产品版本之后尝试捕获该行的其余部分。

你不必担心这一点。如果您的正则表达式单独留下其余文本,您可以只替换 ProductVersion。

我在这方面取得了成功:

<replaceregexp file="${basedir}\Installer.wixproj"
    match="ProductVersion=[0-9]+\.?[0-9]+\.?[0-9]+\.?[0-9]+\.?;"
    replace="ProductVersion=${SpaceVersion};"
    byline="true"
    />
于 2012-06-11T09:32:30.483 回答
0

您需要使用\2而不是\1.

<replaceregexp file="${basedir}\Installer.wixproj"
       match="ProductVersion=([0-9].*);(.*)"
       replace="ProductVersion=${SpaceVersion};\2"
       byline="true"
        />

独立测试:

<project default="test">

    <property name="SpaceVersion" value="a.b.c"/>

    <target name="test">
      <replaceregexp file="test.xml"
         match="ProductVersion=([0-9].*);(.*)"
         replace="ProductVersion=${SpaceVersion};\2"
         byline="true"
       />
    </target>
</project>

更改文件与原始文件的比较:

$diff test.xml test.xml.0
2c2
<     <DefineConstants>XXXXX;ProductVersion=a.b.c;YYYYY</DefineConstants>
---
>     <DefineConstants>XXXXX;ProductVersion=20.323.23;YYYYY</DefineConstants>
于 2012-06-11T09:30:31.307 回答