Set web.config value with build number

Phil Dye's Avatar

Phil Dye

14 Jul, 2016 12:33 PM

What's the best approach to get the build number into a specific web.config value? I want to use it for cachebusting some CDN assets.

Phil

  1. Support Staff 1 Posted by Feodor Fitsner on 14 Jul, 2016 11:48 PM

    Feodor Fitsner's Avatar

    Hi Phil,

    You can make a simple PS script updating web.config during the build, something like: https://blogs.msdn.microsoft.com/sonam_rastogi_blogs/2014/08/18/upd...

  2. 2 Posted by Phil Dye on 18 Jul, 2016 12:40 PM

    Phil Dye's Avatar

    Thanks Feodor, that's worked brilliantly.

    For completeness, here's what I'm using;

    appveyor.yml

    before_build:
    - ps: .\ModifyAppSetting.ps1 $env:APPVEYOR_BUILD_FOLDER\Site.Web\web.config 'CdnPackageVersion' $env:APPVEYOR_BUILD_VERSION
    

    ModifyAppSetting.ps1

    Param($config, $key, $value)
    $doc = New-Object System.Xml.XmlDocument
    $doc.Load($config)
    $node = $doc.SelectSingleNode('configuration/appSettings/add[@key="' + $key + '"]')
    $node.Attributes['value'].Value = $value
    $doc.Save($config)
    

    Phil

  3. Phil Dye closed this discussion on 18 Jul, 2016 12:41 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac