liveBook · Manning

Global.json

As explained in Pro ASP.NET Core 7, Tenth Edition

global.json is a .NET configuration file that controls SDK selection and can specify the .NET version used by projects in a directory hierarchy.

global.json is a .NET configuration file that pins the SDK version used by projects beneath its directory, helping developers obtain consistent results. section 2.2 section 4.1.1

Use global.json to:

  • Select a specific .NET SDK version before creating or working with an ASP.NET Core project. section 2.2
  • Keep development environments aligned and reduce surprises from breaking changes between .NET releases. section 4.1.1
  • Create the file with the globaljson configuration template and --sdk-version option. section 4.1.1

Pinning the SDK during project creation

dotnet new globaljson --sdk-version 7.0.100 --output MySolution/MyProject dotnet new web --no-https --output MySolution/MyProject --framework net7.0 dotnet new sln -o MySolution dotnet sln MySolution add MySolution/MyProject The first command creates global.json; the following commands create a minimal ASP.NET Core project and add it to a solution. section 4.1.1

Listing 2.3 Creating a new project
dotnet new globaljson --sdk-version 7.0.100 --output FirstProject 
dotnet new mvc --no-https --output FirstProject --framework net7.0
dotnet new sln -o FirstProject
dotnet sln FirstProject add FirstProject

View a complete command-line listing that pins SDK 7.0.100 and creates an MVC project targeting net7.0. section 2.2

How Pro ASP.NET Core 7, Tenth Edition covers it

How deep it goes
Explains SDK selection, team consistency, and CLI generation, but does not detail the file’s schema.
Examples
Demonstrates globaljson generation with SDK 7.0.100 before creating net7.0 MVC or web projects.
What it assumes
Assumes PowerShell or another command prompt and access to the .NET SDK command-line templates.
What you can do after
Operate/configure project SDK selection through the dotnet CLI.
How it connects
Connects .NET SDK selection with the dotnet CLI, ASP.NET Core project templates, and solution files.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Pro ASP.NET Core 7, Tenth Edition. The section links point to the parts of the book it draws on.