Project file is incomplete. Expected imports are m

2020-02-02 06:20发布

问题:

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?

回答1:

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



回答2:

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



回答3:

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.



回答4:

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"
  }
}   


回答5:

Repairing last Core installation worked for me



回答6:

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.



回答7:

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:



回答8:

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).



回答9:

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.



回答10:

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.



回答11:

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.

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



回答12:

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



回答13:

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.



回答14:

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.



回答15:

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">


回答16:

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)

Then click Environmental Variables

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

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

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.



回答17:

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



回答18:

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



回答19:

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.



回答20:

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.


回答21:

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.



回答22:

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.



回答23:

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



回答24:

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.



回答25:

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



回答26:

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.



回答27:

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



回答28:

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!



回答29:

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.



回答30:

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