SDK pinning and project references
SDK pinning and project references
The SDK provides the compiler and build tools. A target framework specifies the API surface a project builds against. Project references connect source projects so that their compatible outputs can be built and consumed together. Choose these independently: installing a newer SDK does not by itself retarget an application.
Proposed baseline: .NET SDK 10.0.404, net10.0 / C# 14. All results are reasoned, not executed. Build and test examples require an approved isolated environment. Framework examples are separate test classes, not console entry points.
Pin the SDK at the repository root
Use a full SDK version in global.json. The CLI searches upward from its working directory. This example deliberately fails rather than silently selecting a different SDK.
{ "sdk": { "version": "10.0.404", "rollForward": "disable", "allowPrerelease": false }}The version is documented, not installed here. Strict pinning is useful in controlled CI, but must be updated for servicing. A reviewed latestPatch policy can permit patch updates in the same feature band.
Expected observation (reasoned, not executed):
With SDK 10.0.404 installed, dotnet --version reports 10.0.404 from this directory; without it, SDK selection fails.Declare a library target
Save as Rates/Rates.csproj. A TFM is not a compiler version or a runtime identifier. The SDK provides default compile items.
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>net10.0</TargetFramework> <Nullable>enable</Nullable> <ImplicitUsings>disable</ImplicitUsings> </PropertyGroup></Project>The project has no OutputType of Exe. Multiple targets use TargetFrameworks with semicolon-separated TFMs; each target needs a compatible reference pack and must be checked separately.
Expected observation (reasoned, not executed):
The project builds a library for net10.0 when the matching reference pack is available.Connect a console app to the library
Save as App/App.csproj. Relative reference paths start at the project containing the item, not the terminal working directory.
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>net10.0</TargetFramework> <Nullable>enable</Nullable> <ImplicitUsings>disable</ImplicitUsings> </PropertyGroup> <ItemGroup> <ProjectReference Include="../Rates/Rates.csproj" /> </ItemGroup></Project>The reference expresses a build dependency; it is not a NuGet package reference or a guarantee of API compatibility. See the accompanying local rates lab for the complete file tree.
Expected observation (reasoned, not executed):
Building App normally also builds Rates and makes its public types available to App.Common mistakes and edge cases
Do not use a floating SDK selection in a reproducibility exercise without documenting the policy. Do not confuse net10.0 with linux-x64: the first selects a framework, the second is a runtime identifier used for platform-specific assets. A multi-targeted library may not compile the same code for every framework. Review all project files and inherited imports before build or restore.
Practice and recap
An app targeting net10.0 references a library targeting net10.0. The exact SDK is missing but a newer feature band is installed. Explain the effect of rollForward disable and propose a reviewed update procedure.
Hint: Check dotnet --list-sdks in the lab; compare SDK selection and TFM separately.
Learning objective: Choose explicit SDK and target framework. See accompanying manual practice and knowledge check.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
SDK pinning and project references — knowledge check
Apply the lesson concepts to the following scenarios.
Which file controls repository SDK selection?
What does net10.0 select?
The exact pinned SDK is absent with rollForward disable. What happens?
What does ProjectReference normally connect?
Why verify each TFM in a multitargeted project?