19

I'm publishing a Web Application from Visual Studio 2013. I need include folders that are not a part of the project, and exclude some folders (some apart of the project, some not apart of the project). So I went into my project's properties and set Items To Deploy field to All files in this project folder as you can see below:

enter image description here

Then I began looking for a way to exclude folders from All files in this project folder. I found this page, which specifically states

The Visual Studio UI does not expose all of the deployment settings that you can configure. For example, you can't use the UI to exclude an individual folder from deployment. However, you can do this by editing the files that store configuration settings. For each publish profile there is a .pubxml file that you can edit directly.

This page links to another that explains how to edit the file, but doesn't explain how to exclude specific folders.

I found other sites (this one included) that explained how to exclude folders in older versions of Visual Studio using the following tag in the csproj file:

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> 
  ... 
  <ExcludeFilesFromDeployment>File1.aspx;File2.aspx</ExcludeFilesFromDeployment> 
  <ExcludeFoldersFromDeployment>Folder1;Folder2</ExcludeFoldersFromDeployment> 
</PropertyGroup>

But it appears the XML elements for the csproj file are no longer relevant in VS2013. I read somewhere (can't remember where now) a suggestion that this element had been moved to the [PublishProfileName].pubxml file, but trying this failed to work.

I'm sure that there is a way to do this in Visual Studio 2013, but for the life of me, I can't figure out how. I've found dozen of related question here on Stackoverflow, as well as other forums, but none of the solutions work for me in VS2013. Any help is much appreciated.

Trevor
  • 13,085
  • 13
  • 76
  • 99

3 Answers3

30

These elements have indeed been moved to the .pubxml file in Visual Studio 2012 and later. Here's the relevant documentation in MSDN about excluding files and folders from deployment.

Locate the relevant .pubxml file under Properties / Publish Profiles in the Visual Studio Solution Explorer, and add a new element ExcludeFilesFromDeployment or ExcludeFoldersFromDeployment under the PropertyGroup element listing the files or folders to be excluded, delimited by a semi-colon.

I note these elements didn't appear as options in the IntelliSense selection when I typed them into Visual Studio 2015 - but the project compiled and the exclusion still worked.

James Skemp
  • 8,018
  • 9
  • 64
  • 107
John Trenwith
  • 753
  • 6
  • 10
  • 1
    I noticed in VS 2015 it seems IntelliSense doesn't like the `` tag in the .pubxml file. It works properly, it just does the blue squiggle line saying it's invalid. – nickvans Feb 08 '17 at 16:49
  • 1
    In VS 2019, I'm having the opposite experience. No IntelliSense errors, but files are not excluded from the deployment :( – Doug Sep 24 '20 at 15:42
  • 1
    For publishing with VS 2019, it looks like things have changed. See: https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/visual-studio-publish-profiles?view=aspnetcore-3.1#selective-file-inclusion – Randy Burden Mar 12 '21 at 20:56
  • 1
    The above is directed at ASP.NET Core development, so it may not apply to publishing ASP.NET projects. – techSage Jun 17 '21 at 21:15
  • 1
    This answer still works in VS 2019 for ASP.NET (not Core) projects. – Mike Grove aka Theophilus Mar 24 '22 at 14:54
1
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
   .
   .
   .
  </PropertyGroup>
  <ItemGroup>
    <Content Update="appsettings.Development.json">
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
      <CopyToOutputDirectory>Never</CopyToOutputDirectory>
    </Content>
    <Content Update="appsettings.TestBed.json">
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
      <CopyToOutputDirectory>Never</CopyToOutputDirectory>
    </Content>
    <Content Update="wwwroot\files\**\*" CopyToPublishDirectory="Never" />
    <Content Update="wwwroot\originals\**\*" CopyToPublishDirectory="Never" />
  </ItemGroup>
</Project>
Mehmet Erdoğdu
  • 190
  • 2
  • 8
-4

In your cpproj project file, you add those folder and files that are not to be included in the publishing process like this:

<Content Include="Documentation\**" CopyToPublishDirectory="Never" />
Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
Mohammad S.
  • 429
  • 1
  • 6
  • 26