我試圖將我們的自定義FxCop(=代碼分析)規則從Visual Studio 2010遷移到Visual Studio 2012.FxCop自定義規則沒有在VS2012中的名稱(但「官方」規則有一個名稱)
:到目前爲止,他們的工作除了一件事罰款:雖然顯示了微軟的規則的名稱(>Code Analysis
View
- - >Other windows
),只有CheckId
和Resolution
顯示,他們的名字是在結果窗口空白
什麼是斯特蘭GE,是名字是在規則集編輯器可見:
什麼是錯我的規則?
詳細
下面是這兩個規則如何在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>[email protected]</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>
在我的情況,我用了'.ruleset'文件的'RuleHintPaths'標籤給的路徑,我的DLL,但正如你所說VS的插件似乎忽略它。謝謝你的回答,即使它不是我想看的:)。 –
將文件複製到' \ Team Tools \靜態分析工具\ FxCop \規則「,但它不是最佳的,因爲我們經常添加或調整規則。註冊表項在我的系統中不存在,所以我嘗試創建它,但它似乎不工作。我有一個Windows 7 64位系統,鑰匙可以放在別的地方嗎?謝謝! –
您是否在添加註冊表項後重新啓動Visual Studio?另外,您是否嘗試在預先存在的HKEY_CURRENT_USER \ Software \ Microsoft \ VisualStudio \ 11.0 \ CodeAnalysis'下添加FxCopRulePath值,或者是否創建了一個新的「Code Analysis」鍵,並在單詞之間留有空格? (後者是必要的。) –