繁体   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