2012-06-11 40 views
0

我想要替換以下xml的DefineConstants>節點中的ProductVersion值<。剩餘部分必須保留。 實施例:使用ANT替換xml中的值

<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)" /> 

回答

1

我認爲,試圖捕捉行的剩餘部分後的產品版本是不必要的。

您不必擔心這一點。如果您的正則表達式僅剩下文本的其餘部分,則只能替換ProductVersion。

我有這樣的成功:

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

它正在工作。 :) – Ganeshkumar

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> 
+0

它刪除這條線的YYYY一部分。 預期輸出: XXXXX;的ProductVersion = 21.58.44; YYYYY 實際輸出: XXXXX;的ProductVersion = 21.58.44; Ganeshkumar

+0

不,它不需要。在將'\ 1'更改爲'\ 2'之後不會。 – sudocode