static-analysis
.NET static analysis and code quality tools. Use when configuring analyzers, fixing warnings, or enforcing code standards.
What this skill does
# .NET Static Analysis
## Built-in Analyzers
### .NET Analyzers
.NET SDK includes analyzers for code quality and style. Enable in project file:
```xml
<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>
```
### Analysis Categories
| 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 |
## Running Analysis
### With Build
```bash
# Build with analyzers (default)
dotnet build
# Ensure analyzers run
dotnet build /p:RunAnalyzersDuringBuild=true
# Treat warnings as errors
dotnet build /p:TreatWarningsAsErrors=true
# Run only analyzers (no compile)
dotnet build /p:RunAnalyzers=true /p:RunCodeAnalysis=true
```
### As Separate Step
```bash
# Format check (style only)
dotnet format --verify-no-changes
# Format and fix
dotnet format
# Analyze specific project
dotnet build src/MyApp/MyApp.csproj /p:TreatWarningsAsErrors=true
```
## Configuring Rules
### EditorConfig
```ini
# .editorconfig
root = true
[*.cs]
# Naming conventions
dotnet_naming_rule.private_fields_should_be_camel_case.severity = warning
dotnet_naming_rule.private_fields_should_be_camel_case.symbols = private_fields
dotnet_naming_rule.private_fields_should_be_camel_case.style = camel_case_style
dotnet_naming_symbols.private_fields.applicable_kinds = field
dotnet_naming_symbols.private_fields.applicable_accessibilities = private
dotnet_naming_style.camel_case_style.capitalization = camel_case
dotnet_naming_style.camel_case_style.required_prefix = _
# Code style
csharp_style_var_for_built_in_types = true:suggestion
csharp_style_expression_bodied_methods = when_on_single_line:suggestion
csharp_prefer_braces = true:warning
# Analyzer rules
dotnet_diagnostic.CA1062.severity = warning # Validate arguments
dotnet_diagnostic.CA2007.severity = none # Don't require ConfigureAwait
dotnet_diagnostic.IDE0044.severity = warning # Make field readonly
```
### GlobalAnalyzerConfig
```ini
# .globalconfig
is_global = true
# Apply to all projects
dotnet_diagnostic.CA1062.severity = warning
dotnet_diagnostic.CA2000.severity = error
```
### Project-Level
```xml
<PropertyGroup>
<!-- Suppress in entire project -->
<NoWarn>$(NoWarn);CA1062;CA2007</NoWarn>
<!-- Treat specific as error -->
<WarningsAsErrors>$(WarningsAsErrors);CA2000</WarningsAsErrors>
</PropertyGroup>
```
## Suppressing Warnings
### Code-Level Suppression
```csharp
// 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")]
```
### Global Suppressions
```csharp
// GlobalSuppressions.cs
using System.Diagnostics.CodeAnalysis;
[assembly: SuppressMessage("Design", "CA1062",
Scope = "namespaceanddescendants",
Target = "~N:MyApp.Controllers")]
```
## Common Analyzer Rules
### CA1062 - Validate Arguments
```csharp
// 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();
}
```
### CA2007 - ConfigureAwait
```csharp
// Warning in library code
await SomeAsync(); // CA2007
// Fixed
await SomeAsync().ConfigureAwait(false);
// Or suppress in application code (.editorconfig)
dotnet_diagnostic.CA2007.severity = none
```
### CA1822 - Mark Members Static
```csharp
// Warning: can be static
public int Calculate(int x) => x * 2; // CA1822
// Fixed
public static int Calculate(int x) => x * 2;
```
### IDE0044 - Make Field Readonly
```csharp
// Warning
private int _value; // IDE0044
// Fixed
private readonly int _value;
```
### CA2000 - Dispose Objects
```csharp
// 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);
}
```
## dotnet format
### Check Formatting
```bash
# Check without changes
dotnet format --verify-no-changes
# Check specific files
dotnet format --include "src/**/*.cs" --verify-no-changes
# Exclude paths
dotnet format --exclude "**/Migrations/**"
```
### Apply Fixes
```bash
# Fix all issues
dotnet format
# Fix style issues only
dotnet format style
# Fix analyzers only
dotnet format analyzers
# Fix specific severity
dotnet format --severity warn
```
### Targeting
```bash
# Whitespace only
dotnet format whitespace
# Style and analyzers
dotnet format style
dotnet format analyzers
# Specific diagnostics
dotnet format --diagnostics CA1062 IDE0044
```
## Third-Party Analyzers
### StyleCop.Analyzers
```bash
dotnet add package StyleCop.Analyzers
```
```ini
# .editorconfig
# Configure StyleCop rules
dotnet_diagnostic.SA1101.severity = none # Prefix local calls with this
dotnet_diagnostic.SA1200.severity = none # Using directives placement
dotnet_diagnostic.SA1633.severity = none # File header
```
### Roslynator
```bash
dotnet add package Roslynator.Analyzers
```
### SonarAnalyzer
```bash
dotnet add package SonarAnalyzer.CSharp
```
## CI Integration
### Quality Gate Script
```bash
#!/bin/bash
# Run build with analysis
dotnet build --no-restore /p:TreatWarningsAsErrors=true
# Check format
dotnet format --verify-no-changes
# Exit with error if any issues
exit $?
```
### Azure DevOps
```yaml
- task: DotNetCoreCLI@2
displayName: 'Build with Analysis'
inputs:
command: build
arguments: '/p:TreatWarningsAsErrors=true'
```
See [analyzers.md](analyzers.md) for detailed analyzer configurations.
Related in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.