ktsu.Sdk
A comprehensive, robust MSBuild-based SDK for .NET projects that standardizes configuration, metadata management, and package workflows. Features intelligent project structure detection, hierarchical solution discovery, and path-based namespace generation. Supports multiple .NET versions (.NET 5.0+, .NET Standard 2.0/2.1) with optimizations for .NET 9.0+.
Quick Start
Installation
Add the SDK to your global.json (recommended):
{
"sdk": {
"version": "10.0.100",
"rollForward": "latestFeature"
},
"msbuild-sdks": {
"MSTest.Sdk": "4.3.2",
"ktsu.Sdk": "2.26.1",
"ktsu.Sdk.ConsoleApp": "2.26.1",
"ktsu.Sdk.App": "2.26.1",
"ktsu.Sdk.Tool": "2.26.1",
"ktsu.Sdk.Web": "2.26.1",
"ktsu.Sdk.Windows": "2.26.1",
"ktsu.Sdk.Linux": "2.26.1",
"ktsu.Sdk.macOS": "2.26.1",
"ktsu.Sdk.iOS": "2.26.1",
"ktsu.Sdk.Android": "2.26.1",
"ktsu.Sdk.Unity": "2.26.1",
"ktsu.Sdk.Godot": "2.26.1"
},
"test": {
"runner": "Microsoft.Testing.Platform"
}
}
And reference in your project file:
<Project>
<Sdk Name="Microsoft.NET.Sdk" />
<Sdk Name="ktsu.Sdk" />
<PropertyGroup>
<!-- Your project-specific properties -->
</PropertyGroup>
</Project>
Basic Usage
For a library project:
<Project Sdk="Microsoft.NET.Sdk">
<Sdk Name="ktsu.Sdk" />
</Project>
For a console application:
<Project Sdk="Microsoft.NET.Sdk">
<Sdk Name="ktsu.Sdk" />
<Sdk Name="ktsu.Sdk.ConsoleApp" />
</Project>
For a GUI application:
<Project Sdk="Microsoft.NET.Sdk">
<Sdk Name="ktsu.Sdk" />
<Sdk Name="ktsu.Sdk.App" />
</Project>
For a .NET tool (distributed via dotnet tool install):
<Project Sdk="Microsoft.NET.Sdk">
<Sdk Name="ktsu.Sdk" />
<Sdk Name="ktsu.Sdk.Tool" />
</Project>
For an ASP.NET Core web application or service:
<Project Sdk="Microsoft.NET.Sdk.Web">
<Sdk Name="ktsu.Sdk" />
<Sdk Name="ktsu.Sdk.Web" />
</Project>
Note the outer SDK. An <Sdk Name="..." /> element extends the base SDK rather than replacing
it, so ktsu.Sdk.Web cannot supply the ASP.NET Core framework reference itself. Use
Microsoft.NET.Sdk.Web as above, or keep Microsoft.NET.Sdk and add
<FrameworkReference Include="Microsoft.AspNetCore.App" /> for a service that wants the runtime
without the Web SDK's static asset and Razor machinery. That second form does not bring the Web
SDK's implicit global usings, so write them yourself. It does still get appsettings.json and
appsettings.*.json copied to the output, because ktsu.Sdk.Web contributes those itself.
Getting neither SDK nor framework reference is KTSU1005.
For a platform-specific application (e.g. Linux), reference the matching SDK:
<Project Sdk="Microsoft.NET.Sdk">
<Sdk Name="ktsu.Sdk" />
<Sdk Name="ktsu.Sdk.Linux" />
</Project>
The same pattern applies to ktsu.Sdk.Windows, ktsu.Sdk.macOS,
ktsu.Sdk.iOS, and ktsu.Sdk.Android. Mobile targets require the relevant .NET
workload (dotnet workload install android ios maui), and iOS additionally
requires a macOS host with Xcode.
For a Unity managed plug-in:
<Project Sdk="Microsoft.NET.Sdk">
<Sdk Name="ktsu.Sdk" />
<Sdk Name="ktsu.Sdk.Unity" />
</Project>
For a Godot game assembly, Godot.NET.Sdk is the outer SDK:
<Project Sdk="Godot.NET.Sdk/4.7.2">
<Sdk Name="ktsu.Sdk" />
<Sdk Name="ktsu.Sdk.Godot" />
</Project>
Order matters in both cases: ktsu.Sdk first, then the extension SDK, which is
what lets the extension override the core defaults.
Key Features
๐๏ธ Intelligent Project Structure
- Hierarchical Solution Discovery: Automatically finds solution files up to 5 directory levels above the project
- Path-Based Namespace Generation: Creates namespaces from directory structure between solution and project
- Smart Project Detection: Automatically detects primary, console, GUI, and test project types
- Nested Project Support: Works seamlessly with deeply nested project structures
๐ก๏ธ Robust Error Handling
- Safe Array Operations: Prevents index-out-of-bounds errors in MSBuild expressions
- Null-Safe String Operations: Comprehensive null/empty checks for all string manipulations
- Graceful Fallbacks: Provides sensible defaults when metadata files or properties are missing
- Comprehensive Validation: Built-in validation for all file operations and property access
๐ฆ Advanced Package Management
- Multi-Target Support: .NET 10.0, 9.0, 8.0, .NET Standard 2.0/2.1 (default: net10.0).
Frameworks follow the .NET support lifecycle: one enters the list when it ships and leaves
when it goes out of support. .NET Standard 2.0/2.1 stay as the fallback, so a consumer on an
older framework resolves the netstandard2.1 asset rather than being stranded.
- MSBuildSdk Packaging: Properly configured for MSBuild SDK project packaging
- Automatic Metadata Integration: Seamlessly includes markdown files in package metadata
- Package Validation: Built-in API compatibility and package validation
- Source Link Integration: Automatic GitHub and Azure Repos source linking for debugging
- Central Package Management: Requires and works with Directory.Packages.props
Upgrading: Moving to a ktsu.Sdk version that dropped a target framework from this list can fail
your next dotnet pack if your project carries a CompatibilitySuppressions.xml. See
Package Validation Fails After a Framework Is Dropped
below.
๐ง Development Workflow
- Analyzer-Enforced Requirements: Roslyn analyzers (KTSU0001/KTSU0002) ensure proper package dependencies and internals visibility with helpful diagnostics and code fixers
- Internals Visibility: Code fixer to easily add InternalsVisibleTo attributes for test projects
- GitHub Integration: Built-in support for GitHub workflows and CI/CD
- Cross-Platform Support: Compatible with Windows, macOS, and Linux
- Documentation Generation: Automated XML documentation file generation
- Strict Code Quality: Nullable enabled, warnings as errors, latest analyzer rules
SDK Components
This repository contains the following SDK packages:
ktsu.Sdk (Core)
The base SDK that all projects should reference. Provides:
- Solution and project discovery
- Namespace generation
- Metadata file integration
- Multi-target framework support
- Automatic project references
- Package configuration
- Code quality defaults
ktsu.Sdk.ConsoleApp
Extension SDK for console applications. Adds:
OutputType=Exe configuration
- Single target framework (net10.0)
- Cross-platform console optimizations
ktsu.Sdk.App
Extension SDK for GUI applications (ImGui, WinForms, WPF, etc.). Adds:
OutputType=WinExe on Windows (no console window)
OutputType=Exe on other platforms
- Single target framework (net10.0)
- Platform-specific runtime configurations
ktsu.Sdk.Tool
Extension SDK for applications distributed as .NET tools. Adds:
PackAsTool=true, producing a DotnetTool package instead of an executable
- Single target framework (net10.0), since a tool package cannot multi-target
ToolCommandName derived from the lowercased solution name โ a solution named
KtsuBuild installs as ktsubuild. Set ToolCommandName explicitly to override,
which short or generic solution names should do.
- No runtime identifiers: a tool ships as one RID-agnostic, framework-dependent
package, so consumers need the .NET 10 runtime. For a standalone binary, add a
separate
ktsu.Sdk.ConsoleApp project.
A project named {Solution}.Tool or {Solution}Tool also sets IsToolProject.
{Solution}.CLI deliberately does not โ CLI projects stay console apps unless they
reference this SDK.
Note that packing any project requires the metadata files the SDK declares as package
metadata (LICENSE.md, README.md, icon.png) to exist in the solution directory.
ktsu.Sdk.Web
Extension SDK for ASP.NET Core web applications and services. Adds:
- Single target framework (net10.0). ASP.NET Core publishes no netstandard surface, so the
core SDK's multi-target default cannot stand: its netstandard inner builds fail inside the
Web SDK's generated global usings, as a wall of CS0234 naming neither the framework nor the
SDK responsible. KTSU1004 catches a consumer putting
TargetFrameworks back.
CS1591 suppressed, while GenerateDocumentationFile stays on. The core SDK pairs
documentation generation with warnings-as-errors, which fails a build on the first
undocumented public type. That is right for a library, whose public types are its product,
and wrong for a service, whose public types are request and response shapes with no external
consumer. The documentation file itself is kept because OpenAPI generators read it.
- Package validation, assembly API compatibility and
IncludeSource disabled, as on
ktsu.Sdk.Tool: a web application ships as a container image or a published directory, never
as a package.
IsWebProject=true, matching the IsWindowsProject / IsLinuxProject family so CI and
tooling can tell a service from a library without parsing the project file.
appsettings.json and appsettings.*.json copied to the output and publish directories, but
only on the plain Microsoft.NET.Sdk path. Microsoft.NET.Sdk.Web contributes its own content
glob, and a second one here would list the same file twice. Without this the plain-SDK form
builds clean and with no warning, and the service then starts with none of its configuration,
because the default host reads those files from the content root and finds nothing.
RuntimeIdentifiers is deliberately left as the core SDK's desktop list. A service is
published with an explicit RID about as often as without one, the list permits values rather
than causing a build fan-out, and narrowing it would reject a legitimate -r win-x64.
This is the one SDK in the family whose outer SDK is not Microsoft.NET.Sdk. See the usage
example above, and KTSU1005 for what happens when the ASP.NET Core framework reference is
missing entirely.
Platform-Specific App SDKs
These extension SDKs target a single platform. They fall into two groups:
Desktop (RID-based, no extra prerequisites): build self-contained apps on
the base net10.0 runtime with the runtime identifiers narrowed to one OS.
- ktsu.Sdk.Windows โ
net10.0, OutputType=WinExe, RIDs win-x64;win-x86;win-arm64
- ktsu.Sdk.Linux โ
net10.0, OutputType=Exe, RIDs linux-x64;linux-arm64;linux-musl-x64;linux-musl-arm64
- ktsu.Sdk.macOS โ
net10.0, OutputType=Exe, RIDs osx-x64;osx-arm64
Mobile (TFM + workload): use platform-specific target frameworks and require
the corresponding .NET workload.