Visual studio 2017 Update 3 - The SDK 'Microso

2019-02-11 22:35发布

问题:

Error:

C:\WebApp\WebApp.csproj : error : The SDK 'Microsoft.NET.Sdk.Web' specified could not be found. C:\WebApp\WebApp.csproj

I am trying to open Dotnet core project and I am getting the above error.

I have installed the latest SDK from https://www.microsoft.com/net/core#windowscmd

I have checked the path for dotnet cmd and it works fine.

Am I missing something? Let me know if you need more information.

The target framework is set to .NET 4.5.2

回答1:

I stumbled upon this issue a number of times recently. Here's a brief list of the workaround I found (one of them always worked until now):

  1. Install the right .NET Core SDK: Either the latest version or the version required by your project.
  2. Clean-up obsolete .NET Core versions: Go to Control Panel and uninstall previous .NET Core SDK/Runtime versions (as long as you don't use them anymore).
  3. Create a Global.json file: Add a new global.json file to your project's root with the following content (replace the .NET Core version build with the one you want to run the project with):

    { "sdk": { "version": "2.0.5" } }

  4. Rename the SDK reference: Open your .proj file and replace <project sdk="Microsoft.NET.Sdk.web"> with <project sdk="Microsoft.NET.Sdk"> .

  5. Add the MSBuildSDKsPath Environment Variable: The dotnet CLI sets the MSBuildSDKsPath environment variable when invoking MSBuild: however, a December 2016 patch changed the CLI behaviour so that it will respect an existing environment variable, if it has already been set: this will allow the developer to “force” the CLI to use a specific SDK.

  6. Check your PATH: Verify that both C:\Program Files\dotnet and C:\Program Files (x86)\dotnet are in the PATH environment variable.

For additional info regarding the issue and other viable fixes check out this blog post that I wrote on this topic.



回答2:

I agree with the comment on Sundeep's answer, you shouldn't have a global.json file in your project anymore.

It seems as though installing the .NET Core 2.0 SDK is causing issues with the PATH. Verify that C:\Program Files\dotnet and C:\Program Files (x86)\dotnet are in the PATH environment variable. In my case, these values were already present under System Variables so I added them to User Variables and rebooted my machine. This resolved my issue.



回答3:

As suggested in the comment, I updated global.json file as shown below

{
  "sdk": {
  "version": "1.0.0"
 } 
}

Also, I had to remove the <ItemGroup> which contains wwwroot files path in .csproj file.

Reload the project and it works like a charm!



回答4:

I've encounter same problem, I just rename <project sdk="Microsoft.NET.Sdk.web"> to <project sdk="Microsoft.NET.Sdk"> on csproj



回答5:

I was running into an issue where creating a new ASP.NET Core 2.0 project was giving me an error The SDK 'Microsoft.Net.Sdk.Web' specified could not be found, and leaving me unable to open the project in Visual Studio. The problem was the project was created in a folder that contained a global.json file, tying the SDK version to 1.0.0.

Deleting the global.json, or updating it to 2.0.0, fixed the issue. Be sure to check parent folders too - if any parent folder contains a global.json, the SDK version specified in the "closest" folder will be used.



回答6:

I had this issue when I had to open a .Net Core 1.0.4 project in VS2017.

When I installed 1.0.4 SDK, i chose the x64 version which placed the sdk files in 'c:\Program Files\dotnet' ...

but my VS2017 was 32bit and was therefore looking for the sdk in 'c:\Program Files (x86)\dotnet'.

Once I installed the 32 bit version of the SDK it worked fine.