我一直在尝试使用.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时遇到了麻烦。根据我的阅读,我只需添加一个值为" net462"在"框架下"节点:
{
"net462": {}
}
然而,在添加此节点,运行dotnet还原,然后运行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)时,会出现同样的错误。
我尝试将G64版本的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"
}
}
}
非常感谢任何帮助!