Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between Content and None when "Always copy to output directory" is set?

In csproj file, we can include a file using either None or Content element. From MSDN, it says that:

None - The file is not included in the project output group and is not compiled in the build process. An example is a text file that contains documentation, such as a Readme file.

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 since either None or Content element can contains a CopyToOutputDirectory element, thus I wonder if I set this to be Always, wouldn't the behavior of None and Content be the same?

like image 470
Lifu Huang Avatar asked Jan 20 '17 01:01

Lifu Huang


People also ask

What does Copy to Output Directory mean?

"Copy to Output Directory" is the property of the files within a Visual Studio project, which defines if the file will be copied to the project's built path as it is. Coping the file as it is allows us to use relative path to files within the project.


1 Answers

Not everything which is copied to your output directory, by setting CopyToOutputDirectory, is copied to the Content Output Group. Therefore, you may do this:

File1---CopyToOutputDirectory = Copy always, Content  File2---CopyToOutputDirectory = Copy always, Content  File3---CopyToOutputDirectory = Copy always, None 

All three files will be copied to output directory but only File1 and File2 will be copied to Content Output Group.

Furthermore, Content allows you to retrieve a file (in same directory as the assembly) as a stream via Application.GetContentStream(URI). For this method to work, it needs a AssemblyAssociatedContentFile custom attribute which Visual Studio graciously adds when you mark a file as Content.

None and Content are values for How the file relates to the build and deployment process. Therefore, your build (MS Build for example) and deployment may be very different than simply taking files from the output directory. You may have a .bat file that you do not really need in the output directory but you need it for deployment.

This SO answer has more details about the different build actions.

like image 162
CodingYoshi Avatar answered Sep 18 '22 22:09

CodingYoshi