构建针对完整 .NET Framework 4.6.2 的默认 .NET Core 控制台应用程序时出错

Error in building default .NET Core console application targeting the full .NET framework 4.6.2

我一直在尝试使用 .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 为目标时,编译器似乎无法找到系统命名空间。当我尝试定位早期的 .NET Frameworks(如 4.6.1 和 4.5.2)时出现同样的错误。

我尝试将 System.dll 和 mscorlib.dll 的 x64 版本的副本从 GAC 移动到 C:\Program Files\dotnet\ 目录,以便 csc.exe 程序可以找到系统命名空间但没有成功。

如果有帮助,请在下面找到我的 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"
    }
  }
}

如有任何帮助,我们将不胜感激!

如果您想要以 .Net 4.6.2 为目标,您需要安装 .NET Framework 4.6.2 Developer Pack