How to exclude folders from publish/deployment of Visual Studio 2013 Web Application
Asked Answered
M

4

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.

Monoacid answered 14/9, 2015 at 16:58 Comment(1)
Here is the solution for VS 2019: https://mcmap.net/q/213075/-asp-net-core-exclude-or-include-files-on-publishBrynhild
D
31

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.

Dysphoria answered 29/12, 2015 at 17:45 Comment(5)
I noticed in VS 2015 it seems IntelliSense doesn't like the <ExcludeFilesFromDeployment> tag in the .pubxml file. It works properly, it just does the blue squiggle line saying it's invalid.Automobile
In VS 2019, I'm having the opposite experience. No IntelliSense errors, but files are not excluded from the deployment :(Ranie
For publishing with VS 2019, it looks like things have changed. See: learn.microsoft.com/en-us/aspnet/core/host-and-deploy/…Brynhild
The above is directed at ASP.NET Core development, so it may not apply to publishing ASP.NET projects.Laine
This answer still works in VS 2019 for ASP.NET (not Core) projects.Mather
S
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>
Sinuate answered 6/9, 2022 at 4:23 Comment(1)
Test it works on VS 2019 and 2022, it's best solution.Bud
A
0

publish profile sample for , Exclude file Exclude folder

 <ItemGroup>
    <Content Update="appsettings.json" CopyToPublishDirectory="Never" />
    <Content Update="wwwroot\**" CopyToPublishDirectory="Never" />
  </ItemGroup>
Allocate answered 27/3, 2024 at 10:8 Comment(0)
V
-3

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" />
Vasculum answered 25/1, 2018 at 0:10 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.