using MSBuild.ExtensionPack.FileSystem.File Replace on vdproj

4.1k Views Asked by At

Im trying to replace the ProductName held inside a Visual Studio setup project by performing a regex on the file in my msbuild script. To do the regEx replacement Im trying to use msbuild extension pack and in particular its File task. The target inside my msbuild script looks like this:

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

When this target runs I get the following output, but the file remains unchanged.

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

Am I going about this right way? Has anyone done regex updated on a vdproj (or anything else) in this manner?

1

There are 1 best solutions below

1
On BEST ANSWER

I had this same issue and after trying a few things, I got this to work...

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

This will simply replace the ProductVersion string with the version that I have in my Solution.DeploymentProject variable.

I dont believe you need to mess with CDATA at all.