integrating-sdk-and-msbuild

Guides authoring SDK targets and coordinating MSBuild-SDK integration boundary changes.

1.2k|337|Updated Oct 13, 2022
One-click install
npx skills add https://github.com/dotnet/dotnet --skill integrating-sdk-and-msbuild
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: integrating-sdk-and-msbuild
Source: https://github.com/dotnet/dotnet/tree/main/src/msbuild/.github/skills/integrating-sdk-and-msbuild
Command: npx skills add https://github.com/dotnet/dotnet --skill integrating-sdk-and-msbuild

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Working at the MSBuild-SDK boundary is error-prone: import ordering bugs, restore/build evaluation conflicts, and project-reference protocol changes span multiple repos (MSBuild, SDK, NuGet, Roslyn), and mistakes cause subtle build failures that are hard to diagnose.

Core Features & Use Cases

  • Evaluation Order Guidance: Explains MSBuild's import order (Sdk.props, Directory.Build.props, project file, Directory.Build.targets, Sdk.targets) and how to author SDK defaults that respect user overrides.
  • Target Authoring Patterns: Covers extension points like BuildDependsOn, CompileDependsOn, PublishDependsOn, and PackDependsOn, plus rules for DependsOnTargets, incremental build Inputs/Outputs, and multi-targeting behavior.
  • Cross-Repo Coordination: Describes the protocol for landing changes across MSBuild, SDK, and NuGet, including design-time build contracts for Visual Studio.
  • Use Case: When a property has the wrong value at build time, use the import-ordering rules and the common integration bugs table to determine whether an SDK default is clobbering a user-specified setting.

Quick Start

Ask the AI to review your custom SDK target for correct DependsOnTargets ordering and conditional property defaults before committing it to the dotnet/sdk repo.

Frequently Asked Questions about integrating-sdk-and-msbuild

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I author MSBuild targets for the .NET SDK?

Author SDK targets using well-known extension points like BuildDependsOn, CompileDependsOn, PublishDependsOn, and PackDependsOn. Prefer DependsOnTargets over BeforeTargets/AfterTargets, and declare precise Inputs and Outputs for incremental builds.

Why does my MSBuild property have the wrong value in the SDK?

Wrong property values usually come from import ordering issues. SDK props import before the user project, so SDK defaults must use Condition="'$(Prop)' == ''" to avoid overriding user-specified values in the .csproj or Directory.Build.props.

Can I run restore and build in the same MSBuild invocation?

No, restore and build must never run in the same evaluation. Restore generates .g.props and .g.targets files that must be imported during evaluation, but they do not exist until restore completes, so running /t:Restore;Build causes intermittent failures.

How does the project-reference protocol work with multi-targeting?

The outer build dispatches to _GetProjectReferenceTargetFrameworkProperties to determine inner build parameters, then runs an inner build per resolved TargetFramework. SetTargetFramework communicates the chosen framework, and GetTargetPath returns the output assembly.

Why does my build work in CLI but fail in Visual Studio?

Visual Studio uses design-time builds that set $(DesignTimeBuild)=true and $(BuildingProject)=false, calling ResolveProjectReferences but not Build. Targets that ignore these properties or perform expensive I/O violate the design-time contract and cause failures.

How do I coordinate changes across MSBuild and dotnet/sdk repos?

File an issue in both repos describing the cross-cutting change, land the MSBuild engine change first since it is lower in the stack, then update the SDK via dependency flow and validate with the SDK's MSBuild integration tests.