project.json 的 .Net 控制台应用程序:类型在未引用的程序集中定义

.Net console application with project.json: Type is defined in an assembly that is not referenced

我正在尝试创建一个具有 project.json 结构的简单 .Net 控制台应用程序,使用 VS2015 选项控制台应用程序(包),使用外部 NuGet 包,但出现引用错误。

Program.cs:

using System.Net.Http;
using System.Threading.Tasks;
using Nito.AsyncEx;

namespace AsyncTest
{
    public class Program
    {
        public static void Main(string[] args)
        {
            AsyncContext.Run(() => MainAsync(args));
        }

        public static async void MainAsync(string[] args)
        {
            var urlContents = await AccessTheWebAsync();
        }

        static async Task<int> AccessTheWebAsync()
        {
            HttpClient client = new HttpClient();

            Task<string> getStringTask = client.GetStringAsync("http://msdn.microsoft.com");

            string urlContents = await getStringTask;

            return urlContents.Length;
        }

    }
}

project.json:

{
  "version": "1.0.0-*",
  "description": "AsyncTest Console Application",
  "authors": [ "ricsmania" ],
  "tags": [ "" ],
  "projectUrl": "",
  "licenseUrl": "",

  "compilationOptions": {
    "emitEntryPoint": true
  },

  "dependencies": {
    "Nito.AsyncEx": "3.0.1"
  },

  "commands": {
    "AsyncTest": "AsyncTest"
  },

  "frameworks": {
    "dnx451": {
      "dependencies": {
        "Microsoft.Net.Http": "2.2.22",
        "System.Runtime": "4.0.0"
      }
    }
  }
}

错误:

DNX 4.5.1 error CS0012: The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
DNX 4.5.1 error CS0012: The type 'Action' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
DNX 4.5.1 error CS0012: The type 'Func<>' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

如果我创建一个 "traditional" 控制台应用程序而不使用 project.json 使用完全相同的 Program.cs 代码它工作正常。

环境:

Windows 10 Pro
Visual Studio 2015 Professional 14.0.25123.00 Update 2
.Net 4.6.1
DNX 1.0.0-rc2-20221

编辑:我尝试恢复包和 clean/rebuild,并从头开始创建项目,但这些都没有帮助。

我是不是做错了什么或者这是一个错误?

我找到了解决办法。我必须在 frameworkAssemblies 中添加 System.Runtime,而不是依赖项。工作 project.json:

{
  "version": "1.0.0-*",
  "description": "AsyncTest Console Application",
  "authors": [ "ricardo.smania" ],
  "tags": [ "" ],
  "projectUrl": "",
  "licenseUrl": "",

  "compilationOptions": {
    "emitEntryPoint": true
  },

  "dependencies": {
    "Nito.AsyncEx": "3.0.1"
  },

  "commands": {
    "AsyncTest": "AsyncTest"
  },

  "frameworks": {
    "dnx451": {
      "dependencies": {
        "Microsoft.Net.Http": "2.2.22"
      },
      "frameworkAssemblies": {        
        "System.Runtime": "4.0.0.0",
        "System.Threading.Tasks": "4.0.0.0"
      }
    }
  }
}