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
