Parameterization of Web. config content when ASP. NET is published

Source: Internet
Author: User

Microsoft's msdeploy provides the Web. config transform method, which provides the Web. config transformation capability during release to cope with deployment in different modes. When you create an ASP. NET project in vs2010, the debug and release web. config versions are provided by default. For details, refer to msdn.

In other scenarios, you also need to change the Web. config content during deployment, but you need to specify the parameters to be changed through external (such as the installation program. This requires the parameterization of Web. config. This part does not seem to be detailed on msdn (or I did not find it ).

Some related instructions are found here (please bring your own wall flip tool ).


Step 1: Create parameters. xml and set the parameters you want to change during deployment.

I didn't find the corresponding schema, and it was a little troublesome to write it by hand. I didn't need much parameterized content this time. First, give a reference (from the above blog)

Code <? XML version = "1.0" encoding = "UTF-8"?>

<Parameter name = "log folder location" Description = "Please provide a shared location where the app can write log files to" defaultvalue = "\ logs \ mvcapp \ logs \" tags = "">
<Parameterentry kind = "xmlfile" Scope = "\ WEB. CONFIG $" match = "/configuration/appsettings/Add [@ key = 'logfolder']/@ value"/>

<Parameter name = "WCF service1 endpoint address" Description = "Please provide the endpoint address for service1 that this MVC app needs to call" defaultvalue = "http: // localhost: 61938/service1.svc "tags =" ">
<Parameterentry kind = "xmlfile" Scope = "\ WEB. CONFIG $" match = "// system. servicemodel/client/Endpoint/@ address"/>



Describe the attributes of parameter (from the preceding blog)

Name-must be an attribute and cannot be repeated.

Description-When IIS manager is used for deployment, it will appear in the UI

Defaultvalue-not required

Scope-use a regular expression to indicate the location of the Parameter

Kind-there are many types, but you only need to remember two types

Xmlfile-use XPath to transform web. config or other XML files

Textfile-you can search for and replace non-XML files. For example, you can define @ replacementme @ to replace

Match-depends on kind. If kind = xmlfile, match is defined as an XPath. If it is textfile, match is the phrase you predefine In the transformed file, for example, @ replacementme @@

Step 2: Package

Step 3: Use IIS manager or command line deployment, which is not discussed in this article.

[Update] Here is a more detailed document

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.