After creating a .NET Core project or opening an existing one I was getting the error:
“Project file is incomplete. Expected imports are missing.“
There are tons of places on the web talking about this error. Sometimes it is simply because you are opening a project that was built with a version of .NET Core that you do not have installed.
In my scenario, it was a clean install of Visual Studio 2017. I could create any type of project, even a .NET Core console app. If I tried to create a Web app it would just create the project and end up with an empty solution.
Try to load just the project file and it would show the above error.
Things I tried
- Un-installing Visual Studio 2017 and Re-installing
- Deleting all folders from %APPDATA% that reference Visual Studio and then do a re-install
- Un-Installing all version of .NET Core and Re-installing
- Deleting dotnet folder from C:\Program Files and C:\Program Files (x86) and then doing a re-install
- Un-installing all previous versions of Visual Studio (Regret this one now)
- Running the Visual Studio 2017 repair install
- Trying Visual Studio 2017 Community instead of Professional
- Adding a Globals.json file and making sure it pointed to a version of dotnet I have installed.
- At command prompt, typing dotnet –list-sdks and verifying I had versions installed other than preview
- In Visual Studio, going to Tootsà Options à Projects and Solutions à .NET Core and checking the Use previews of the .NET Core SDK checkbox.
The fix for me was turned out to be quite simple. It was the dotnet folder not being in the environment variable path property for my user.
That is the key issue. The System path variable looked right but did not work.
Go to Control Panel > System > Advanced system settings > Environment Variables
In the top area under User variables for Your User Name, select Path and then click edit.
If your .NET Core installs are X64 then add the following:
- Add C:\Program Files\dotnet\sdk
- Add C:\Program Files\dotnet
If your .NET Core installs are x86 then add the following:
- C:\Program Files (x86)\dotnet\sdk
- C:\Program Files (x86)\dotnet
Reboot and hopefully your issues are resolved.