Updating web.config with an MSBUILD task
-
20-09-2019 - |
Question
I'm using an Web Deployment project to do a few post build tasks on a website I'm deploying.
I want to use a FileUpdate task to update my web.config and change the compilation mode from debug="true"
to debug="false".
So, from this
<compilation defaultLanguage="c#"
debug="true" />
To this
<compilation defaultLanguage="c#"
debug="false" />
My FileUpdateTask looks like this
<FileUpdate Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU'"
Files="$(Configuration)\Web.Config"
Regex="debug=\"true\""
ReplacementText="debug=\"false\"" />
but that is completely invalid as you can't escape a quote in XML.
How else can I match the debug attribute in the Regex and have a valid ReplacementText value?
Cheers
Solution
either use the XmlUpdate task from MSBuild Community Tasks or try a regex of:
Regex="debug="true""
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow