简体   繁体   中英

Dependencies not found in .Net Core console application - showing as missing on startup

I'm having trouble getting any .Net Core 2.1 console application to build from scratch (or any kind of .Net Core/ASP.Net Core application for that matter). I posted a screenshot below that shows the errors (missing dependencies/references) and circled the Dependencies in the Solution Explorer as there's a yellow exclamation. I've also listed the "dotnet --info" command below as well as the "Output" window after trying to build. I cannot for the life of me figure out why my machine is not finding the Nuget packages/references on my machine. I really appreciate any help. I've tried many things like issuing a "dotnet restore" command. Deleting the NugetPackageFallBack folder, reparing Visual Studio and getting all updates. I'm using Visual Studio 15.7.4 on a Windows 10 machine x64.

Output of " dotnet --info "

C:\Projects\JDB_POC>dotnet --info
.NET Core SDK (reflecting any global.json):
 Version:   2.1.300
 Commit:    adab45bf0c

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.14393
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\2.1.300\

Host (useful for support):
  Version: 2.1.0
  Commit:  caa7b7e2ba

.NET Core SDKs installed:
  1.0.4 [C:\Program Files\dotnet\sdk]
  2.1.201 [C:\Program Files\dotnet\sdk]
  2.1.300 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 1.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 1.1.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.0.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download

Notice the yellow exclamation around the dependencies in the Solution Explorer

Output from the Output window:

1>C:\Users\RossJ\AppData\Local\Temp\.NETCoreApp,Version=v2.1.AssemblyAttributes.cs(4,20,4,26): error CS0400: The type or namespace name 'System' could not be found in the global namespace (are you missing an assembly reference?)
1>obj\Debug\netcoreapp2.1\ConsoleApp4.AssemblyInfo.cs(14,12,14,18): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?)
1>obj\Debug\netcoreapp2.1\ConsoleApp4.AssemblyInfo.cs(15,12,15,18): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?)
1>obj\Debug\netcoreapp2.1\ConsoleApp4.AssemblyInfo.cs(16,12,16,18): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?)
1>obj\Debug\netcoreapp2.1\ConsoleApp4.AssemblyInfo.cs(17,12,17,18): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?)
1>obj\Debug\netcoreapp2.1\ConsoleApp4.AssemblyInfo.cs(18,12,18,18): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?)
1>obj\Debug\netcoreapp2.1\ConsoleApp4.AssemblyInfo.cs(19,12,19,18): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?)
1>obj\Debug\netcoreapp2.1\ConsoleApp4.AssemblyInfo.cs(20,12,20,18): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?)
1>C:\Users\RossJ\AppData\Local\Temp\.NETCoreApp,Version=v2.1.AssemblyAttributes.cs(4,71,4,97): error CS0518: Predefined type 'System.String' is not defined or imported
1>C:\Users\RossJ\AppData\Local\Temp\.NETCoreApp,Version=v2.1.AssemblyAttributes.cs(4,99,4,119): error CS0246: The type or namespace name 'FrameworkDisplayName' could not be found (are you missing a using directive or an assembly reference?)
1>C:\Users\RossJ\AppData\Local\Temp\.NETCoreApp,Version=v2.1.AssemblyAttributes.cs(4,122,4,124): error CS0518: Predefined type 'System.String' is not defined or imported
1>obj\Debug\netcoreapp2.1\ConsoleApp4.AssemblyInfo.cs(14,55,14,68): error CS0518: Predefined type 'System.String' is not defined or imported
1>obj\Debug\netcoreapp2.1\ConsoleApp4.AssemblyInfo.cs(15,61,15,68): error CS0518: Predefined type 'System.String' is not defined or imported
1>obj\Debug\netcoreapp2.1\ConsoleApp4.AssemblyInfo.cs(16,59,16,68): error CS0518: Predefined type 'System.String' is not defined or imported
1>obj\Debug\netcoreapp2.1\ConsoleApp4.AssemblyInfo.cs(17,68,17,75): error CS0518: Predefined type 'System.String' is not defined or imported
1>obj\Debug\netcoreapp2.1\ConsoleApp4.AssemblyInfo.cs(18,55,18,68): error CS0518: Predefined type 'System.String' is not defined or imported
1>obj\Debug\netcoreapp2.1\ConsoleApp4.AssemblyInfo.cs(19,53,19,66): error CS0518: Predefined type 'System.String' is not defined or imported
1>obj\Debug\netcoreapp2.1\ConsoleApp4.AssemblyInfo.cs(20,55,20,64): error CS0518: Predefined type 'System.String' is not defined or imported
1>Program.cs(1,7,1,13): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?)
1>C:\Users\RossJ\AppData\Local\Temp\.NETCoreApp,Version=v2.1.AssemblyAttributes.cs(2,7,2,13): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?)
1>C:\Users\RossJ\AppData\Local\Temp\.NETCoreApp,Version=v2.1.AssemblyAttributes.cs(3,7,3,13): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?)
1>obj\Debug\netcoreapp2.1\ConsoleApp4.AssemblyInfo.cs(11,7,11,13): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?)
1>obj\Debug\netcoreapp2.1\ConsoleApp4.AssemblyInfo.cs(12,7,12,13): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?)
1>Program.cs(5,11,5,18): error CS0518: Predefined type 'System.Object' is not defined or imported
1>Program.cs(7,26,7,32): error CS0518: Predefined type 'System.String' is not defined or imported
1>Program.cs(7,16,7,20): error CS0518: Predefined type '

I had a similar issue to this. My working project all of a sudden had missing nuget packages. I tried all the suggestions above eg delete NugetFallBack Folder, clean solution, dotnet restore, etc. None worked. I tried creating a new project from scratch and it was missing packages on creation.

What fixed the issue for me was opening Visual Studio in Admin mode.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM