Use vs compilation events to dynamically publish configuration files

Source: Internet
Author: User

We know that there are many development environments. Generally, we are divided into development environments, test environments, and production environments. we use two default vs configurations: Debug and release. of course, vs supports adding, editing, and deleting configurations through the Configuration Manager.

For this reason, our applications in different environments and configurations will copy and paste various configuration files, such as database connection strings, at the time of release, which are prone to errors and increase the effort to maintain them.

The vs compilation event is used to automate the configuration file. In short, the configuration file of the development environment is used when I publish or compile the configuration file. if it is a production environment, use the configuration file of the production environment.

The following describes several macro descriptions of compilation events:

1: $ (projectdir) represents the root directory of the current application;

2: $ (targetdir) indicates the bin directory of the current application;

3: $ (configurationname) indicates the current configuration name (such as debug );

Let's first set up an Application Scenario: assume that we have two environments: Debug (Development Environment) and release (production environment)

If the directory structure of an application is as follows:

--- Root

-- Config

--- Debug. config. Publish

--- Release. config. Publish

--- Setting. config

---- A. aspx

---- B. aspx

---- Web. config

The Web. config file contains the following configuration files: <etettings file = "config \ setting. config"> </appsettings>;

Debug. config. Publish is the database connection string configuration in the development environment;

Release. config. Publish is the database connection string in the production environment;

If we want to compile or release an application to the production environment, that is, release, our goal is to compile or release the application. config. the configuration file in publish is automatically copied to setting. config.

What should we do? The procedure is as follows:

1: "$ (projectdir) copyconfigcontent. Bat" "$ (projectdir) config \ $ (configurationname). config. Publish" "$ (projectdir) config \ setting. config" Configure this code to properties --- generate event ---- pre-generate event command line. 2: Download copyconfigcontent. BAT and put the batch to the application directory.

 

Use vs compilation events to dynamically publish configuration files

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: info-contact@alibabacloud.com 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.