Skip to content

meziantou/Meziantou.NET.Sdk

Repository files navigation

Meziantou.NET.Sdk

  • Meziantou.NET.Sdk on NuGet

MSBuild SDK that provides:

  • Opinionated defaults for .NET projects
  • Naming conventions
  • Static analysis with Roslyn analyzers
  • Set ContinuousIntegrationBuild based on the context
  • dotnet test features
    • Dump on crash or hang
    • Loggers when running on GitHub
    • Disable Roslyn analyzers to speed up build
  • Relevant NuGet packages based on the project type

Usage

Method 1

To use it, create a global.json file at the solution root with the following content:

{
  "sdk": {
    "version": "9.0.304"
  },
  "msbuild-sdks": {
    "Meziantou.NET.Sdk": "1.0.16",
    "Meziantou.NET.Sdk.BlazorWebAssembly": "1.0.16",
    "Meziantou.NET.Sdk.Razor": "1.0.16",
    "Meziantou.NET.Sdk.Test": "1.0.16",
    "Meziantou.NET.Sdk.Web": "1.0.16",
    "Meziantou.NET.Sdk.WindowsDesktop": "1.0.16"
  }
}

And reference the SDK in your project file:

<Project Sdk="Meziantou.NET.Sdk">
</Project>

Method 2

You can the SDK by specifying the version inside the csproj file:

<Project Sdk="Meziantou.NET.Sdk/1.0.16">
</Project>

Method 3

<Project Sdk="Microsoft.NET.SDK">
    <Sdk Name="Meziantou.NET.Sdk" Version="1.0.16" />
</Project>

Build configuration properties

Set these properties in your project file or a directory-level props file. Unless stated otherwise, defaults apply only when the property is empty.

General build

Property Default Description
ContinuousIntegrationBuild Auto-detected Set to true or false to force CI behavior (warnings as errors, code style enforcement, SBOM, code coverage, npm locked mode).
TargetFramework net$(NETCoreAppMaximumVersion) Used when both TargetFramework and TargetFrameworks are empty.
GenerateSBOM true on CI Controls SBOM generation on CI builds.
RollForward LatestMajor Applied for non-test projects when unset.
SuppressNETCoreSdkPreviewMessage true Suppresses preview SDK message.
PublishRepositoryUrl true Publishes repository URL in packages.
DebugType embedded Embeds PDBs in the output.
EmbedUntrackedSources true Embeds untracked sources in PDBs.
ImplicitUsings enable Enables implicit global usings.
Nullable enable Enables nullable reference types.
GenerateDocumentationFile true Generates XML docs.
RestoreUseStaticGraphEvaluation false Disables static graph restore.
RestoreSerializeGlobalProperties true Serializes global properties for restore.
ReportAnalyzer true Enables analyzer reporting.
Features strict Enables strict compiler features.
Deterministic true Enables deterministic builds.
EnableNETAnalyzers true Enables .NET analyzers.
AnalysisLevel latest-all Uses the latest analyzer rules.
AllowUnsafeBlocks true Allows unsafe code blocks.
LangVersion latest Uses the latest C# language version.
MSBuildTreatWarningsAsErrors true on CI or Release Treats MSBuild warnings as errors.
TreatWarningsAsErrors true on CI or Release Treats compiler warnings as errors.
EnforceCodeStyleInBuild true on CI or Release Enforces analyzer code style during builds.
AccelerateBuildsInVisualStudio true Enables faster builds in Visual Studio.

Package validation and auditing

Property Default Description
EnablePackageValidation true Enables package validation when unset.
NuGetAudit true Enables NuGet vulnerability auditing.
NuGetAuditMode all Audits all dependency types.
NuGetAuditLevel low Minimum severity level to report.
WarningsAsErrors Adds NU1900NU1904 on CI or Release Promotes NuGet audit warnings to errors.

Banned symbols and analyzers

Property Default Description
IncludeDefaultBannedSymbols true Includes the default banned API list.
BannedNewtonsoftJsonSymbols true Includes banned Newtonsoft.Json APIs.
Disable_SponsorLink true Removes SponsorLink and Moq analyzers when not set to false.

Web SDK and containers

Property Default Description
AutoRegisterServiceDefaults true Adds ServiceDefaults auto-registration for web projects unless set to false.
EnableSdkContainerSupport true on GitHub Actions Enables container support for web projects on GitHub Actions.
ContainerRegistry ghcr.io Default container registry.
ContainerRepository From GitHub repository Default repository name when running on GitHub Actions.
ContainerImageTagsMainVersionPrefix 1.0 Prefix used to generate tags on the main branch.
ContainerImageTagsIncludeLatest true Appends latest tag on main.
ContainerImageTags Computed Uses build number on main and 0.0.1-preview.$(GITHUB_SHA) elsewhere when unset.

Packaging metadata

Property Default Description
SearchReadmeFileAbove false When true, searches parent directories for a README to pack.
PackageIcon icon.png for Meziantou projects Default icon when the project name starts with Meziantou and no value is set.
Authors meziantou for Meziantou projects Default authors when the project name starts with Meziantou and no value is set.
Company meziantou for Meziantou projects Default company when the project name starts with Meziantou and no value is set.
PackageLicenseExpression MIT for Meziantou projects Default license expression when the project name starts with Meziantou and no value is set.
PackageReadmeFile README.md when found Default README packing behavior when a README exists.

npm restore

Property Default Description
EnableDefaultNpmPackageFile Enabled when unset Enables automatic package.json inclusion as NpmPackageFile (set to false to disable).
NpmRestoreLockedMode true on CI or when RestoreLockedMode is true Uses npm ci when true, otherwise npm install.

Testing

Property Default Description
EnableCodeCoverage true on CI Enables code coverage collection on CI.
OptimizeVsTestRun true Disables analyzers during dotnet test unless set to false.
UseMicrosoftTestingPlatform Auto Uses MTP when set to true or when xunit.v3.mtp-v2 is referenced.
EnableDefaultTestSettings true Adds default crash/hang dumps and loggers.
TestingPlatformCommandLineArguments Appended Adds MTP arguments such as --report-trx and --coverage when enabled.
VSTestBlame true Enables VSTest blame.
VSTestBlameCrash true Enables crash dumps.
VSTestBlameCrashDumpType mini Sets crash dump type.
VSTestBlameHang true Enables hang dumps.
VSTestBlameHangDumpType mini Sets hang dump type.
VSTestBlameHangTimeout 10min Sets hang dump timeout.
VSTestCollect Code Coverage when enabled Enables VSTest code coverage.
VSTestSetting Default runsettings when enabled Uses the default runsettings file for coverage.
VSTestLogger trx;console%3bverbosity=normal Appends loggers, including GitHub Actions on CI.

About

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •