如何在多个项目中分享code Analysis 规则设置

 使用Visual Studio,创建一个新的空项目

  1. In Solution Explorer , right-click the project and choose Properties解决方案资源管理器 ,右键单击该项目,然后选择属性
  2. In the Project Properties window, choose the Code Analysis tab项目属性窗口中,选择选项卡代码分析
  3. In the Code Analysis tab, choose the rules you want for your minbar代码分析选项卡,选择适合你开放团队的规则
  4. In Solution Explorer , right-click the project and choose Unload Project , answering Yes to any prompt to save changes解决方案资源管理器 ,右键单击该项目,然后选择卸载项目 ,回答任何提示保存更改
  5. In Solution Explorer , right-click the project and choose Edit解决方案资源管理器 ,右键单击该项目,然后选择编辑
  6. Search for the <CodeAnalysisRules> element and copy the text within it搜寻<CodeAnalysisRules>元素和它的内复制文本
  7. Create an empty text file called [team].CodeAnalysis.Rules.targets , replacing [team] with the name of your team创建一个空的文本文件名为[team].CodeAnalysis.Rules.targets,用你项目的名称取代[team]
  8.  In the text file enter the following, replacing [rulesettings] with the text copied above in Step 6:在文本文件中输入以下,取代[rulesettings]与上述步骤6复制的文本:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">                        
   <
PropertyGroup>
      <
CodeAnalysisRules>$(CodeAnalysisRules);[rulesettings]</CodeAnalysisRules
   </
PropertyGroup>
 </
Project>

 

  1. 使用Visual Studio中,打开你的项目
  2. In Solution Explorer , right-click a project and choose Unload Project解决方案资源管理器 ,右键单击一个项目,然后选择卸载项目
  3. In Solution Explorer , right-click the unloaded project and choose Edit解决方案资源管理器 ,右键单击卸载项目,然后选择编辑
  4. Add the following <Import> element to the project, replacing [path] with the path of the targets file created above.添加以下<Import>元素项目,取代[path]与文件的创建上述目标的路径。 This needs to be the last line (just above the closing </Project> element) to ensure that settings within the project do not override the team settings:这需要在离</project>最近的最后一行,以确保在项目设置不重写队设置:

<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 

   [...]

   <Import Project="[path]" />
 </Project>

  1. Repeat from Step 11 for each project you want to share the rule settings with重复的步骤,每个项目要共享的规则设置11

其实也可以通过源代码管理工具签入签出工程项目文件实现规则共享,codeAnalysis的规则都保存在项目文件中。

在一个方法或类上排出某个规则或几个规则

[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1707:IdentifiersShouldNotContainUnderscores", MessageId = "Member")]

    protected virtual void DataPortal_Fetch(object criteria)

    {

      throw new NotSupportedException(Resources.FetchNotSupportedException);

    }

 

 

 附:其实还可以在一个工程项目中建一个文件,写下:

//------------------------------------------------------------
//CodeAnalysis 豁免规则
//------------------------------------------------------------

Assemblies should have valid string names
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA2210:AssembliesShouldHaveValidStrongNames")]

//Mark assemblies with CLSCompliantAttribute
//[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1014:MarkAssembliesWithClsCompliant")]

/*
[assembly:
SuppressMessage(
"Microsoft.Globalization", "CA1304:SpecifyCultureInfo",
Scope = "member|type|namespace",
Target = "...|....|"
)]

System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
public PartCreator(Func<PartLifetimeContext<T>> creator, TMetadata metadata)
    : base(creator)
{
    this._metadata = metadata;
}
*/

都一样效果

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值