7

I'm writing a .NET Core 2 console app where i have some files i want to be copied to the output directory. I set the "Copy to output directory" to true and the build action to "Embedded Resource". The file gets copied to the directory like a charm. However, it also does so if i set the build action to "Content".

The official Microsoft docs say:

  • 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.
  • Embedded Resource: The file is passed to the compiler as a resource to be embedded in the assembly. You can call System.Reflection.Assembly.GetManifestResourceStream to read the file from the assembly.

So i thought if I set the build action to "Content", the file will get copied automatically to the output directory without having to set the flag "Copy to output directory" explicitly. But this doesn't seem to be the case.

So what does "Content" actually do, and when do I have to use it instead of "Embedded resource"? An example on when to use "Content" and when to use "Embedded resource" would be great.

Tobias von Falkenhayn
  • 1,355
  • 5
  • 26
  • 59
  • 1
    Possible duplicate of https://stackoverflow.com/questions/22552589/what-is-content-build-action-in-visual-studio –  Apr 15 '19 at 14:49
  • 1
    The docs and the duplicate question are clear. I'd suggest the actual question is `Why is the "Copy To" action separate from "Build Action" and why doens't one change the other ?` When you ask it like this, it's apparent that it would be a bad idea. The automatic change would create a lot of confusion. You probably *don't* want to copy large files during development either, this would increase build times significantly – Panagiotis Kanavos Apr 15 '19 at 15:07
  • Do you ask regarding Content [build action](https://learn.microsoft.com/en-us/visualstudio/ide/build-actions) specifically to .net-core solution? Perfectly legit question as docs are only talking about asp.net. Though duplicate mention *"In console or WinForms applications, it does not do anything"*, so maybe nothing has changed – Sinatr Apr 15 '19 at 15:10
  • @PanagiotisKanavos unfortunately this does not answer my question. However, i found https://stackoverflow.com/questions/12245208/difference-between-build-action-content-and-copy-to-output-directory-in-visual which made it a little more clear, but what is the "Content output group" written in this thread...? – Tobias von Falkenhayn Apr 16 '19 at 11:46
  • 1
    @Sinatr so the only difference is that "Content" does not get compiled, whereas "Embedded resource" will get compiled within the .dll? But why would you compile it AND move it to the output folder? – Tobias von Falkenhayn Apr 16 '19 at 11:47
  • `Content` vs `Embed` is clear, yes, latter is to include it as resource so you can use certain methods to read it from at run-time. I was thinking about `Content` vs `None`, because for .net core application they are probably behaving the same: file is only included into project (for source control and easier navigation), but it doesn't participate in build process at all, you have to deal yourself of how this file will appears at client machine. – Sinatr Apr 16 '19 at 11:53
  • 1
    Possible duplicate of [What is Content Build Action in Visual Studio?](https://stackoverflow.com/questions/22552589/what-is-content-build-action-in-visual-studio) – StayOnTarget Aug 15 '19 at 15:07

0 Answers0