How to exclude specified files and web Service projects when a web site and windows Service Project are released

Source: Internet
Author: User

How to exclude specified files and web Service projects when a web site and windows Service Project are released

When publishing the asp.net site and windows service projects, you may need to exclude the specified files when the msbuild is compiled and published to the specified directory on the server. For example, during jenkins build, do not want to overwrite the original Web. config and App. config, so how to exclude it?

Web Site Project

For example, if you do not want to publish the Web. config file, you can use the following three methods.

1. Change the item Content to None.

Before modification:

1 <Content Include="Web.config" />

 

After modification:

1 <None Include="Web.config" />

2. Use the Exclude attribute of the item

The following code:

1 <Content Include="Web.config" Exclude="Web.config" />

 

Note:

Although this method can be excluded during release, it is also excluded from the project, which is inconvenient for local development and debugging.

 

3. Use Target and ExcludeFromPackageFiles

Add a new Target node with the following code:

1 <! -- Exclude Web by ExcludeFromPackageFiles. config --> 2 <Target Name = "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, which can be used for release exclusion, and ensure that files exist in the project without affecting local development and debugging.

In addition:

Because msbuild is based on the. csproj project file, the above operations are to modify the. csproj file. The modification method is as follows:

1. Uninstall the project

For example:

 

2. Edit the csproj File

For example:

 

Windows Service Project

In windows service projects, App. config is of the None type, and the method of using Target and ExcludeFromPackageFiles is not applicable. Therefore, the Exclude attribute 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" />
References

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

 

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: 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.