史坑:.Net core 2.0 编译失败

Net core 2.0 生成的包文件更少,大小也更小了。同一个项目 1.1  是约21M;2.0是 2.4M.

愉快地使用一天之后。VS2017 突然识别不到 .NET core 2.0 。更新修复后,可识别,但有编译时出现头痛错误。无论是VS2017 还是 命令行:

 

 

生成失败。请修复生成错误并重新运行。

各种尝试,无解....................

 

解决过程:

0.在VS2017中清空nuget 缓存

1.删除已安装的.net core 2.0

2.下载压缩版本的.net core 2.0,设置好系统变量

3.创建新项目

dotnet new console -o -haapp

cd haapp

dotnet restore

dotnet run 

输出:Hello World! 能够正确运行

(VS 新建也正常)

4.运行之前报错的项目console-app

依然报以上错误

(VS编译也报以上错误)

5.将项目拷贝出来,并删除之前的 .vs bin obj 三个文件夹.重新执行 dotnet run 

编译成出输出Hello World!

 

问题无意中解决!

初步估计:系统某个时期痴线生成问题项目有缓存?

 

继续...............

7.直接在拷贝出来的项目文件夹执行:dotnet run 


C:\Users\Yu-we\Desktop\app>dotnet run
C:\Users\Yu-we\AppData\Local\Temp\.NETCoreApp,Version=v2.0.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:\Users\Yu-we\Desktop\app\console-app.csproj]
obj\Debug\netcoreapp2.0\console-app.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:\Users\Yu-we\Desktop\app\console-app.csproj]
obj\Debug\netcoreapp2.0\console-app.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:\Users\Yu-we\Desktop\app\console-app.csproj]
obj\Debug\netcoreapp2.0\console-app.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:\Users\Yu-we\Desktop\app\console-app.csproj]
obj\Debug\netcoreapp2.0\console-app.AssemblyInfo.cs(17,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\Yu-we\Desktop\app\console-app.csproj]
obj\Debug\netcoreapp2.0\console-app.AssemblyInfo.cs(18,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\Yu-we\Desktop\app\console-app.csproj]
obj\Debug\netcoreapp2.0\console-app.AssemblyInfo.cs(19,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\Yu-we\Desktop\app\console-app.csproj]
obj\Debug\netcoreapp2.0\console-app.AssemblyInfo.cs(20,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\Yu-we\Desktop\app\console-app.csproj]
obj\Debug\netcoreapp2.0\console-app.AssemblyInfo.cs(21,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\Yu-we\Desktop\app\console-app.csproj]
C:\Users\Yu-we\AppData\Local\Temp\.NETCoreApp,Version=v2.0.AssemblyAttributes.cs(4,71): error CS0518: Predefined type 'System.String' is not defined or imported [C:\Users\Yu-we\Desktop\app\console-app.csproj]
C:\Users\Yu-we\AppData\Local\Temp\.NETCoreApp,Version=v2.0.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:\Users\Yu-we\Desktop\app\console-app.csproj]
C:\Users\Yu-we\AppData\Local\Temp\.NETCoreApp,Version=v2.0.AssemblyAttributes.cs(4,122): error CS0518: Predefined type 'System.String' is not defined or imported [C:\Users\Yu-we\Desktop\app\console-app.csproj]
obj\Debug\netcoreapp2.0\console-app.AssemblyInfo.cs(14,55): error CS0518: Predefined type 'System.String' is not defined or imported [C:\Users\Yu-we\Desktop\app\console-app.csproj]
obj\Debug\netcoreapp2.0\console-app.AssemblyInfo.cs(15,61): error CS0518: Predefined type 'System.String' is not defined or imported [C:\Users\Yu-we\Desktop\app\console-app.csproj]
obj\Debug\netcoreapp2.0\console-app.AssemblyInfo.cs(16,59): error CS0518: Predefined type 'System.String' is not defined or imported [C:\Users\Yu-we\Desktop\app\console-app.csproj]
obj\Debug\netcoreapp2.0\console-app.AssemblyInfo.cs(17,59): error CS0518: Predefined type 'System.String' is not defined or imported [C:\Users\Yu-we\Desktop\app\console-app.csproj]
obj\Debug\netcoreapp2.0\console-app.AssemblyInfo.cs(18,68): error CS0518: Predefined type 'System.String' is not defined or imported [C:\Users\Yu-we\Desktop\app\console-app.csproj]
obj\Debug\netcoreapp2.0\console-app.AssemblyInfo.cs(19,55): error CS0518: Predefined type 'System.String' is not defined or imported [C:\Users\Yu-we\Desktop\app\console-app.csproj]
obj\Debug\netcoreapp2.0\console-app.AssemblyInfo.cs(20,53): error CS0518: Predefined type 'System.String' is not defined or imported [C:\Users\Yu-we\Desktop\app\console-app.csproj]
obj\Debug\netcoreapp2.0\console-app.AssemblyInfo.cs(21,55): error CS0518: Predefined type 'System.String' is not defined or imported [C:\Users\Yu-we\Desktop\app\console-app.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:\Users\Yu-we\Desktop\app\console-app.csproj]
C:\Users\Yu-we\AppData\Local\Temp\.NETCoreApp,Version=v2.0.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:\Users\Yu-we\Desktop\app\console-app.csproj]
C:\Users\Yu-we\AppData\Local\Temp\.NETCoreApp,Version=v2.0.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:\Users\Yu-we\Desktop\app\console-app.csproj]
obj\Debug\netcoreapp2.0\console-app.AssemblyInfo.cs(11,7): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\Yu-we\Desktop\app\console-app.csproj]
obj\Debug\netcoreapp2.0\console-app.AssemblyInfo.cs(12,7): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\Yu-we\Desktop\app\console-app.csproj]
Program.cs(5,11): error CS0518: Predefined type 'System.Object' is not defined or imported [C:\Users\Yu-we\Desktop\app\console-app.csproj]
Program.cs(7,26): error CS0518: Predefined type 'System.String' is not defined or imported [C:\Users\Yu-we\Desktop\app\console-app.csproj]
Program.cs(7,16): error CS0518: Predefined type 'System.Void' is not defined or imported [C:\Users\Yu-we\Desktop\app\console-app.csproj]

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

C:\Users\Yu-we\Desktop\app>

 

完美重现

 

8.逐个文件夹删除

发现删除obj文件夹后可正常编译

 

 

----------------------------------

By the way:

代码中不要引入未使用的命令空间,会更加打包出来的项目大小,即使,代码中没有使用。

 

posted on 2017-09-13 23:41  Yu-weiz  阅读(930)  评论(0编辑  收藏  举报

导航