简体   繁体   English

无法构建.Net core 2.2项目? 找不到类型或名称空间名称“系统”

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

I just install the newest .Net core at this moment. 我现在仅安装最新的.Net内核。

PS C:\temp> dotnet --version
2.2.301

And I created a new console project. 我创建了一个新的控制台项目。

PS C:\temp> dotnet new console

Welcome to .NET Core! 欢迎使用.NET Core!

Learn more about .NET Core: https://aka.ms/dotnet-docs Use 'dotnet --help' to see available commands or visit: https://aka.ms/dotnet-cli-docs 了解有关.NET Core的更多信息: https : //aka.ms/dotnet-docs使用'dotnet --help'查看可用命令或访问: https : //aka.ms/dotnet-cli-docs

Telemetry 遥测

The .NET Core tools collect usage data in order to help us improve your experience. .NET Core工具收集使用情况数据,以帮助我们改善您的体验。 The data is anonymous and doesn't include command-line arguments. 数据是匿名的,不包含命令行参数。 The data is collected by Microsoft and shared with the community. 数据由Microsoft收集并与社区共享。 You can opt-out of telemetry by setting the DOTNET_CLI_TELEMETRY_OPTOUT environment variable to '1' or 'true' using your favorite shell. 您可以使用自己喜欢的外壳程序,通过将DOTNET_CLI_TELEMETRY_OPTOUT环境变量设置为“ 1”或“ true”,选择退出遥测。

Read more about .NET Core CLI Tools telemetry: https://aka.ms/dotnet-cli-telemetry 阅读有关.NET Core CLI工具遥测的更多信息: https : //aka.ms/dotnet-cli-telemetry

ASP.NET Core ASP.NET核心

Successfully installed the ASP.NET Core HTTPS Development Certificate. 成功安装了ASP.NET Core HTTPS开发证书。 To trust the certificate run 'dotnet dev-certs https --trust' (Windows and macOS only). 要信任证书,请运行“ dotnet dev-certs https --trust”(仅限Windows和macOS)。 For establishing trust on other platforms refer to the platform specific documentation. 要在其他平台上建立信任,请参阅平台特定的文档。 For more information on configuring HTTPS see https://go.microsoft.com/fwlink/?linkid=848054 . 有关配置HTTPS的更多信息,请参见https://go.microsoft.com/fwlink/?linkid=848054 Getting ready... The template "Console Application" was created successfully. 准备...模板“控制台应用程序”已成功创建。

Processing post-creation actions... Running 'dotnet restore' on C:\\temp\\temp.csproj... Restore completed in 190.58 ms for C:\\temp\\temp.csproj. 正在处理创建后的操作...在C:\\ temp \\ temp.csproj上运行“ dotnet restore” ... C:\\ temp \\ temp.csproj的还原在190.58毫秒内完成。

Restore succeeded. 恢复成功。


However, dotnet run got the following error? 但是, 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.

Running dotnet restore didn't get any error. 运行dotnet restore没有任何错误。

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

I tried "deleting the C:\\Program Files\\dotnet\\sdk\\NuGetFallbackFolder" ( https://github.com/dotnet/core/issues/1006 ) but it still didn't resolve the issue. 我尝试“删除C:\\ Program Files \\ dotnet \\ sdk \\ NuGetFallbackFolder”( https://github.com/dotnet/core/issues/1006 ),但仍然无法解决问题。

However, in visual studio, the project compiles and runs after I switch the .net core version of the project to 2.1 . 但是,在Visual Studio中,我将项目的.net核心版本切换为2.1后 ,该项目才能编译并运行。

Try to run: 尝试运行:

dotnet restore

Then it should work, or at least give you information about the reason why the dependencies cannot be resolved. 然后它应该起作用,或者至少为您提供有关无法解决依赖关系的原因的信息。

In the command prompt you can write: dotnet --version and you will see your current version. 在命令提示符下,您可以编写:dotnet --version,您将看到当前版本。 I recommend you download the core framework from here instead of installing through the visual studio installer. 我建议您从此处下载核心框架,而不要通过Visual Studio安装程序进行安装。 Installing .net core from the site fixed my problems. 从站点安装.net core解决了我的问题。

The problem is gone today. 这个问题今天消失了。 I tried to install the newest .Net core SDK and it still didn't resolve the problem. 我尝试安装最新的.Net核心SDK,但仍然无法解决问题。

Then I launched VS 2019 and created a new .Net core project in VS. 然后我启动了VS 2019,并在VS中创建了一个新的.Net核心项目。 And it compiles. 并编译。 And I go back to the powershell and found out dotnet run works now. 我回到Powershell,发现dotnet run现在dotnet run工作了。

暂无
暂无

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

相关问题 将 .Net Core 项目从 3.1 降级到 2.2 - 找不到类型或命名空间名称“IWebHostEnvironment” - Downgrade .Net Core project from 3.1 to 2.2 - The type or namespace name 'IWebHostEnvironment' could not be found Visual Studio Code Do.net Core C# 错误:“找不到类型或命名空间名称‘System’”,但构建成功 - Error in Visual Studio Code Dotnet Core C#: "The type or namespace name 'System' could not be found", but build succeeds 在 asp.net core 2.2 中找不到类型或命名空间名称“Worker”(您是否缺少 using 指令或程序集引用?)? - The type or namespace name 'Worker' could not be found (are you missing a using directive or an assembly reference?) in asp.net core 2.2? 在.Net Core应用中找不到类型或名称空间“系统” - The type or namespace 'system' could not be found in .Net Core app Net Core:找不到类型或命名空间名称“RoleProvider” - Net Core: Type or namespace name 'RoleProvider' could not be found 网络核心:找不到类型或名称空间名称“ GlobalFilterCollection” - Net Core: Type or namespace name 'GlobalFilterCollection' could not be found .net 核心 2.2 中的命名空间“System.web”中不存在类型或命名空间名称“HttpBrowserCapabilitiesBase” - the type or namespace name 'HttpBrowserCapabilitiesBase' does not exist in the namespace 'System.web' in .net core 2.2 找不到类型或命名空间名称“System”和“Xamarin” - The type or namespace name 'System' and 'Xamarin' could not be found 找不到类型或命名空间名称“系统” - The type or namespace name 'System' could not be found 在'system'中找不到类型或命名空间名称'linq' - the type or namespace name 'linq' could not be found in 'system'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM