Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to force replace an element using config transform in Visual Studio?
    primarykey
    data
    text
    <p>We know that Visual Studio has this awesome feature to transform Web.config on publish. So we can have something like the following in Web.Release.config to replace the original value in Web.config:</p> <p>Web.config:</p> <pre><code>&lt;add key="SomeKey" value="DebugValue"/&gt; </code></pre> <p>Web.Release.config:</p> <pre><code>&lt;add key="SomeKey" value="ReleaseValue" xdt:Transform="Replace" xdt:Locator="Match(key)"/&gt; </code></pre> <p>This is all good as long as you don't have a typo in the transform config. So for instance if you have the following line in your transform config:</p> <pre><code>&lt;add key="SomeKeyTypo" value="ReleaseValue" xdt:Transform="Replace" xdt:Locator="Match(key)"/&gt; </code></pre> <p>Then "SomeKey" item is not going to be replaced because transform will not find the key and will silently print this warning:</p> <pre><code>...\Web.Release.config: Warning : No element in the source document matches '/configuration/appSettings/add[@key='SomeKeyTypo']' </code></pre> <p>The <strong>problem</strong> is that under some situations like if you change the key in the main Web.config and you forget to change it in Web.Release.config, when you publish there is a good chance that you don't read the publish output messages and you miss the Warning, which can end up in disaster because the Debug value will be used in your application instead of the Release value. </p> <p>So the <strong>question</strong> is when you define the transform in Web.Release.config is there a way to indicate that the given item MUST be replaced and if the key is not found <em>throw and ERROR instead of WARNING</em> and basically exit the publish with some error code?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload