C# 为 .NET 程序集设置 CLS 合规性
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/774359/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Setting CLS compliance for a .NET assembly
提问by Peter Mortensen
Setting CLS compliance for an entire .NET assembly is possible. But how is it actually done? E.g. with Visual Studio 2008?
可以为整个 .NET 程序集设置 CLS 合规性。但实际上是怎么做的呢?例如使用 Visual Studio 2008?
采纳答案by pocheptsov
Visual Studio adds a directive for the compiler, and the compiler checks the code for some more strict rules than in the native programming language.
Visual Studio 为编译器添加了一条指令,编译器会检查代码中的一些比本机编程语言中更严格的规则。
You can add the CLS compliant attribute to all your project by adding the assembly level attribute
您可以通过添加程序集级别属性将 CLS 兼容属性添加到您的所有项目
[assembly: CLSCompliant(true)]
anywhere in your project, generally in the assemblyinfo.cs
file.
项目中的任何位置,通常在assemblyinfo.cs
文件中。
If the line using System;
is not at the top of the file, add it. Or, use the long form:
如果该行using System;
不在文件顶部,请添加它。或者,使用长格式:
[assembly: System.CLSCompliant(true)]