如何防止Visual Studio在Web项目中“发布”XML文档文件?

时间:2023-01-14 19:01:52

Note: This question is similar to How to prevent the copy of XML documentation files in a release mode build?, but it's not the same and the answers there don't apply. Read on to find out why. (Please ask in the comments or in chat if you disagree, I'll be glad to elabroate).

注意:此问题类似于如何在发布模式构建中阻止XML文档文件的副本?,但它不相同,并且那里的答案不适用。请继续阅读以找出原因。 (如果您不同意,请在评论或聊天中询问,我很乐意精心制作)。


I have a library project (myLibrary) and an ASP.NET web application project referencing this library (both are in the same solution). "Generate XML documentation file" is checked for the library project, because I want to have those nice IntelliSense features while developing.

我有一个库项目(myLibrary)和一个引用该库的ASP.NET Web应用程序项目(两者都在同一个解决方案中)。检查库项目的“生成XML文档文件”,因为我希望在开发时具有那些不错的IntelliSense功能。

When I publish the web application (Context Menu on the project/Publish...), it copies only the files required for running the application (no source code, etc.) to some publish directory. That's good. Unfortunately, it also copies the XML documentation file of the library. Since I consider our library's documentation to be a trade secret, I wouldn't want it to end up on a customer's server. Thus, we have to remember to manually remove this file from the publish directory before deploying it.

当我发布Web应用程序(项目上的上下文菜单/发布...)时,它只将运行应用程序所需的文件(无源代码等)复制到某个发布目录。那很好。不幸的是,它还复制了库的XML文档文件。由于我认为我们图书馆的文档是商业秘密,我不希望它最终出现在客户的服务器上。因此,我们必须记住在部署之前从发布目录中手动删除此文件。

Is there a way to prevent Visual Studio from copying this file when publishing the ASP.NET project, but still retain the benefit of XML documentation IntelliSense when developing?

有没有办法阻止Visual Studio在发布ASP.NET项目时复制此文件,但在开发时仍然保留XML文档IntelliSense的好处?

5 个解决方案

#1


10  

Assuming you're using distinct configurations for development and release (and whatever else), unchecking 'XML documentation file'/turning off generation for a specific configuration would prevent it being deployed when not needed. Another option would be a post-build action to delete the file/s.

假设您正在使用不同的配置进行开发和发布(以及其他任何内容),取消选中“XML文档文件”/关闭特定配置的生成将阻止在不需要时进行部署。另一种选择是删除文件的构建后操作。

The former of those two options seeming more elegant.

前两种选择看起来更优雅。

#2


4  

Is there a way to prevent Visual Studio from copying this file when publishing the ASP.NET project,

有没有办法阻止Visual Studio在发布ASP.NET项目时复制此文件,

Turn XML docs off in Release mode

在发布模式下关闭XML文档

but still retain the benefit of XML documentation IntelliSense when developing?

但在开发时仍然保留XML文档IntelliSense的好处?

Turn XML docs on / off in Debug mode. Intellisense will work either way.

在调试模式下打开/关闭XML文档。 Intellisense将以任何一种方式工作。

#3


2  

There is another solution. Just include the following in your csproj file somewhere in the beginning:

还有另一种解决方案。只需在开头的某个地方的csproj文件中包含以下内容:

<AllowedReferenceRelatedFileExtensions>.pdb</AllowedReferenceRelatedFileExtensions>

That's it. XML files will no longer be published. Of course, you can make it conditional on the concrete configuration.

而已。将不再发布XML文件。当然,您可以以具体配置为条件。

#4


1  

I'm doing this in Express, but this seemed to work for me...

我在Express中这样做,但这似乎对我有用......

  1. Went to Properties (for the Project)
  2. 去了物业(项目)
  3. Clicked Publish Tab
  4. 单击“发布”选项卡
  5. Click Application Files button
  6. 单击应用程序文件按钮
  7. Checked Show All Files
  8. 选中显示所有文件
  9. Set xml File to Exclude
  10. 将xml文件设置为Exclude

As I said, using Express 2010, but this worked (it didn't copy the file to the Publish location).

正如我所说,使用Express 2010,但这有效(它没有将文件复制到Publish位置)。

#5


0  

You can do this by adding the addon Web deployment project on visual studio which can be downloaded from here: http://www.microsoft.com/download/en/details.aspx?id=19995 and to exclude whatever files/folders you need please follow the steps found here

你可以通过在visual studio上添加addon Web部署项目来实现这个目的,可以从这里下载:http://www.microsoft.com/download/en/details.aspx?id = 199199并排除你的任何文件/文件夹需要请按照此处的步骤操作

#1


10  

Assuming you're using distinct configurations for development and release (and whatever else), unchecking 'XML documentation file'/turning off generation for a specific configuration would prevent it being deployed when not needed. Another option would be a post-build action to delete the file/s.

假设您正在使用不同的配置进行开发和发布(以及其他任何内容),取消选中“XML文档文件”/关闭特定配置的生成将阻止在不需要时进行部署。另一种选择是删除文件的构建后操作。

The former of those two options seeming more elegant.

前两种选择看起来更优雅。

#2


4  

Is there a way to prevent Visual Studio from copying this file when publishing the ASP.NET project,

有没有办法阻止Visual Studio在发布ASP.NET项目时复制此文件,

Turn XML docs off in Release mode

在发布模式下关闭XML文档

but still retain the benefit of XML documentation IntelliSense when developing?

但在开发时仍然保留XML文档IntelliSense的好处?

Turn XML docs on / off in Debug mode. Intellisense will work either way.

在调试模式下打开/关闭XML文档。 Intellisense将以任何一种方式工作。

#3


2  

There is another solution. Just include the following in your csproj file somewhere in the beginning:

还有另一种解决方案。只需在开头的某个地方的csproj文件中包含以下内容:

<AllowedReferenceRelatedFileExtensions>.pdb</AllowedReferenceRelatedFileExtensions>

That's it. XML files will no longer be published. Of course, you can make it conditional on the concrete configuration.

而已。将不再发布XML文件。当然,您可以以具体配置为条件。

#4


1  

I'm doing this in Express, but this seemed to work for me...

我在Express中这样做,但这似乎对我有用......

  1. Went to Properties (for the Project)
  2. 去了物业(项目)
  3. Clicked Publish Tab
  4. 单击“发布”选项卡
  5. Click Application Files button
  6. 单击应用程序文件按钮
  7. Checked Show All Files
  8. 选中显示所有文件
  9. Set xml File to Exclude
  10. 将xml文件设置为Exclude

As I said, using Express 2010, but this worked (it didn't copy the file to the Publish location).

正如我所说,使用Express 2010,但这有效(它没有将文件复制到Publish位置)。

#5


0  

You can do this by adding the addon Web deployment project on visual studio which can be downloaded from here: http://www.microsoft.com/download/en/details.aspx?id=19995 and to exclude whatever files/folders you need please follow the steps found here

你可以通过在visual studio上添加addon Web部署项目来实现这个目的,可以从这里下载:http://www.microsoft.com/download/en/details.aspx?id = 199199并排除你的任何文件/文件夹需要请按照此处的步骤操作