What is the difference between Content and No when installing "Always copy to output directory"?

In the csproj file, we can include the file using the None or Content element. From MSDN it is said that:

Not. The file is not included in the project output group and is not compiled during the build process. An example would be a text file containing documentation, such as a Readme file.

Content. The file is not compiled, but is included in the output content. For example, this parameter is the default value for .htm or another type of web file.

But since the None or Content element may contain the CopyToOutputDirectory element, so I wonder if this is set to Always , will the None and Content behavior be the same?

+6
source share
1 answer

Not everything copied to your output directory, setting CopyToOutputDirectory , is copied to the content output group. So you can do this:

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

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

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

None and Content are values ​​for how the file relates to the build and deployment process. Thus, your build (for example, MS Build) and deployment may be different from simply deleting files from the output directory. You may have a .bat file that you really don't need in the output directory, but you need it to deploy.

This SO answer provides more details on the various build actions.

+4
source

Source: https://habr.com/ru/post/1014242/


All Articles