Keywords: Visual Studio 2017 | .NET Standard 2.0 | .NET Core SDK
Abstract: This article provides an in-depth analysis of the common error encountered when creating .NET Standard 2.0 class library projects in Visual Studio 2017 after updating to version 15.3. It explains the error message, diagnoses the issue by checking installed .NET Core SDK versions and global configuration files, and offers a complete solution. Key steps include using the dotnet --info command, downloading and installing the .NET Core 2.0 SDK, and understanding the impact of global.json files. The guide helps developers properly configure their environment for successful project builds.
After updating Visual Studio 2017 to version 15.3, many developers encounter a common error when trying to create class library projects targeting .NET Standard 2.0: "The current .NET SDK does not support targeting .NET Standard 2.0. Either target .NET Standard 1.6 or lower, or use a version of the .NET SDK that supports .NET Standard 2.0." This error indicates that the current development environment lacks the necessary components to support .NET Standard 2.0 development.
Analysis of the Error Cause
The core cause of this error is that the Visual Studio 2017 update process may not automatically install the .NET Core 2.0 SDK. Even if users have manually installed the .NET Framework 4.7 SDK and its targeting pack, these components do not directly provide support for .NET Standard 2.0. .NET Standard 2.0 requires a specific version of the .NET Core SDK for proper compilation and project building.
Diagnosing Installed SDK Versions
To confirm the .NET Core SDK versions installed on the system, developers can run the following command in the command line:
dotnet --info
This command outputs information about the currently available SDK versions, including runtime environments and the list of installed SDKs. If the output does not show an SDK version that supports .NET Standard 2.0 (e.g., .NET Core 2.0 or later), then manual installation of the missing component is required.
Installing the .NET Core 2.0 SDK
The direct solution to this problem is to download and install the .NET Core 2.0 SDK. Developers can obtain the installer from the official Microsoft website. After installation, restart Visual Studio 2017, and the .NET Standard 2.0 option should appear in the target framework dropdown when creating new projects.
Impact of Global Configuration Files
In some cases, even with the correct SDK version installed, projects may still fail to build. This could be due to the presence of a configuration file named global.json in the project. This file specifies the SDK version to use for the project and can be located in the current working directory or any of its parent directories. If global.json specifies an older SDK version that does not support .NET Standard 2.0, the build process will fail.
For example, a global.json file might contain:
{
"sdk": {
"version": "1.0.4"
}
}
In this example, the SDK version is pinned to 1.0.4, which does not support .NET Standard 2.0. Developers need to check and update this file or temporarily remove it to use the system's default SDK version.
Verifying the Solution
After installing the .NET Core 2.0 SDK and handling the global.json file, developers can run the dotnet --info command again to confirm the SDK version. If the output shows the .NET Core 2.0 SDK, they can attempt to rebuild the project. At this point, the project should compile successfully without the previous error message.
Summary and Best Practices
By following these steps, developers can effectively resolve the .NET SDK does not support targeting .NET Standard 2.0 error in Visual Studio 2017. Key points include ensuring the correct .NET Core SDK version is installed, checking and managing global configuration files, and using command-line tools for environment diagnosis. In practice, it is recommended to regularly update development tools and SDKs to avoid similar compatibility issues. Additionally, for team projects, unifying development environment configurations can reduce problems caused by environmental differences.