Automatically switch connectionString when publishing a website

Source: Internet
Author: User
1. Install Web Deploy Projects
2. Right-click the Web Project in VS, Add the Web Deployment Project, and click OK.
3. Set the properties of the newly added project. The Output Path on the "Compilation" page is the directory to be published.
4. On the Deployment page of the project properties, select "Enable Web. config file section replacement", and enter "connectionStrings = connectionStrings. config;", OK
5. Add a connectionStrings. config file to the original Web project, and enter connectionStrings of the release/Production Environment version:

<ConnectionStrings>
<Add/>
</ConnectionStrings>

6. In the Web. config file of the original web project, the connectionStrings section only needs to contain the connection string used during development.
7. Execute the "generate" Operation of the deployment project to find the file and directory structure that can be directly released from the Output Path you have set.

In addition, if some files do not want to be published (such as file1.name and file2.name, dir1.name and dir2.name), you can open the project file of the deployment project and implement the following modifications: <ItemGroup>
<RemoveFileAfterBuild Include = "$ (OutputPath) \ file1.name"/>
<RemoveFileAfterBuild Include = "$ (OutputPath) \ file2.name"/>
<RemoveDirAfterBuild Include = "$ (OutputPath) \ dir1.name"/>
<RemoveDirAfterBuild Include = "$ (OutputPath) \ dir2.name"/>
</ItemGroup>

<Target Name = "AfterBuild">
<RemoveDir Directories = "@ (RemoveDirAfterBuild)"/>
<Delete Files = "@ (RemoveFileAfterBuild)"/>
</Target>

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.