MS Visual Studio: How to exclude certain Project Folders from publishing?

C#asp.net.NetVisual StudioPublish

C# Problem Overview


I have certain folders which I want to keep in the project but not to include it in publishing.

Is that possible?

C# Solutions


Solution 1 - C#

Michael is totally right, through editing the .csproj file you can manually exclude files/folder from being published.

One easier way if you don't want to mess with the .csproj file is to highlight the file(s) inside the VS solution explorer. Under the properties panel, change build to action from 'content' to 'none'.

This way you don't have to unload the project from the solution, load the .csproj and add a line for each new file you add that doesn't need to be published but instead achieve the same with 3 mouse-clicks.

(assuming you've set the 'Only publish files needed to run this application' under the publishing tab)

Solution 2 - C#

If it is a web-site project, you may exclude certain folders and/or files as follows (see elements ExcludeFoldersFromDeployment and ExcludeFilesFromDeployment):

<?xml version="1.0" encoding="utf-8"?>
<!--
This file is used by the publish/package process of your Web project. You can customize the behavior of this process
by editing this MSBuild file. In order to learn more about this please visit http://go.microsoft.com/fwlink/?LinkID=208121. 
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
	<PropertyGroup>
		<WebPublishMethod>FileSystem</WebPublishMethod>
		<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
		<LastUsedPlatform>Any CPU</LastUsedPlatform>
		<SiteUrlToLaunchAfterPublish />
		<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
		<ExcludeApp_Data>True</ExcludeApp_Data>
		<publishUrl>D:\YAZILIM\Adopen.2015\PreCompiledWeb</publishUrl>
		<DeleteExistingFiles>True</DeleteExistingFiles>
		<PrecompileBeforePublish>True</PrecompileBeforePublish>
		<EnableUpdateable>True</EnableUpdateable>
		<DebugSymbols>False</DebugSymbols>
		<WDPMergeOption>MergeAllOutputsToASingleAssembly</WDPMergeOption>
		<UseMerge>True</UseMerge>
		<SingleAssemblyName>AdoIntranet</SingleAssemblyName>
		<ExcludeFoldersFromDeployment>customobjects;uploads</ExcludeFoldersFromDeployment> 
		<ExcludeFilesFromDeployment>app.config</ExcludeFilesFromDeployment>
	</PropertyGroup>
</Project>

Solution 3 - C#

You can do a 'Find & Replace' in the Web.cspoj file to quickly eliminate a particular folder from the publish/deployment process

Like so;

<Content Include="Uploads/

to

<None Include="Uploads/

Solution 4 - C#

Another way you can do is you can hide folders in windows explorer that are not needed to be get published(not the best solution but works if you have large set of images that still need to be in development box).

Solution 5 - C#

  • Unload Project,
  • Right click Edit *.csproj,
  • Add this:

> > > Never > >

  • Reload Project.

This should work nicely

Solution 6 - C#

As the question is tagged with ASP, there is no .proj file to mess with. With VS2015, there is another useful file instead: website.publishproj. And this Asp.Net article on excluding files and folders mentions the .wpp.targets file.

All of these files contain <ItemGroup> elements, that may have elements like <ExcludeFromPackageFolders>. As these seem documented features, just use them and don't feel guilty for hacking or 'messing'. For me, excluding a directory using the simple instructions of that link and the website.publishproj file worked like a charm!

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionmeetpdView Question on Stackoverflow
Solution 1 - C#jbokkersView Answer on Stackoverflow
Solution 2 - C#HGMamaciView Answer on Stackoverflow
Solution 3 - C#Stacker-flowView Answer on Stackoverflow
Solution 4 - C#DSharperView Answer on Stackoverflow
Solution 5 - C#ZilpioView Answer on Stackoverflow
Solution 6 - C#RolandView Answer on Stackoverflow