【发布时间】:2017-07-26 16:38:33
【问题描述】:
我一直在尝试使用 .NET Core CLI 工具学习 .NET Core 编程的基础知识。我下载了 .NET Core SDK for Windows 1.0.1 版,并按照下载页面 (https://www.microsoft.com/net/core#windows) 上的简单说明进行操作:
mkdir hwapp
cd hwapp
dotnet new
dotnet restore
dotnet run
这在我的 Windows 10 x64 机器上编译并运行良好。
当我尝试在同一个应用程序中定位 .NET Framework 4.6.2 时遇到了麻烦。根据我的阅读,我应该只需要在“框架”节点下添加一个值为“net462”的节点:
{
"net462": {}
}
然而,在添加此节点后,运行 dotnet restore 然后运行 dotnet build CLI 命令,我收到以下错误:
Project hwapp (.NETFramework,Version=v4.6.2) will be compiled because expected outputs are missing
Compiling hwapp for .NETFramework,Version=v4.6.2
C:\Program Files\dotnet\dotnet.exe compile-csc @C:\Development\dotNet\hwapp\obj\Debug\net462\dotnet-compile.rsp returned Exit Code 1
C:\Development\dotNet\hwapp\obj\Debug\net462\dotnet-compile.assemblyinfo.cs(2,11): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?)
C:\Development\dotNet\hwapp\obj\Debug\net462\dotnet-compile.assemblyinfo.cs(3,11): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?)
C:\Development\dotNet\hwapp\obj\Debug\net462\dotnet-compile.assemblyinfo.cs(4,11): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?)
C:\Development\dotNet\hwapp\obj\Debug\net462\dotnet-compile.assemblyinfo.cs(5,11): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?)
C:\Development\dotNet\hwapp\obj\Debug\net462\dotnet-compile.assemblyinfo.cs(2,58): error CS0518: Predefined type 'System.String' is not defined or imported
C:\Development\dotNet\hwapp\obj\Debug\net462\dotnet-compile.assemblyinfo.cs(3,54): error CS0518: Predefined type 'System.String' is not defined or imported
C:\Development\dotNet\hwapp\obj\Debug\net462\dotnet-compile.assemblyinfo.cs(4,67): error CS0518: Predefined type 'System.String' is not defined or imported
C:\Development\dotNet\hwapp\obj\Debug\net462\dotnet-compile.assemblyinfo.cs(5,62): error CS0518: Predefined type 'System.String' is not defined or imported
C:\Development\dotNet\hwapp\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:\Development\dotNet\hwapp\Program.cs(5,18): error CS0518: Predefined type 'System.Object' is not defined or imported
C:\Development\dotNet\hwapp\Program.cs(7,33): error CS0518: Predefined type 'System.String' is not defined or imported
C:\Development\dotNet\hwapp\Program.cs(7,23): error CS0518: Predefined type 'System.Void' is not defined or imported
Compilation failed.
0 Warning(s)
12 Error(s)
从输出中可以看出,当面向 .NET Framework 4.6.2 时,编译器似乎无法找到 System 命名空间。当我尝试针对早期的 .NET 框架(如 4.6.1 和 4.5.2)时,也会出现同样的错误。
我尝试将 x64 版本的 System.dll 和 mscorlib.dll 的副本从 GAC 移动到 C:\Program Files\dotnet\ 目录,以便 csc.exe 程序无法成功找到 System 命名空间.
如果有帮助,请在下面找到我的 project.json 文件的内容:
{
"version": "1.0.0-*",
"buildOptions": {
"debugType": "portable",
"emitEntryPoint": true
},
"dependencies": {},
"frameworks": {
"net462": {},
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.1"
}
},
"imports": "dnxcore50"
}
}
}
任何帮助将不胜感激!
【问题讨论】:
-
您的 project.json 适合我。你有.NET Framework 4.6.2 Developer Pack 安装吗?
-
安装 .NET Framework 4.6.2 开发包解决了这个问题!谢谢@svick!
标签: .net .net-core .net-framework-version