Loading...
Loading...
Compare original and translation side by side
<PropertyGroup>
<!-- Enable all .NET analyzers -->
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<!-- Analysis level (latest, 8.0, 7.0, etc.) -->
<AnalysisLevel>latest</AnalysisLevel>
<!-- Analysis mode: Default, Minimum, Recommended, All -->
<AnalysisMode>Recommended</AnalysisMode>
</PropertyGroup><PropertyGroup>
<!-- Enable all .NET analyzers -->
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<!-- Analysis level (latest, 8.0, 7.0, etc.) -->
<AnalysisLevel>latest</AnalysisLevel>
<!-- Analysis mode: Default, Minimum, Recommended, All -->
<AnalysisMode>Recommended</AnalysisMode>
</PropertyGroup>| Category | Prefix | Focus |
|---|---|---|
| Design | CA1xxx | API design guidelines |
| Globalization | CA2xxx | Internationalization |
| Performance | CA18xx | Performance optimizations |
| Security | CA2xxx, CA3xxx | Security vulnerabilities |
| Usage | CA2xxx | Correct API usage |
| Naming | CA17xx | Naming conventions |
| Reliability | CA2xxx | Error handling, resources |
| 类别 | 前缀 | 关注方向 |
|---|---|---|
| 设计 | CA1xxx | API设计准则 |
| 全球化 | CA2xxx | 国际化 |
| 性能 | CA18xx | 性能优化 |
| 安全 | CA2xxx, CA3xxx | 安全漏洞 |
| 使用规范 | CA2xxx | API正确使用方式 |
| 命名 | CA17xx | 命名规范 |
| 可靠性 | CA2xxx | 错误处理、资源管理 |
undefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefined<PropertyGroup>
<!-- Suppress in entire project -->
<NoWarn>$(NoWarn);CA1062;CA2007</NoWarn>
<!-- Treat specific as error -->
<WarningsAsErrors>$(WarningsAsErrors);CA2000</WarningsAsErrors>
</PropertyGroup><PropertyGroup>
<!-- Suppress in entire project -->
<NoWarn>$(NoWarn);CA1062;CA2007</NoWarn>
<!-- Treat specific as error -->
<WarningsAsErrors>$(WarningsAsErrors);CA2000</WarningsAsErrors>
</PropertyGroup>// Suppress on member
[SuppressMessage("Design", "CA1062:Validate arguments",
Justification = "Validated by framework")]
public void Process(Request request) { }
// Suppress on line
#pragma warning disable CA1062
public void Process(Request request) { }
#pragma warning restore CA1062
// Suppress all in file
[assembly: SuppressMessage("Design", "CA1062")]// Suppress on member
[SuppressMessage("Design", "CA1062:Validate arguments",
Justification = "Validated by framework")]
public void Process(Request request) { }
// Suppress on line
#pragma warning disable CA1062
public void Process(Request request) { }
#pragma warning restore CA1062
// Suppress all in file
[assembly: SuppressMessage("Design", "CA1062")]// GlobalSuppressions.cs
using System.Diagnostics.CodeAnalysis;
[assembly: SuppressMessage("Design", "CA1062",
Scope = "namespaceanddescendants",
Target = "~N:MyApp.Controllers")]// GlobalSuppressions.cs
using System.Diagnostics.CodeAnalysis;
[assembly: SuppressMessage("Design", "CA1062",
Scope = "namespaceanddescendants",
Target = "~N:MyApp.Controllers")]// Warning: parameter 'request' is never validated
public void Process(Request request)
{
request.Execute(); // CA1062
}
// Fixed
public void Process(Request request)
{
ArgumentNullException.ThrowIfNull(request);
request.Execute();
}// Warning: parameter 'request' is never validated
public void Process(Request request)
{
request.Execute(); // CA1062
}
// Fixed
public void Process(Request request)
{
ArgumentNullException.ThrowIfNull(request);
request.Execute();
}// Warning in library code
await SomeAsync(); // CA2007
// Fixed
await SomeAsync().ConfigureAwait(false);
// Or suppress in application code (.editorconfig)
dotnet_diagnostic.CA2007.severity = none// Warning in library code
await SomeAsync(); // CA2007
// Fixed
await SomeAsync().ConfigureAwait(false);
// Or suppress in application code (.editorconfig)
dotnet_diagnostic.CA2007.severity = none// Warning: can be static
public int Calculate(int x) => x * 2; // CA1822
// Fixed
public static int Calculate(int x) => x * 2;// Warning: can be static
public int Calculate(int x) => x * 2; // CA1822
// Fixed
public static int Calculate(int x) => x * 2;// Warning
private int _value; // IDE0044
// Fixed
private readonly int _value;// Warning
private int _value; // IDE0044
// Fixed
private readonly int _value;// Warning: not disposed
public void Process()
{
var stream = new FileStream("file.txt", FileMode.Open);
} // CA2000
// Fixed
public void Process()
{
using var stream = new FileStream("file.txt", FileMode.Open);
}// Warning: not disposed
public void Process()
{
var stream = new FileStream("file.txt", FileMode.Open);
} // CA2000
// Fixed
public void Process()
{
using var stream = new FileStream("file.txt", FileMode.Open);
}undefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefineddotnet add package StyleCop.Analyzersundefineddotnet add package StyleCop.Analyzersundefinedundefinedundefineddotnet add package Roslynator.Analyzersdotnet add package Roslynator.Analyzersdotnet add package SonarAnalyzer.CSharpdotnet add package SonarAnalyzer.CSharp#!/bin/bash#!/bin/bashundefinedundefined- task: DotNetCoreCLI@2
displayName: 'Build with Analysis'
inputs:
command: build
arguments: '/p:TreatWarningsAsErrors=true'- task: DotNetCoreCLI@2
displayName: 'Build with Analysis'
inputs:
command: build
arguments: '/p:TreatWarningsAsErrors=true'