In a .csproj file, what is for?

2020-05-16 13:14发布

How is

<None Include="C:\foo.bar" />

different from

<Content Include="C:\foo.bar" />

?

标签: c# csproj
8条回答
手持菜刀,她持情操
2楼-- · 2020-05-16 14:03

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.

查看更多
Rolldiameter
3楼-- · 2020-05-16 14:03

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.

查看更多
登录 后发表回答