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

Solution 1:

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

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

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:

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:

  • Unload Project,
  • Right click Edit *.csproj,
  • Add this:
<ItemGroup>
<Content Update="Data\CernainFolder\*.*">
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</Content>
</ItemGroup>
  • Reload Project.

This should work nicely