简体   繁体   English

在.Net Core控制台应用程序中找不到依赖项-在启动时显示为丢失

[英]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). 我无法从头开始构建任何.Net Core 2.1控制台应用程序(或者与此相关的任何一种.Net Core / ASP.Net Core应用程序)。 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. 尝试构建后,我还在下面列出了“ dotnet --info”命令以及“输出”窗口。 I cannot for the life of me figure out why my machine is not finding the Nuget packages/references on my machine. 我一辈子都无法弄清楚为什么我的机器在我的机器上找不到Nuget软件包/引用。 I really appreciate any help. 我非常感谢您的帮助。 I've tried many things like issuing a "dotnet restore" command. 我已经尝试了很多事情,例如发出“ dotnet restore”命令。 Deleting the NugetPackageFallBack folder, reparing Visual Studio and getting all updates. 删除NugetPackageFallBack文件夹,修复Visual Studio并获取所有更新。 I'm using Visual Studio 15.7.4 on a Windows 10 machine x64. 我在Windows 10计算机x64上使用Visual Studio 15.7.4。

Output of " dotnet --info " 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. 我的工作项目突然间缺少了nuget包。 I tried all the suggestions above eg delete NugetFallBack Folder, clean solution, dotnet restore, etc. None worked. 我尝试了上述所有建议,例如删除NugetFallBack文件夹,干净的解决方案,dotnet还原等。没有任何效果。 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. 对我而言,解决此问题的原因是在管理模式下打开Visual Studio。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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