Reputation: 40393
I'm looking for a way to have a GUID in my web.config file, which gets transformed into a new GUID at publish-time.
For example:
<add key="someGuid" value="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" />
and when you publish the app using MSBuild or Visual Studio's publish screen, the resulting config file, after transformation, contains a brand-new GUID, like:
<add key="someGuid" value="ab15c61ba16d1651a6c89a621d64c4f8" />
Basically, I need a new GUID every time I publish the app, but also need the ability to replace this GUID on demand without a full recompile.
Before I build something custom, using a placeholder and replacing the text manually, I wanted to see if there's a config transform or built-in MSBuild function that could help.
Upvotes: 2
Views: 1074
Reputation: 9938
In MSBuild, you can create a new GUID like this
<PropertyGroup>
<SomeGuid>$([System.Guid]::NewGuid())</SomeGuid>
</PropertyGroup>
And then you can use the XmlPoke task to make the replacement using your newly created property $(SomeGuid).
Excerpted from in the book MSBuild Trickery tricks #9 and #101
Upvotes: 2