2011-04-12 31 views
3

我試圖通過對我的msbuild腳本中的文件執行一個正則表達式來替換Visual Studio安裝項目中的ProductName。要執行regEx替換,我試圖使用msbuild extension pack,特別是它的文件任務。我的MSBuild腳本內的目標看起來是這樣的:使用MSBuild.ExtensionPack.FileSystem.File替換vdproj

<Target Name="CustomiseMsi"> 
<PropertyGroup> 
    <RegExPattern> 
    <![CDATA[(?:\""ProductName\"" = \""8:.*)]]> 
    </RegExPattern> 
    <RegExReplacement> 
    <![CDATA["\"ProductName\" = \"8:MyApp v1.0\""]]> 
    </RegExReplacement> 
    <RegExOutput></RegExOutput> 
</PropertyGroup> 

<MSBuild.ExtensionPack.FileSystem.File 
    TaskAction="Replace" 
    RegexPattern="$(RegExPattern)" 
    Replacement="$(RegExReplacement)" 
    Files="@(AbsolutePathToVdProjToParse)"> 
</MSBuild.ExtensionPack.FileSystem.File></Target> 

當這個目標運行我得到下面的輸出,但該文件保持不變。

CustomiseMsi: 
    Processing File Collection 
Processing File: C:\pathHere\mySetup.vdproj 

我該說這個正確的方法嗎?有沒有人用這種方式完成了vdproj(或其他任何東西)的regex更新?

回答

4

我有同樣的問題,並試圖幾件事後,我得到這個工作...

<MSBuild.ExtensionPack.FileSystem.File TaskAction="Replace" 
    TextEncoding="ASCII" RegexPattern='"ProductVersion" = "8:.*"' 
    Replacement='"ProductVersion" = "8:$(Version)"' 
    Files="%(Solution.DeploymentProject)"/> 

這將只需更換與版本的ProductVersion字符串,我在我的Solution.DeploymentProject變量。

我不相信你需要混淆CDATA。

+0

替換是不是太遲了,不會在.msi中結束? – reinierpost 2013-05-22 07:37:36