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

前端 未结 3 1595
时光取名叫无心
时光取名叫无心 2020-12-15 03:28

In my project in Visual Studio, I have files that I want included in the output, but not compiled or embedded.

I am aware that there are 2 ways to accomplish this.

3条回答
  •  北海茫月
    2020-12-15 03:48

    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).

提交回复
热议问题