我想替换以下 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)MicrosoftWiXv3.xWix.targets</WixTargetsPath>
<WixTargetsPath Condition=" '$(WixTargetsPath)' == '' ">$(MSBuildExtensionsPath)MicrosoftWiXv3.xWix.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=SoftwareMicrosoftXSSE;</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)" />
我认为没有必要尝试在产品版本之后捕获该行的其余部分。
你不需要担心这一点。如果您的正则表达式不理会文本的其余部分,则只能替换产品版本。
我在这方面取得了成功:
<replaceregexp file="${basedir}Installer.wixproj"
match="ProductVersion=[0-9]+.?[0-9]+.?[0-9]+.?[0-9]+.?;"
replace="ProductVersion=${SpaceVersion};"
byline="true"
/>
您需要使用 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>