簡體   English   中英

無法構建.Net core 2.2項目? 找不到類型或名稱空間名稱“系統”

[英]Cannot build .Net core 2.2 project? The type or namespace name 'System' could not be found

我現在僅安裝最新的.Net內核。

PS C:\temp> dotnet --version
2.2.301

我創建了一個新的控制台項目。

PS C:\temp> dotnet new console

歡迎使用.NET Core!

了解有關.NET Core的更多信息: https : //aka.ms/dotnet-docs使用'dotnet --help'查看可用命令或訪問: https : //aka.ms/dotnet-cli-docs

遙測

.NET Core工具收集使用情況數據,以幫助我們改善您的體驗。 數據是匿名的,不包含命令行參數。 數據由Microsoft收集並與社區共享。 您可以使用自己喜歡的外殼程序,通過將DOTNET_CLI_TELEMETRY_OPTOUT環境變量設置為“ 1”或“ true”,選擇退出遙測。

閱讀有關.NET Core CLI工具遙測的更多信息: https : //aka.ms/dotnet-cli-telemetry

ASP.NET核心

成功安裝了ASP.NET Core HTTPS開發證書。 要信任證書,請運行“ dotnet dev-certs https --trust”(僅限Windows和macOS)。 要在其他平台上建立信任,請參閱平台特定的文檔。 有關配置HTTPS的更多信息,請參見https://go.microsoft.com/fwlink/?linkid=848054 准備...模板“控制台應用程序”已成功創建。

正在處理創建后的操作...在C:\\ temp \\ temp.csproj上運行“ dotnet restore” ... C:\\ temp \\ temp.csproj的還原在190.58毫秒內完成。

恢復成功。


但是, dotnet run出現以下錯誤?

PS C:\temp> dotnet run
C:\Users\wangyi\AppData\Local\Temp\1\.NETCoreApp,Version=v2.2.AssemblyAttributes.cs(4,20): error CS0400: The type or namespace name 'System' could not be found in the global namespace (are you missing an assembly reference?) [C:\temp\temp.csproj]
obj\Debug\netcoreapp2.2\temp.AssemblyInfo.cs(10,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\temp\temp.csproj]
obj\Debug\netcoreapp2.2\temp.AssemblyInfo.cs(11,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\temp\temp.csproj]
obj\Debug\netcoreapp2.2\temp.AssemblyInfo.cs(12,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\temp\temp.csproj]
obj\Debug\netcoreapp2.2\temp.AssemblyInfo.cs(13,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\temp\temp.csproj]
obj\Debug\netcoreapp2.2\temp.AssemblyInfo.cs(14,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\temp\temp.csproj]
obj\Debug\netcoreapp2.2\temp.AssemblyInfo.cs(15,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\temp\temp.csproj]
obj\Debug\netcoreapp2.2\temp.AssemblyInfo.cs(16,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\temp\temp.csproj]
C:\Users\wangyi\AppData\Local\Temp\1\.NETCoreApp,Version=v2.2.AssemblyAttributes.cs(4,71): error CS0518: Predefined type 'System.String' is not defined or imported [C:\temp\temp.csproj]
C:\Users\wangyi\AppData\Local\Temp\1\.NETCoreApp,Version=v2.2.AssemblyAttributes.cs(4,99): error CS0246: The type or namespace name 'FrameworkDisplayName' could not be found (are you missing a using directive or an assembly reference?) [C:\temp\temp.csproj]
C:\Users\wangyi\AppData\Local\Temp\1\.NETCoreApp,Version=v2.2.AssemblyAttributes.cs(4,122): error CS0518: Predefined type 'System.String' is not defined or imported [C:\temp\temp.csproj]
obj\Debug\netcoreapp2.2\temp.AssemblyInfo.cs(10,55): error CS0518: Predefined type 'System.String' is not defined or imported [C:\temp\temp.csproj]
obj\Debug\netcoreapp2.2\temp.AssemblyInfo.cs(11,61): error CS0518: Predefined type 'System.String' is not defined or imported [C:\temp\temp.csproj]
obj\Debug\netcoreapp2.2\temp.AssemblyInfo.cs(12,59): error CS0518: Predefined type 'System.String' is not defined or imported [C:\temp\temp.csproj]
obj\Debug\netcoreapp2.2\temp.AssemblyInfo.cs(13,68): error CS0518: Predefined type 'System.String' is not defined or imported [C:\temp\temp.csproj]
obj\Debug\netcoreapp2.2\temp.AssemblyInfo.cs(14,55): error CS0518: Predefined type 'System.String' is not defined or imported [C:\temp\temp.csproj]
obj\Debug\netcoreapp2.2\temp.AssemblyInfo.cs(15,53): error CS0518: Predefined type 'System.String' is not defined or imported [C:\temp\temp.csproj]
obj\Debug\netcoreapp2.2\temp.AssemblyInfo.cs(16,55): error CS0518: Predefined type 'System.String' is not defined or imported [C:\temp\temp.csproj]
Program.cs(1,7): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\temp\temp.csproj]
C:\Users\wangyi\AppData\Local\Temp\1\.NETCoreApp,Version=v2.2.AssemblyAttributes.cs(2,7): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\temp\temp.csproj]
C:\Users\wangyi\AppData\Local\Temp\1\.NETCoreApp,Version=v2.2.AssemblyAttributes.cs(3,7): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\temp\temp.csproj]
obj\Debug\netcoreapp2.2\temp.AssemblyInfo.cs(7,7): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\temp\temp.csproj]
obj\Debug\netcoreapp2.2\temp.AssemblyInfo.cs(8,7): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\temp\temp.csproj]
Program.cs(5,11): error CS0518: Predefined type 'System.Object' is not defined or imported [C:\temp\temp.csproj]
Program.cs(7,26): error CS0518: Predefined type 'System.String' is not defined or imported [C:\temp\temp.csproj]
Program.cs(7,16): error CS0518: Predefined type 'System.Void' is not defined or imported [C:\temp\temp.csproj]

The build failed. Please fix the build errors and run again.

運行dotnet restore沒有任何錯誤。

PS C:\temp> dotnet restore
Restore completed in 41.15 ms for C:\temp\temp.csproj.

我嘗試“刪除C:\\ Program Files \\ dotnet \\ sdk \\ NuGetFallbackFolder”( https://github.com/dotnet/core/issues/1006 ),但仍然無法解決問題。

但是,在Visual Studio中,我將項目的.net核心版本切換為2.1后 ,該項目才能編譯並運行。

嘗試運行:

dotnet restore

然后它應該起作用,或者至少為您提供有關無法解決依賴關系的原因的信息。

在命令提示符下,您可以編寫:dotnet --version,您將看到當前版本。 我建議您從此處下載核心框架,而不要通過Visual Studio安裝程序進行安裝。 從站點安裝.net core解決了我的問題。

這個問題今天消失了。 我嘗試安裝最新的.Net核心SDK,但仍然無法解決問題。

然后我啟動了VS 2019,並在VS中創建了一個新的.Net核心項目。 並編譯。 我回到Powershell,發現dotnet run現在dotnet run工作了。

暫無
暫無

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

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