1

I get a compiler warning on my ASP.Net Core (2.1) project:

warning CA1014: Mark assemblies with CLSCompliant

This warning is given by the CodeAnalysis analyzer (I use version 1.1.0-beta008).

I have already added an "AssemblyInfo.cs" file to that same project containing this single line of code:

[assembly: System.CLSCompliant(false)]

However, I see that there are TWO dlls generated for this project: the expected {projectname}.dll but also {projectname}.Views.dll.

Using ILSpy I can confirm that the attribute is applied to the {projectname}.dll, but it is not applied to the {projectname}.Views.dll - which undoubtedly causes this warning.

Adding that same AssemblyInfo.cs to the Views folder causes an error: CS0579 Duplicate 'System.CLSCompliant' attribute. So apparently that Views dll does not contain "everything in the Views folder" but only the compiled cshtml files.

Adding that attribute to (for instance) the _ViewStart.cshtml does not lead to a legal syntax.

So how can I apply this attribute specifically to the views?

Note that I can remove the warning by lowering the severity of the CA1014 rule (Dependencies > Analyzers > Microsoft.CodeQuality.Analyzers), but I would rather "solve" this than "hide" it.

Hans Kesting
  • 38,117
  • 9
  • 79
  • 111
  • This question seems to be dealing similar issues: https://stackoverflow.com/questions/42138418/equivalent-to-assemblyinfo-in-dotnet-core-csproj/42183749#42183749 – mortb Jun 28 '18 at 11:48
  • @mortb It is *related* but not a duplicate: that question is about *having* an AssemblyInfo file (which I already have), and not for this particular attribute specifically for the Views dll. – Hans Kesting Jun 28 '18 at 11:50
  • I realize that. I can understand that you want to be thorough here and fix the style cop errors, that is a *good thing*. However, I could argue that it might not feel entirely natural to alter this attribute on an assembly that you have not generated yourself; can you guarantee that the code is CLSCompliant? Maybe it is more of an issue for the aspnet core team: https://github.com/aspnet/Home/issues? – mortb Jun 29 '18 at 10:08
  • @mortb The CA issue is that "a" CLSCompliant attribute must be present, not that is must specifically be set to "true". "false" is also an accepted value. And you are right, in the case of 3rd party assemblies, you need to take their word, you cannot force it. But in this case, the dll is generated from *my* views - so maybe I should file an issue there. – Hans Kesting Jun 29 '18 at 10:33
  • Issue filed as https://github.com/aspnet/Mvc/issues/8074 – Hans Kesting Jul 13 '18 at 07:38

1 Answers1

1

As answered to the github issue, add the following fragment to the project file (.csproj):

<ItemGroup>
  <RazorCompile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>

to include the referenced file in the Views assembly. You could reference any file, of course make sure the path is correct (relative from the project root).

See documentation.

Hans Kesting
  • 38,117
  • 9
  • 79
  • 111