【问题标题】:using MSBuild.ExtensionPack.FileSystem.File Replace on vdproj在 vdproj 上使用 MSBuild.ExtensionPack.FileSystem.File 替换
【发布时间】:2011-04-12 10:14:36
【问题描述】:

我试图通过对我的 msbuild 脚本中的文件执行正则表达式来替换 Visual Studio 安装项目中保存的 ProductName。要进行正则表达式替换,我正在尝试使用 msbuild extension pack,尤其是它的 File 任务。我的 msbuild 脚本中的目标如下所示:

<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 msbuild vdproj msbuildextensionpack


    【解决方案1】:

    我遇到了同样的问题,在尝试了一些事情之后,我得到了这个工作......

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

    这将简单地将 ProductVersion 字符串替换为我在 Solution.DeploymentProject 变量中的版本。

    我认为你根本不需要弄乱 CDATA。

    【讨论】:

    • 替换会不会太晚而无法在 .msi 中结束?
    猜你喜欢
    • 1970-01-01
    • 2011-02-07
    • 2010-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多