Insert DateTime.Now to a Web.Config during publish/deploy

2k Views Asked by At

I want to have a date when an application was deployed/published in my Web.Config.

Is there a way to achieve that with web.config transformations?

With xdt:Transform="Replace" I can replace any node with predefined value, but is there a way to use some custom function to calculate that value (like DateTime.Now)?

1

There are 1 best solutions below

0
On

I don't think you can do this with the config transforms (although I'm not 100% certain).

I would suggest using the MSBuild Extension Pack which contains a DateAndTime task to get the current Date and a Detokenise task to perform token replacement on a file.

You could then either:

  1. edit your website csproj file remove the comments around the AfterBuild target, and place your tasks there
  2. write a separate MSBuild script and run that after your site builds.

Hope that helps.