Difference between Build action content and 'Copy to output directory' in Visual Studio

怎甘沉沦 提交于 2019-11-30 05:36:12
Oded

When setting the Build Action to Content, the file will not be compiled and will be put in the Content output group.

Whether the file gets copies or not depends on the Copy to Output Directory setting at that point.

Of course, if you set Copy Always on a file, it may get compiled and then copied.

See File Properties on MSDN:

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.

The Content build action has visible effect in WPF projects (possibly ASP too).

It adds

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

to WpfApplication1_Content.g.cs. Read about AssemblyAssociatedContentFileAttribute.

In WinForms and console application (what OP may be using) it does not do this, so there's no difference to None action when building.

In this comment, I've found also 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.

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

Copy Always will also trigger a rebuild of that project in a solution even if no code has changed.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!