我正在尝试将我们的自定义 FxCop(= 代码分析)规则从 Visual Studio 2010 迁移到 Visual Studio 2012。
到目前为止,它们工作正常,除了一件事:它们的名称在结果窗口 ( View
-> Other windows
-> Code Analysis
) 中是空白的,只有CheckId
和Resolution
显示,而名称显示为 Microsoft 的规则:
奇怪的是,该名称在规则集编辑器中可见:
我的规则有什么问题?
细节
以下是这两个规则在 MSBuild 输出中的显示方式(那里有些可疑,但我不明白为什么我有不同的消息):
6>c:\Users\Me\MySolution\MyProject\Program.cs(15): warning : CA1804 : Microsoft.Performance : 'Foo<T>.SomeMethod()' declares a variable, 'z', of type 'int', which is never used or is only assigned to. Use this variable or remove it.
6>MSBUILD : warning : CF1001 : CustomRules.ThreadSafety : The public Public Field "Tests.Program.Foo" must be preceded of readonly
这是我的规则的 XML 文件中的规则声明:
<?xml version="1.0" encoding="utf-8" ?>
<Rules FriendlyName="CustomRules">
<Rule TypeName="PublicFieldsMustBeReadonly" Category="CustomRules.ThreadSafety" CheckId="CF1001">
<Name>Public Fields must be readonly or must be replaced with a Getter/Setter Method.</Name>
<Description>Public Fields must be readonly or must be replaced with a Getter/Setter Method.</Description>
<GroupOwner>MyCompany</GroupOwner>
<DevOwner>Me</DevOwner>
<Owner>Me</Owner>
<Url>http://example.com</Url>
<Resolution>The public Public Field "{0}" must be preceded of readonly</Resolution>
<Email>my@email.com</Email>
<MessageLevel Certainty="100">Warning</MessageLevel>
<FixCategories>Breaking</FixCategories>
</Rule>
</Rules>
这是 Microsoft 规则的 XML 中的规则声明。
<Rules FriendlyName="Performance Rules">
<Rule TypeName="RemoveUnusedLocals" Category="Microsoft.Performance" CheckId="CA1804">
<Name>
Remove unused locals
</Name>
<Description>
Remove locals that are not used or are only assigned to in method implementations.
</Description>
<Url>
@ms182278(VS.100).aspx
</Url>
<Resolution>
{0} declares a variable, {1}, of type {2}, which is never used or is only assigned to. Use this variable or remove it.
</Resolution>
<Email />
<MessageLevel Certainty="95">
Warning
</MessageLevel>
<FixCategories>
NonBreaking
</FixCategories>
<Owner />
</Rule>
</Rules>