什么是 Visual Studio 中的内容构建操作? [英] What is Content Build Action in Visual Studio?

查看:20
本文介绍了什么是 Visual Studio 中的内容构建操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Visual Studio 中的 Content 构建操作有什么作用?它看起来没有做任何事情.

What does the Content Build Action in Visual Studio do? It does not look like it's doing anything.

MSDN 上的文件属性文章(不再存在) 说:

The File Properties article on MSDN (does not exist anymore) says:

内容 - 文件未编译,但包含在内容输出组中.例如,此设置是 .htm 或其他类型的 Web 文件的默认值.

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.

但我不知道内容输出组"是什么意思.

But I have no idea what the "Content output group" means.

这与部署有关吗?意思是,这个动作在构建时没有实际效果,但只有在部署时才有效果?

Is this something about deployment? Meaning, the action has no actual effect, when building, but only later when deploying?

推荐答案

更新的 Visual Studio 文档有更有意义的描述:

Content - 标记为 Content 的文件可以通过调用 Application.GetContentStream.对于 ASP.NET 项目,这些文件在部署时作为站点的一部分包含在内.

Content - A file marked as Content can be retrieved as a stream by calling Application.GetContentStream. For ASP.NET projects, these files are included as part of the site when it's deployed.

<小时>

同样经过一些测试并从 什么是各种构建操作"的提示?Visual Studio 项目属性中的设置以及它们的作用是什么?,我发现 Content 构建操作在 WPF 项目(也可能是 ASP)中具有这种效果.


Also after some testing and with a hint from What are the various "Build action" settings in Visual Studio project properties and what do they do?, I've found that the Content build action has this effect in WPF projects (possibly ASP too).

它增加了

[assembly: System.Windows.Resources.AssemblyAssociatedContentFileAttribute("filename")]

WpfApplication1_Content.g.cs.阅读AssemblyAssociatedContentFileAttribute.

在控制台或 WinForms 应用程序中,它不执行任何操作(无论是源代码还是输出二进制文件).

In console or WinForms applications, it does not do anything (neither in source code nor output binary).

虽然在评论中,对于前面提到的问题,有关于对部署的影响的说明:

Though in the comment, to previously mentioned question, there's a note about effect on deployment:

另请注意,使用一键部署时将包含内容,但即使选择了如果更新则复制",也不会包含内容.

Also note that Content will be included when using one-click deploy, but None won't even if "copy if newer" is selected.

这可能甚至适用于控制台和 WinForms 应用程序(我还没有尝试过).

Possibly this works even for console and WinForms applications (I haven't tried).

这篇关于什么是 Visual Studio 中的内容构建操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆