Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In a .csproj file, what is <None Include="..."> for?

Tags:

c#

csproj

People also ask

What does none remove mean in Csproj?

So the two statements mean "remove it from the None set (items) and add it to the EmbeddedResource set (items)". Follow this answer to receive notifications.

What does Csproj file contains?

A CSPROJ file is a C# (C Sharp) programming project file created by Microsoft Visual Studio. It contains XML-formatted text that lists a project's included files and compilation options.

What does a project file include?

A project file contains all of the data you have imported, all of the parameters associated with each data file, the content of the journal, and several other collections of important data. All of this gets saved in a single, easily transportable file. The primary purpose of the project file is to save you work.

How do I edit a .csproj file in Visual Studio?

Right-click on the project (tagged as unavailable in solution explorer) and click "Edit yourproj. csproj". This will open up your CSPROJ file for editing. After making the changes you want, save, and close the file.


The MSDN article on the build action property explains the differences.

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.


One difference is how they get published; "None" items don't get included in a publish, "Content" items do; for example, on the "Application Files" dialog on the Publish tab.


I am not 100% sure (I read the MSDN description of Build Action property) but just copying that answer from MSDN to StackOverflow does not answer the question completely for me.

The difference of None and Content only has an effect on Web projects. For a command line project, WinForm project or UnitTest project (in my case) etc. None and Content have no different behavior.

MSDN: "project output group" or "Content output group" only terms used in a Web project, right?


In my situation, my MSBuild file had an ItemGroup for image resources that appeared as follows:

  <ItemGroup>
    <Content Include="Resources\image001.png" />
    <Content Include="Resources\image002.png" />
    <Content Include="Resources\image003.png" />
    <Content Include="Resources\image004.png" />
    <None Include="Resources\image005.png" />
    <None Include="Resources\image006.png" />
    <None Include="Resources\image007.png" />
  </ItemGroup>

While my project was building fine, this left me wondering why I had a mix of Content and None item type elements in my ItemGroup. This MSDN article (for Visual Studio 2010) gave me the guidance I was looking for:

Note that when the resource editor adds an image, it sets Build Action to None, because the .resx file references the image file. At build time, the image is pulled into the .resources file created out of the .resx file. The image can then easily be accessed by way of the strongly-typed class auto-generated for the .resx file. Therefore, you should not change this setting to Embedded Resource, because doing this would include the image two times in the assembly.

Resolution: With this guidance, using a text editor, I changed the Content item type elements to None.

Also, for an overview of MSBuild items, see this MSDN article.


I have a project that contains no compilable items (it stores html and javascript for jasmine unit tests).

One day my solution (that contained said project) stopped compiling saying "The target "Build" does not exist in the project".

I added an import to bring in the compiler, which worked fine on my machine but failed using msbuild on the build server.

<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

I then changed a line from

<None Include="SpecRunner.html" />

to

<Content Include="SpecRunner.html" />

and it worked on the build server as well.


Content files are not included in a build, but are included in a publish.

None files are not included in a build or publish, unless they are configured that way by you. For instance, a "Copy to Output Directory" setting of "Always" or "Newer", will cause them to be included in both a build and publish.