Project development process will encounter problems, development environment configuration is certainly not the same as the production environment,
Always repeat manual copy, but the drawbacks of configuring too many copies are revealed,
There are several scenarios to solve this problem:
1.web.config transformation
Transformation the relevant knowledge points can refer to the following article,
This thing has a bad place, it is only in the publish when the execution, during the development of debugging is not working,
So the general application during the site release
https://msdn.microsoft.com/en-us/library/dd465326 (v=vs.110). aspx
Http://www.cnblogs.com/worksguo/archive/2009/08/29/1556307.html
2.MSBuild application of Xsltransformation in Buildbefore event
Example code: Https://github.com/xlb378917466/MSBuild_BuildBefore
Knowledge Point Learning: http://www.cnblogs.com/shanyou/p/3452938.html
This is a powerful feature that uses the Buildbefore event so that you can get the modified configuration during development debugging.
<target name= "BeforeBuild" >
<xsltransformation condition= "' $ (Configuration) |$ (Platform) ' = = ' debug| AnyCPU ' "xslinputpath=" Debug.xslt "xmlinputpaths=" Webtemplate.config "outputpaths=" Web. config "/>
<xsltransformation condition= "' $ (Configuration) |$ (Platform) ' = = ' release| AnyCPU ' "xslinputpath=" Release.xslt "xmlinputpaths=" Webtemplate.config "outputpaths=" Web. config "/>
</Target>
This defines two XSLT files for outputting the final web. config file, and of course you have to define your own original input file Webtemplate.config,
In this example, the values in the simple appsetting are modified according to the actual configuration.
<appSettings> <add key= "Mode" value= "Release"/> </appSettings>
Debug.xslt
<?xml version= "1.0" encoding= "UTF-8"? ><xsl:stylesheet version= "1.0" xmlns:xsl= "Http://www.w3.org/1999/XSL /transform "><xsl:output indent=" yes "/> <xsl:template match=" @*|node () "> <xsl:copy> <xsl:apply-templates select= "@*|node ()"/> </xsl:copy> </xsl:template><xsl:template match = "/configuration/appsettings/add[@key = ' mode ']" > <add key= "mode" value= "Debug"/></xsl:template>< /xsl:stylesheet>
Release.xslt
<?xml version="1.0"encoding="UTF-8"? ><xsl:stylesheet version="1.0"Xmlns:xsl="Http://www.w3.org/1999/XSL/Transform"><xsl:output indent="Yes"/> <xsl:template match="@*|node ()"> <xsl:copy> <xsl:apply-templatesSelect="@*|node ()"/> </xsl:copy> </xsl:template><xsl:template match="/configuration/appsettings/add[@key = ' Mode ')"> <add key="Mode"Value="Release"/></xsl:template></xsl:stylesheet>
3. Using C # code control through symbols (conditional compilation)
Refer to a previous article: conditional compilation
This is usually done when loading configurations such as other XML, at least for me at this time.
. NET combat generates different config files based on configuration options