Symptoms
Suddenly you get build errors in your build pipeline which perfectly builds in your local machine 🤔🤔🤔
Cause
Most likely the root cause is .NET SDK versions. Your local machine builds on a different SDK and the pipeline builds on a different SDK.
Resolution
The ideal way of solving this is to force everyone to use one define .Net SDK. Regardless of whether it is a developer or CI pipeline.
Simply to make this happen .NET provides you a file called "global.json".
The global.json file allows you to define which .NET SDK version is used when you run .NET CLI commands. Selecting the .NET SDK version is independent from specifying the runtime version a project targets.
For information about specifying the runtime version instead of the SDK version, see Target frameworks.
If you always want to use the latest SDK version that is installed on your machine, no global.json file is needed.
Into the Depth
The sample global.json file looks like the below,
{
"sdk": {
"version": "3.1.100",
"rollForward": "disable"
"allowPrerelease": false
}
}
version: String
The version of the .NET SDK to use.
allowPrerelease: Boolean
Indicates whether the SDK resolver should consider prerelease versions when selecting the SDK version to use.
rollForward: String
The roll-forward policy to use when selecting an SDK version, either as a fallback when a specific SDK version is missing or as a directive to use a higher version.
To set an SDK version in the global.json file, it's helpful to know which SDK versions are installed on your machine. How to do that,
Type this one your command line
dotnet --list-sdks
This command will give you all the installed SDK versions like the below,
3.1.424 [C:\program files\dotnet\sdk] 5.0.100 [C:\program files\dotnet\sdk] 6.0.402 [C:\program files\dotnet\sdk] 7.0.100 [C:\program files\dotnet\sdk]
3.1.424 [C:\program files\dotnet\sdk] 5.0.100 [C:\program files\dotnet\sdk] 6.0.402 [C:\program files\dotnet\sdk] 7.0.100 [C:\program files\dotnet\sdk]
You can create a new global.json file in the current directory by executing the dotnet new command, similar to the following example:
dotnet new globaljson --sdk-version 6.0.100
May the force be with you!
Comments
Post a Comment