English 中文(简体)
利用密码档案检索海关编码分析规则图书馆
原标题:Referencing a custom code analysis rule library using a ruleset file
问题回答

In your .ruleset file, you should be able to add relative paths to the custom rule DLLs. e.g.:

<?xml version="1.0" encoding="utf-8"?>
<RuleSet Name="Sample" Description="Sample ruleset" ToolsVersion="10.0">
  <RuleHintPaths>
    <Path>..ToolsFxCopSomeRules.dll</Path>
    <Path>..ToolsFxCopSomeOtherRules.dll</Path>
  </RuleHintPaths>
  ...
</RuleSet>

I found even the correct project-relative relative path (provided as Nicole s answer) to my custom rules assembly did not cause my rules to appear in the ruleset editor, while an absolute path to the same assembly did make the rules show up. When I enabled the rules and then changed the path back to a relative path, the rules remain in the editor and are run during source analysis. If I uncheck the rules with a relative path specified, the rules disappear - this seems like a bug in the rules editor.

So, if your rules do not seem to appear when specifying a relative path, try using an absolute one, enabling the rules, and then switching back to a relative path (relative to the project location per @Raithlin).

这个问题似乎也影响到2013年《联邦调查》。 我发现,人工进入相对规则组()。 当我使用演播室规则设计师时,该大会的规则将产生这些规则。 规则也将得到遵守。

So an operational CustomRules.ruleset could look like this, where SR1000 is a rule from SomeRules.dll and SOR1000 is from SomeOtherRules.dll. Note that the tools version is 12.0 for Visual Studio 2013.

<?xml version="1.0" encoding="utf-8"?>
<RuleSet Name="Sample" Description="Sample ruleset" ToolsVersion="12.0">
  <RuleHintPaths>
    <Path>..ToolsFxCopSomeRules.dll</Path>
    <Path>..ToolsFxCopSomeOtherRules.dll</Path>
  </RuleHintPaths>
  <Rules AnalyzerId="Microsoft.Analyzers.ManagedCodeAnalysis" RuleNamespace="Microsoft.Rules.Managed">
    <Rule Id="SR1000" Action="Error" />
    <Rule Id="SOR1000" Action="Warning" />
    <!-- etc. -->
  </Rules>
</RuleSet>

Note that you can easily include standard Microsoft rules by adding includes like this to RuleSet:

<Include Path="minimumrecommendedrules.ruleset" Action="Default" />

I am using Visual Studio C# 2015 with Update 2. My custom rules do not show up in the ruleset editor of Visual Studio 2015. However when i run the CodeAnalysis, violations appear if there are any. My RuleHintPath looks like this and is relative to the location of the ruleset file:

<RuleHintPaths>
  <Path>..Rules</Path>
</RuleHintPaths>

因此,由于发现了这些侵权行为,事实上,DLLs规则是按既定的相对路线确定的。 为什么规则没有在规则编辑中显示,这是问题。 因此,我假定编辑的 b。





相关问题
Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How do I compare two decimals to 10 decimal places?

I m using decimal type (.net), and I want to see if two numbers are equal. But I only want to be accurate to 10 decimal places. For example take these three numbers. I want them all to be equal. 0....

Exception practices when creating a SynchronizationContext?

I m creating an STA version of the SynchronizationContext for use in Windows Workflow 4.0. I m wondering what to do about exceptions when Post-ing callbacks. The SynchronizationContext can be used ...

Show running instance in single instance application

I am building an application with C#. I managed to turn this into a single instance application by checking if the same process is already running. Process[] pname = Process.GetProcessesByName("...

How to combine DataTrigger and EventTrigger?

NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...