Distinguish between configuring debug and release Webconfig

The configuration during each development is different from the configuration in actual production. In the past, the Webconfig was modified after release every time. It becomes troublesome if used too often, so I want to study Web.Debug.config and Web.Release.config.
However, according to the articles on the Internet, I configured some appSettings myself, but it does not take effect when running. After several searches, I couldn't find the problem. Just when I was about to give up, I saw an article about the solution to invalid settings of Web.Debug.config and Web.Release.config.
Based on the above experience, I found xx.Web.csproj . Open it in the Webconfig directory
Insert image description here
and scroll to the bottom of the article, uncomment the BeforeBuild and AfterBuild, and then add:

<TransformXml Source="Web.config" Transform="Web.$(Configuration).config" Destination="Web.config" />

Insert image description here

Afterwards, the debug and release modifications will take effect.
It is also recommended not to use xdt:Transform="Insert". This method will add appSettings every time it is run.
The way I handle it is to add a line of placeholders in Webconfig.

<add key="Developer" value="XXXX"/>

Then add in debug.config and release.config

<appSettings>
    <add key="Developer" value="XXXX"/> xdt:Transform="Replace" xdt:Locator="Match(key)"/>
  </appSettings>

Use: xdt:Transform="Replace" xdt:Locator="Match(key)" to replace instead of adding.
After running, different configurations will be automatically made according to the environment.
Regarding the configuration of Transform, please refer to:
About the debug and release.config files of Web.config
Flexible configuration of the configuration file web.config in ASP.NET multiple environments

Supongo que te gusta

Origin blog.csdn.net/qq_42988836/article/details/108218615
Recomendado
Clasificación