加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 设置“始终复制到输出目录”时,Content和None之间有什么区

发布时间:2020-12-15 07:42:52 所属栏目:百科 来源:网络整理
导读:在csproj文件中,我们可以使用None或Content元素包含一个文件.从MSDN,它说: None – The file is not included in the project output group and is not compiled in the build process. An example is a text file that contains documentation,such as a R
在csproj文件中,我们可以使用None或Content元素包含一个文件.从MSDN,它说:

None – The file is not included in the project output group and is not
compiled in the build process. An example is a text file that contains
documentation,such as a Readme file.

Content – The file is not compiled,but is included in the Content
output group. For example,this setting is the default value for an
.htm or other kind of Web file.

但是由于None或Content元素都可以包含CopyToOutputDirectory元素,因此我想知道我是否将它设置为Always,不会将None和Content的行为相同吗?

解决方法

并非通过设置CopyToOutputDirectory复制到输出目录的所有内容都将复制到内容输出组.因此,您可以这样做:
File1---CopyToOutputDirectory = Copy always,Content 
File2---CopyToOutputDirectory = Copy always,Content 
File3---CopyToOutputDirectory = Copy always,None

所有三个文件都将复制到输出目录,但只有File1和File2将被复制到内容输出组.

此外,Content允许您通过Application.GetContentStream(URI)检索文件(与程序集在同一目录中)作为流.要使此方法起作用,它需要一个AssemblyAssociatedContentFile自定义属性,当您将文件标记为内容时,Visual Studio会慷慨地添加该属性.

None和Content是文件如何与构建和部署过程相关的值.因此,您的构建(例如,MS Build)和部署可能与仅从输出目录中获取文件非常不同.您可能在输出目录中有一个您不需要的.bat文件,但是您需要它来进行部署.

This SO答案提供了有关不同构建操作的更多详细信息.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读