2012-06-11 3 views
0

다음 xml의 Constine> 노드 정의 <에서 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> 

비교 : I 제품 버전이 필요 후 라인의 나머지 부분을 캡처하려고 생각

$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