Search code examples
visual-studiovisual-studio-2012buildbuildaction

What is Content Build Action in Visual Studio?


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

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

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?


Solution

  • Updated Visual Studio documentation has more meaningful description:

    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.


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

    It adds

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

    to WpfApplication1_Content.g.cs. Read about the AssemblyAssociatedContentFileAttribute.

    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.

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