Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to mark .NET Standard code as CLS-compliant?

The title says it all - how do I flag a .NET standard library as CLS-compliant?

I wrote a simple library in C# targeting .NET Standard 1.0 framework. It includes two enums:

public enum Alignments { Left, Center, Right }
public enum Actions { None, Total, Average, Count }

When I try to use the library in a .NET 4.6 project it flags the enums as non-CLS-compliant:

Warning CS3001 Argument type 'Actions' is not CLS-compliant

I cannot add anything to AssemblyInfo.cs since this is not used by .NET standard. It does not seem to be supported as a property in the .csproj file either.

like image 362
Quango Avatar asked Feb 28 '18 09:02

Quango


People also ask

What is a CLS code?

NET Framework. CLS is a part of the specifications of the . NET Framework. CLS was designed to support language constructs commonly used by developers and to produce verifiable code, which allows all CLS-compliant languages to ensure the type safety of code.

What is Clscompliant attribute?

The CLSCompliantAttribute attribute is used to indicate whether a particular program element complies with the Common Language Specification (CLS), which defines the features that any language that targets . NET must support.


1 Answers

There isn't an AssemblyInfo.cs file, but assembly attributes can be added to any file in a .NET Standard project.

So adding this to a C# file in the project will make the assembly CLS-compliant:

using System; [assembly: CLSCompliant(true)]

Reference: NetStandard v1.0 docs

For convention I'll create an AssemblyInfo.cs file and place it there anyway.

like image 105
Quango Avatar answered Oct 02 '22 18:10

Quango