我一直在尝试使用.NET Core CLI工具学习.NET Core编程的基础知识。我下载了Windows版本1.0.1的.NET Core SDK,并按照下载页面(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时,遇到了问题。从我所读的资料来看,我只需要在“frameworks”节点下添加一个值为"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命名空间。尝试将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"
}
}
}
任何帮助都将不胜感激!