Reputation: 1929
We're using a library that needs to have a value updated in the web.config with every build. Is there a way to do this natively?
We're using a library that has a custom config section in the web.config
The version attribute needs to be updated with every build. Increment or even DateTime.Now equivalent would work.
<clientDependency version="6">
...
</clientDependency>
Upvotes: 1
Views: 1930
Reputation: 94
Here is other sample to do with XmlPoke in MSBuild.
Auto replace VersionBuild value with yyyyMMddmmss when publish
Web.config
<appSettings>
<add key="VersionBuild" value=".121"/>
</appSettins>
<Target Name="BeforeBuild">
<PropertyGroup>
<CurrentDate>$([System.DateTime]::Now.ToString(yyyyMMddmmss))</CurrentDate>
</PropertyGroup>
<XmlPoke
Condition="'$(PublishProfileName)' != ''"
XmlInputPath="Web.config"
Query="/configuration/appSettings/add[@key = 'VersionBuild']/@value"
Value=".$(CurrentDate)" />
</Target>
Upvotes: -1
Reputation: 5767
You can try using MSBuild Tasks.
Maybe XMLPoke to update the web.config
with a formatted date/time string:
<Target Name="EchoTime">
<Time Format="yyyyMMddHHmmss">
<Output TaskParameter="FormattedTime" PropertyName="currentTime" />
</Time>
<Message Text = "$(currentTime)" />
</Target>
<Target Name="UpdateWebConfig">
<XmlPoke
XmlInputPath="web.config"
Query="//<complete-path>/clientDependency/@version"
Value="$(currentTime)" />
</Target>
Moving the updatable section to an external file, using configSource
could also make the job easier.
Upvotes: 4
Reputation: 17014
You should first review, why exactly the config change on every build. This seems not to be good. Maybe you can change this.
However, with Visual Studio 2013 the Gulp Task Runner was introduced.
You could abuse it a little bit.
Basicly:
Write a *.config
file on every build, which includes only the changing settings.
In your web.config
you include the *.config
.
Upvotes: 1