112

After format my computer I reinstalled Vs 2017 V 15.6.3 and install ASP.Net Core SDK from Microsoft 2.1.4

But when I create new asp core application VS failed with error

"Project file is incomplete. Expected imports are missing"

Please, can anyone help?

Error after while creating ASP core application

JonathanDavidArndt
  • 2,518
  • 13
  • 37
  • 49
Majd Albaho
  • 1,311
  • 2
  • 10
  • 14
  • How did you " install ASP.Net Core SDK from Microsoft 2.1.4"? Using the Visual Studio Installer, or by some other process? – Neil Mar 22 '18 at 15:34
  • can you post your project file? – Francesco B. Mar 22 '18 at 16:28
  • 1
    I have used this link to setup .net core sdk https://www.microsoft.com/net/download/thank-you/dotnet-sdk-2.1.101-windows-x64-installer – Majd Albaho Mar 22 '18 at 18:21
  • Mmm, you want me to upload project files from my hard ? Because my visual studio show nothing in the solution – Majd Albaho Mar 22 '18 at 18:24
  • For me the issue was that I wasn't using the required dotnet sdk 2.1.104; I was using a much earlier version which another solution demands. Once I changed the active dotnet SDK to 2.1.104 the problem resolved itself. See this CLI tool: https://reynders.co/use-this-helper-cli-for-switching-net-core-sdk-versions/ – Nigel Belham May 01 '18 at 13:43
  • New in a project with a freshly installed vs 2017 on a new computer? Check if the expected .NET Core version is installed: `dotnet --list-sdks`. I had only `2.1.4` while the project required `1.1.10`. – Thomas Eyde Aug 27 '18 at 12:43
  • 4
    This answer helped me out https://stackoverflow.com/a/55529011/342113. Currently, it turns out the 2.2.1xx SDKs are compatible with VS.NET 2017, but the 2.2.2XX SDKs are not. – rsbarro Apr 12 '19 at 18:44
  • 1
    @rsbarro Exactly! Same problem here. [Therefore, I posted it as an answer](https://stackoverflow.com/a/55750005/590790). – Steven Jeuris Apr 18 '19 at 16:12
  • Doesn't anybody else think that we should ask microsoft to improve this? Looking at the answers it seems like there are lots of different causes of this that all lead to the same generic error message with little clue of what's the underlying problem. – AgostinoX Sep 05 '20 at 09:41

32 Answers32

72

I had the same issue. In my case, deleting global.json and appsettings solved the problem.

PilgrimViis
  • 1,511
  • 2
  • 17
  • 21
  • 10
    This worked for me although to clarify I just had to delete (/rename) "global.json". Fwiw: It contained: { "sdk": { "version": "2.0.0" } } – ubienewbie Apr 02 '18 at 17:06
  • I have the issue on a non-ASP project -- no global.json or appsettings file to be deleted/renamed – alelom May 10 '18 at 14:55
  • 2
    In my case, I had missing .NetCore version 2.0.0 installation on my machine and it was mentioned in global.json. So I just installed it and it worked fine. – Muhammad Umar Jun 04 '18 at 06:17
  • 3
    `dotnet --version` shows 2.1.201, while global.json mentioned a slightly lower version, 2.1.101. Apparently the version has to match exactly for it to work, no downwards compatibility. Or just remove the file as suggested in this answer. – GolezTrol Jun 05 '18 at 10:17
  • 7
    deleting only global.json was enough for me. The appsettings can stay on place – Wouter Janssens Aug 31 '18 at 06:34
  • Just deleting global.json was enough for me too. Thx all. – Mark Sep 22 '18 at 21:47
  • 13
    It would be nice to tell the folder(s) of global.json and appsettings in this answer. – fernacolo Mar 16 '19 at 23:38
  • I suggest Smart Dev answer before remove global.json: https://stackoverflow.com/a/52311504/5522115 – George Wurthmann Jun 14 '19 at 13:26
43

Another potential cause is you installed a .NET Core version which is incompatible with Visual Studio. This might be unrelated to the original question by the OP, since it concerns different version numbers, but since I landed on this page while looking for help I thought this might be useful to others.

At the time of writing, I installed .NET Core 2.2.203 which is not compatible with Visual Studio 2017 (Professional 15.9.11).

The .NET Core download page lists a separate download for Visual Studio 2017. Be sure to download this one when you intend to use Visual Studio 2017. The current supported version is .NET Core 2.2.106.

Steven Jeuris
  • 18,274
  • 9
  • 70
  • 161
  • Oddly, in my app I have an N-Tier app (UI, BLL and DAL). The BLL project loaded fine wtih this version of .NET Core. +1 – Dave May 09 '19 at 06:57
  • Thank you very much! This works! SDK 2.2.105 only works with Visual Studio 15.9.8 or lower. – hubert17 May 21 '19 at 05:06
  • upgrading the VS 2017 Community to version 15.9.12 solved the issue in my case – GoldenAge May 29 '19 at 14:02
26

You can check global.json file which you can find in solution root directory and make sure that the target SDK version in it installed on your machine or update it to one you already have it installed for example if you have SDK version 2.1.4 installed your global.json should look like this

{
  "sdk":
  {
    "version": "2.1.400"
  }
}   
Drew Noakes
  • 300,895
  • 165
  • 679
  • 742
Smart Dev
  • 449
  • 5
  • 9
  • 1
    This was it for me. Version "2.1.300" in `global.json`, but `2.1.200` & `2.1.403` installed; changing to 2.1.400 worked. – Pasi Savolainen Oct 29 '18 at 08:33
  • 3
    Worked both changing it to one of installed versions of SDK or removing `version` attribute completely – Salaros Nov 16 '18 at 08:38
  • 2
    Worked for me as well. Changed the version to match the closest to what I already had on my system. You can run "dotnet --versions" to see what you have installed. – daudihus Dec 12 '18 at 03:02
  • 3
    `dotnet --list-sdks` and `dotnet --list-runtimes` to see all you have installed `dotnet --version` will show the current version in use. – nathanchere Dec 18 '18 at 08:13
  • I had ```"version": "2.1.403"``` in global.json with SDK 2.1.4 installed. ```"version": "2.1.400"``` didn't work for me. I had to get SDK 2.4.103. – Stephen Jun 25 '19 at 18:43
  • 1
    This was the solution for us as well. In our case, we had some projects on VS2017 with netcore 2.1; we installed netcore 3, and we could not open the projects any more. Creating global.json in the project's root folder solved the issue – Jack Casas Aug 18 '20 at 15:02
  • @Jack Cacas same as us... We have VS 2017 and VS 2019 running side by side. We needed to add a global.json file to our solution pointing to .NET Core 2.2.110. We then reloaded the project and all was well. Would be nice if you could do the global.json file at a project level though – Sethles Aug 19 '20 at 08:51
20

Resolved

  1. Even after uninstalling certain version from control panel, there would the files and folders with deleted version found in C:\Program Files\dotnet\sdk

  2. Please go and delete unwanted version folder

  3. Try reloading the project

This worked for me

jithin john
  • 552
  • 4
  • 12
19

Repairing last Core installation worked for me

Uzay
  • 809
  • 9
  • 18
  • 1
    I had to reboot as well but this fixed it for me. – DTown Jun 11 '18 at 12:49
  • 2
    For people looking "how" to repair the .NET Framework (works for Core too), search for ".NET Framework Repair Tool" in your favorite search engine. Running just the first step fixed it for me. – KSwift87 Jun 13 '18 at 18:00
  • 2
    also W10 Contol Panel - Programs- Programs and Features select installation and repair – Uzay Jun 14 '18 at 12:07
17

In my case, I had two versions of Visual Studio installed (15.7 and 15.6). 15.7 didn't have the web workloads installed, though .net core 2.1 RC1 was already installed. I installed the asp.net workload into VS2017, and then repaired my .net core install for good measure. Definitely something in this process swapped my c:\program files(x86)\dotnet and c"\program files\dotnet in this path and Visual Studio (15.7) wouldn't open my web project.

I simply edited the System Environment variables, moved the x86 folder down one and voila - reopened Visual Studio and it now loaded my project. System environment variables

Adam Tuliper
  • 29,982
  • 4
  • 53
  • 71
17

I solved this problem by modifying the first line in the .csproj file from:

<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">

to:

<Project Sdk="Microsoft.NET.Sdk">
codeDom
  • 1,623
  • 18
  • 54
15

Eh, rookie mistake, I had Visual Studio SSDT open and was trying to open an existing .Net Core project which produces the same error:

"Project file is incomplete. Expected imports are missing"

The solution was to use Visual Studio not SSDT, see in Help > About:

enter image description here

Jeremy Thompson
  • 61,933
  • 36
  • 195
  • 321
  • 1
    After hours of confusion over .net core versioning, this was the actual solution for me. And for me SSDT had become the default when opening a solution file from a folder, so I fixed that too. Thanks! – Alex Aug 07 '19 at 14:34
10

I have solved this problem a couple of times lately by closing Visual Studio and running the following commands

  1. dotnet nuget locals -c all
  2. dotnet clean
  3. dotnet build

There seems to be times, especially at the beginning of projects, when nuget gets out of whack (technical term).

Brett Bim
  • 3,190
  • 4
  • 28
  • 26
10

After installing VS2019 I started to have the same error when opening existing .Net Core solutions in VS2017.
In Visual Studio Installer I've updated VS2017 to the latest version (15.9.11) and the problem disappeared.

Later after upgrading VS2019 to the latest release I started to have the same errors and had to upgrade VS2017 again.

Michael Freidgeim
  • 26,542
  • 16
  • 152
  • 170
5

I started to get this error when unistalled all my old .NET Core SDKs and installed the latest one, 2.1.5 at the time of posting. I have tried all the solutions here without any luck so decided to check what is the current SDK version after all the cleaup I did because I thought this is causing the problem, and I was right - started a command prompt and wrote dotnet --version and got the message "Did you mean to run dotnet SDK commands? Please install dotnet SDK from:". Strange, the SDK is installed but the system doesn't see it. Then I looked in my environment variables and the PATH variable had the x86 for dotnet path before the regular Program Files (the x64 one) path. So I moved the x64 before the x86 and voila, everthing is back to normal.

Hope I helped someone.

Ivaylo
  • 467
  • 6
  • 19
  • You helped me. This just happened when I upgraded from 2.2.3 to 2.2.4. I wonder if there's a specific order of install new/uninstall old that causes it to happen. – MattOG Apr 11 '19 at 14:59
  • @MattOG, I have tried numerous variants for installing/uninstalling but this problem occurs every time. I guess will just have to get used to that ;) It's not a biggy after all when we have a source like stackoverflow. – Ivaylo Apr 11 '19 at 16:07
  • Is it the same as Smart Dev's answer [Project file is incomplete. Expected imports are missing](//stackoverflow.com/a/50461714) ? – Michael Freidgeim Apr 29 '19 at 04:49
4

I got the same issue. I could not create new ASP .Net Core 2 on fresh installed VS2017 or open existing one, which works perfectly on another computer with VS2017.

It's started work for me after uninstalling all .NET Core Runtimes and .NET Core Windows Server Hosting from Windows. SDKs have been left only and all works finally. enter image description here

Probably, I needed to uninstall just .NET Core Runtimes or .NET Core Windows Server Hosting from Windows and it would be enough.

Serg
  • 95
  • 8
  • I never had ASP Core 2 SDK installed on my machine, issue still present even after fresh installation – alelom May 10 '18 at 14:54
  • Worked for me. After uninstalling Core Windows Server Hosting. no restart of VS. I just reloaded the projects. – profimedica Nov 21 '18 at 08:18
4

The only thing that worked for me was to upgrade Visual studio:

enter image description here

enter image description here

Egon Allison
  • 1,329
  • 1
  • 13
  • 22
3

I had the same symptoms from a corrupted dotnet core SDK (from the command line I was unable to run dotnet -v, where previously I was able). My project failed to load after a failed IIS web platform installation failure. Reinstalling .NET core SDK resolved the issue.

lukace
  • 91
  • 1
  • 2
3

I had the same issue. took me quiet a while to figure it out. In my case, I was trying to open a new ASP .NET Core Application and I was getting back 0 Projects like the one on this post.

What I tried: I tried changing environmental variables under Control Panel\System and Security\System (click advance settings)

enter image description here

Then click Environmental Variables

enter image description here

Then check to see if you have dotnet path included, whether it is under Program Files or Program files (x86) enter image description here

Some people suggested to move (x86) up, which is based on microsoft documentation

What fixed my issue: Turns out I had the wrong version installed and it was not compatible with Visual Studio 2017 enter image description here

Then I removed the other installations and reinstalled the right version that is compatible with VS17 and works like a magic. Hope it helps someone in the future.

  • 2
    This was a portion of what worked for me. All other SDKs on my machine were 64bit (and thus in "Program Files".) I had to install the latest Core for VS 2017 - 2.2.110 as the x86 version. This goes into the "Program Files (x86)" tree. I removed the previously added PATH statements to the normal "Program Files" folder and replaced them with the "Program Files (x86)" and it works again! – Grandizer Jan 17 '20 at 13:47
  • This helped me! I uninstalled a bunch of sdk's that Windows 10 Insider Preview auto installed for me and accidentally removed the one VS 2017 needed. Thanks! – Jeff LaFay Mar 26 '20 at 14:57
2

in my case, I went to the folder C:\Program Files\dotnet\sdk delete the preview sdk folder, then on the command line run:

dotnet sdk 2.1.200

to set the correct sdk version for asp.net core. this fixed the problem.

koo9
  • 409
  • 5
  • 15
2

I had the same error message. In my case. I had to install the .NET Core cross-platform development toolset.

Steps:

  1. In Visual Studio, go to Tools > Get Tools and Features...
  2. Modify the installation under Workloads: select .NET Core cross-platform development and click Modify.
  3. Restart VS and rebuild your project.
victorlin
  • 638
  • 7
  • 14
1

Thanks guys, i had reinstall older version of visual studio 2017 and it works well. My VS version is 15.4 and it's fine

Majd Albaho
  • 1,311
  • 2
  • 10
  • 14
  • 7
    Version 15.6.7 here, and the issue is still present. I wouldn't mark this as an accepted answer as it isn't really a solution for the latest VS versions. – alelom May 10 '18 at 14:52
  • https://learn.microsoft.com/en-us/dotnet/core/windows-prerequisites?tabs=netcore2x#prerequisites-with-visual-studio-2017 required VS2017 is 15.9.0 – Griffin Apr 12 '19 at 17:06
1

This happened to me when I uninstalled a VS2015 instance of Visual Studio I had running side by side with VS2017.

I had to go out and reinstall the .Net Core sdk/runtime with the x86 version. I had already manually done the x64 versions of these but didn't think about visual studio running in 32bit.

These are the files:

  • dotnet-sdk-x.x.x-win-x86.exe

  • DotNetCore.x.x.x-WindowsHosting.exe

Felipe Augusto
  • 7,733
  • 10
  • 39
  • 73
Jason
  • 79
  • 8
1

Delete all build generated bin and obj folders. This worked for me after renaming project and trying to reload solution. Not really sure about the real cause of incompatible loading.

Antti
  • 1,029
  • 12
  • 15
1

I was facing the same issue. I was running my project on .Net core 2.2. I tried every single solution given here but nothing worked. I repaired my visual studio and it's working fine now.

Kinjal Parmar
  • 342
  • 1
  • 3
  • 17
1

I have resolved it by updating visual studio to 2017 version.

The actual problem was that .net core version was later than Visual Studio.

Go to Help> Check for update, update Visual Studio.

Asad ullah
  • 88
  • 7
0

I had the same problem with an ASP.net Core 2.0 project after I've installed the DotNetCore.2.0.5-WindowsHosting Framework on my development machine. I could solve this problem after I've deinstalled the WindowsHosting Framework and all .net Core packages. After this I've reinstalled the dotnet-sdk-2.1.200-win-x64 package and everything worked fine.

Peter H
  • 1
  • 1
0

Deleting the bin and obj folders for the project fixed this for me.

Foole
  • 4,754
  • 1
  • 26
  • 23
0

Same issue...took me a while to figure out. Since I was working on an ASP.NET Core project that targeted .NET Core 1.1, I thought I still needed the .NET Core 1.1 SDK installed. Since I had .NET Core SDK 2.1 installed too there was some sort of conflict and I couldn't open the project file. After uninstalling .NET Core 1.1 I was then able to open my project.

Lee Cordell
  • 276
  • 3
  • 9
0

Run dotnet restore on command line for the solution.

Tip. If you've uninstalled the latest .net core version let's say 2.1.403 and installed the previous one, ensure the 2.1.403 folder has been actually removed at the path

C:\Program Files\dotnet\sdk\

I had the issue due to there left an empty folder with 2.1.403

Artem Vertiy
  • 1,002
  • 15
  • 31
0

I get the same issue, and I run Visual with Administrator privilege again. This helps me to open project nomarlly.

hoanvd1210
  • 149
  • 5
  • 15
0

Turns out my project was dependent on another project in the solution, which had failed NuGet dependency issues, which in turn was because the Target Framework in the project properties was blank.

I opened the .csproj file to check the target framework, downloaded the target framework and chose "repair", then restarted Visual Studio and all good again!

SharpC
  • 6,974
  • 4
  • 45
  • 40
0

I just had the same issue while installing the new preview version of VS 2019. I fixed it by uninstalling the latest update which in turn uninstalled the most recent downloaded version of core. Which I belive caused the missmatch.

Johan
  • 11
  • 2
0

Solved for me updating Visual Studio 2017 to 15.9.11 (I can't remember the version that was failing). Maybe repairing Visual Studio would have worked too. Reparing .NET Core installation, and cleaning build artifacts and temporary files didn't solve it.

hectorct
  • 3,335
  • 1
  • 22
  • 40
0

Just need to cross check your project creation .net core library version with updated one.When you update core library it won't get updated into .csproj, either you need to update it manually or need to remove latest/updated core sdk file.

To check .net core version --fire command on cmd :- dotnet --version

Then check with installed library in Program and Features --Removing of latest library resolve the problem without change of single line

0

It seems that, visual studio is searching for right version of sdk. VS2017 does not support all version of sdk where as VS2019 supports. When you install VS2019 it always install latest version of sdk, which is not going to support by VS2017, which lids to this showing "Project file is incomplete. Expected imports are missing." and project become unavailable in vs2017 projects

.NET Core 2.2 sdk is supported by both VS2017 and VS2019.

Installation Steps:

1.Uninstall all previously installed sdk from control panel

2.delete sdk folder from "C:\Program Files\dotnet"

3.install .net core 2.2 sdk

4.check installed sdk by running dotnet --version on administrative command prompt (if it say dotnet not supported then update global.json file from C:\Windows\system32\global.json which pointing to right version of sdk)

enter image description here

5.restart the computer and reopen VS

List of sdk https://dotnet.microsoft.com/download/visual-studio-sdks