How to exclude specified files when Web sites and Windows service projects are published

Source: Internet
Author: User

When publishing an ASP. NET site and Windows Service project, there are times when you need to exclude specified files when you publish to a server-specified directory after MSBuild compiles, such as when you build with Jenkins and don't want to overwrite the original web. config and App. Config.

Web site project

For example, you do not want to publish the Web. config file in the following three ways.

1, change the item content to none

Before modification:

1 <content include="Web. config" />

After modification:

1 <none include="Web. config" />

2, using the Exclude property of the item

The following code:

1 <content include="Web. config " exclude="Web. config" />

Attention:

Although this can be achieved by the release of the exclusion, but also excluded from the project, for local development debugging inconvenient.

3, using Target and Excludefrompackagefiles

Add a new target node with the following code:

1 <!--exclude web.config-->2 <target name=" by Excludefrompackagefiles Customexcludefiles "beforetargets="excludefilesfrompackage">3 <ItemGroup>4   <excludefrompackagefiles include="web.config "></ExcludeFromPackageFiles>5 </ItemGroup>6 </Target>
View Code

Summary: The best practice is to use Method 3, both to achieve the release of the exclusion, but also to ensure that the file exists in the project, does not affect the local development and debugging.

Other than that:

Because MSBuild is based on the. csproj project file, the above actions are to modify the. csproj file and modify the method as follows:

1, uninstalling the project

Such as:

2, edit csproj file

Such as:

Windows Service Project

Because app. config is the none type in the Windows Service project, and the use of target and excludefrompackagefiles is not applicable, the Exclude property of the item is used for the time being.

Before modification:

1 <none include="app. config" />

After modification:

1 <none include="app. config" exclude="app. config" />
Resources

1,https://stackoverflow.com/questions/6358635/exclude-files-from-web-site-deployment-with-msbuild

2,msbuild Reference: Https://docs.microsoft.com/zh-cn/visualstudio/msbuild/msbuild

How to exclude specified files when Web sites and Windows service projects are published

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.