如何从 Visual Studio 2013 Web 应用程序的发布/部署中排除文件夹

如何从 Visual Studio 2013 Web 应用程序的发布/部署中排除文件夹

问题描述:

我正在从 Visual Studio 2013 发布 Web 应用程序.我需要包含不属于项目的文件夹,并排除某些文件夹(有些属于项目,有些不属于项目).所以我进入了我的项目的属性并将 Items To Deploy 字段设置为 All files in this project folder,如下所示:

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:

然后我开始寻找一种从此项目文件夹中的所有文件中排除文件夹的方法.我找到了 this 页面,其中特别指出

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

Visual Studio UI 不会公开所有部署设置您可以配置.例如,您不能使用 UI 排除部署中的单个文件夹.但是,您可以通过编辑存储配置设置的文件.对于每次发布profile 有一个 .pubxml 文件,您可以直接编辑.

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.

我发现了其他网站(这个 包括),解释了如何使用 csproj 文件中的以下标记排除旧版 Visual Studio 中的文件夹:>

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>

但似乎 csproj 文件的 XML 元素在 VS2013 中不再相关.我在某处(现在不记得在哪里)读到一个建议,该元素已移至 [PublishProfileName].pubxml 文件,但尝试此操作失败.

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.

我确信在 Visual Studio 2013 中有一种方法可以做到这一点,但对于我的生活,我不知道如何做.我在 * 以及其他论坛上发现了许多相关问题,但在 VS2013 中没有一个解决方案对我有用.非常感谢任何帮助.

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 *, as well as other forums, but none of the solutions work for me in VS2013. Any help is much appreciated.

这些元素确实已移至 Visual Studio 2012 及更高版本的 .pubxml 文件中.这是 MSDN 中的相关文档关于从部署中排除文件和文件夹.

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.

在 Visual Studio 解决方案资源管理器中的 Properties/Publish Profiles 下找到相关的 .pubxml 文件,并在 PropertyGroupExcludeFilesFromDeploymentExcludeFoldersFromDeployment/code> 元素列出要排除的文件或文件夹,用分号分隔.

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.

我注意到,当我将这些元素输入到 Visual Studio 2015 中时,这些元素并未作为选项出现在 IntelliSense 选择中 - 但项目已编译并且排除仍然有效.

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.