Matt
Matt

Reputation: 26981

Replace string in ASPX with build version at build time

Is there a way to look for a pattern in aspx/ascx files and replace it with a build number or some other token? I'm not interested in using reflection and setting the string at runtime. I'd like to go into the aspx/ascx files and replace the string using msbuild.

Is this possible?

Upvotes: 2

Views: 231

Answers (1)

Sean Glover
Sean Glover

Reputation: 1786

There's a project called MSBuild Community Tasks that contains a FileUpdateTask. This should satisfy your requirement. It allows you to make arbitrary text replacements using regular expressions.

<FileUpdate Files="MyWebPage.aspx"
            Regex="\<div id\=\'version\'\>(.*)\<\/div\>"
            ReplacementText="$(BuildVersion)" />

Please note that I haven't tested this regular expression.

Upvotes: 3

Related Questions