簡體   English   中英

在.Net Core控制台應用程序中找不到依賴項-在啟動時顯示為丟失

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

我無法從頭開始構建任何.Net Core 2.1控制台應用程序(或者與此相關的任何一種.Net Core / ASP.Net Core應用程序)。 我在下面發布了一個屏幕截圖,顯示了錯誤(缺少依賴關系/引用),並在解決方案資源管理器中圈出了依賴關系,因為有一個黃色的驚嘆號。 嘗試構建后,我還在下面列出了“ dotnet --info”命令以及“輸出”窗口。 我一輩子都無法弄清楚為什么我的機器在我的機器上找不到Nuget軟件包/引用。 我非常感謝您的幫助。 我已經嘗試了很多事情,例如發出“ dotnet restore”命令。 刪除NugetPackageFallBack文件夾,修復Visual Studio並獲取所有更新。 我在Windows 10計算機x64上使用Visual Studio 15.7.4。

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

注意解決方案資源管理器中依賴項周圍的黃色驚嘆號

從“輸出”窗口中輸出:

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 '

我有與此類似的問題。 我的工作項目突然間缺少了nuget包。 我嘗試了上述所有建議,例如刪除NugetFallBack文件夾,干凈的解決方案,dotnet還原等。沒有任何效果。 我嘗試從頭開始創建一個新項目,但創建時缺少包。

對我而言,解決此問題的原因是在管理模式下打開Visual Studio。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM