What is the GlobalSuppressions.cs/GlobalSuppressions.vb file
FAQ: What is the GlobalSuppressions.cs/GlobalSuppressions.vb file and why is it needed? Is it possible to change the name of this file? [David Kean]I've noticed that Code Analysis sometimes places suppressions in a file called GlobalSuppression.cs (GlobalSuppressions.vb in Visual Basic). Why this is file needed and it is possible to change its name? What is this file? When you right-click on awarning and choose Suppress Message(s),Code Analysis checks to see if the warning was raised against an element thatexists within source. If it does,suchas in the case of a type or a member,then the suppression is applied against the element itself. This is called In-Source Suppression because the suppression is applied in-sourcealongside the targetof the warning. The following sequence shows this:
If the warning was raised against an element that does not live in source,such as namespaces*,assemblies and or any other element without source information (ie compiler generated constructors),then Code Analysis places the suppression,by default,in a file called GlobalSuppression.cs (GlobalSuppression.vb in Visual Basic). This is currently called Module-Level Suppression or Assembly-Level Suppression because the suppression is applied at the assembly-level using the [assembly:] declarator,however,as warnings can be raised and suppressed against both a module and assembly at this level,this is confusing terminologyand in future versions of Visual Studio this name will likely change. *Although technically namespaces do live within source files,they do not have a representation in the Common Intermediate Language (CIL) and therefore you cannot apply attributes against them. The following sequence shows this:
As you can see from above,GlobalSuppression.cs/GlobalSuppression.vb exists to store suppressions against elements without source information. If this file does not exist within the project,then Code Analysis will automatically create it. Note: Starting in Orcas,it will become possible to choose whether to apply a suppression against a element containing source information as anin-source or module-level suppression. How do I change the name of this file? While not very obvious,it is possible to change the name of the Global Suppression file that Code Analysis stores these Module-Level Suppressions in. To change the name,do the following:
If you want all your projects to use the same name,see thefollowing: FAQ: How do I share Managed Code Analysis rule settings over multiple projects? (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |