Giter Club home page Giter Club logo

textreplace's Introduction

TextReplace Wix Extension

TextReplace is a WiX extension that allows you to do regular expression find and replace on text files during an install I built it because I had a particular need for something similar, and I had need of a new side project to keep me amused during the long commute to work.

License

The code is licensed under the MIT License. See license.txt for details.

Building

The component was designed to be build in VS2015. It may build in earlier versions, but this hasn't been tested. It will build in VS2015 Community. Note you will require both C# and C++ libraries installed in order to build it - the extension is written in C#, but the custom action it's built on is written in C++. It just a case of loading the solution and hitting "build".

The solution will build in VS2017 Community as well, although you will need to upgrade the projects on loading for the first time.

The built extension is under the TextReplace\bin folder. You only need the TextReplace.dll.

Usage

To use text replace, you need to do two things:

  1. Add the namespace http://schemas.rottedfrog.co.uk/wix/TextReplace to your WixElement:
  2. Add TextReplace elements to the components you want to associate the change to.

The TextReplace element has 3 attributes:

Attribute Description
Id A unique name to identify the replacement
File The name of a file. This field accepts formatted values
Match An Expression to replace with
Replace A replacement expression. You can use captured numbered references $1..$9 for different captures from the match expression. $& is the whole matched expression.

Things to note about Match and replace:

The Match and Replace expressions use ECMAScript syntax for regexes and replacement strings. For more information go to https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions

Note that both expressions can be read either as formatted strings or non-formatted strings. They are by default not formatted. If you add the special prefix [@@], then the expression will be read as a formatted string and you can include property values. Note that for Match, you will need to escape square brackets and braces if you make it formatted.

Example:

<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" xmlns:tx="http://schemas.rottedfrog.co.uk/wix/TextReplace">
	<Fragment>
		<DirectoryRef Id="INSTALLFOLDER">
      <Component Id="Comp1">
        <File Id="testfile" Source="Testfile.txt" />
        <tx:TextReplace Id="text1" File="[#testfile]" Match="Hello " Replace="$&amp;$&amp;" />
      </Component>
		</DirectoryRef>
	</Fragment>
</Wix>

This will replace the string 'Hello World' in the test file with 'Hello Hello World'.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.