VS 2015. 为 ASP.NET 5 web 项目设置正确的目标框架 [英] VS 2015. Setting right target framework for ASP.NET 5 web project

查看:29
本文介绍了VS 2015. 为 ASP.NET 5 web 项目设置正确的目标框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Visual Studio 2015 中创建了新的 ASP.NET 5 MVC 项目.在项目创建向导中,我选择显示 .NET 框架 4.6 的模板,然后在下一个屏幕上从 ASP 选择Web 应用程序".NET 5 预览模板.

I've created new ASP.NET 5 MVC project in Visual Studio 2015. On project creation wizard I've chosen to show the templates for .NET framework 4.6 and then on the next screen selected "Web Application" from ASP.NET 5 Preview Templates.

但是,在创建后,该项目似乎只在 project.json 的frameworks"部分列出了dnx451"和dnxcore50":

However, after creation it appears that the project listed only "dnx451" and "dnxcore50" in "frameworks" section of project.json:

  "frameworks": {
    "dnx451": { },
    "dnxcore50": { }
  },

我尝试将dnx451"更改为dnx46".该项目已经构建良好,但是当我尝试运行它时,我收到以下错误消息:

I've tried to change "dnx451" to "dnx46". The project has been built well but when I tried to run it, I got the following error message:

当前运行时目标框架与..."不兼容.

The current runtime target framework is not compatible with '...'.

当前运行时目标框架:'DNX,Version=v4.5.1 (dnx451)' 类型:CLR 架构:x86 版本:1.0.0-beta5

Current runtime Target Framework: 'DNX,Version=v4.5.1 (dnx451)' Type: CLR Architecture: x86 Version: 1.0.0-beta5

如何更改 ASP.NET 5 项目的目标框架"?

How is it possible to change that "target framework" for ASP.NET 5 project?

这是我的 global.json:

Here is my global.json now:

{
  "projects": [
    "src",
    "test",
    "wrap"
  ],
  "sdk": {
    "version": "1.0.0-beta5",
    "runtime": "clr",
    "architecture": "x86"
  }
}

但是那里列出的内容并不重要.我已经尝试过不同版本的 1.0.0-beta5 和最新的 1.0.0-beta6

but it does not really matter what is listed there. I've already tried different builds of 1.0.0-beta5 and the latest 1.0.0-beta6

推荐答案

问题是 DNX 知道您的项目面向 dnx46 但 IIS 不是 :).因此,IIS 以 .NET 4.5.1(默认情况下)启动并尝试加载与 4.5.1 不兼容的项目.

The problem is that DNX is aware that your project is targeting dnx46 but IIS is not :). So, IIS is starting as .NET 4.5.1 (by default) and trying to load your project which isn't compatible with 4.5.1.

在 VS Tooling 的未来版本中,我们将更好地检测这一点,但在此之前,对于想要面向 .NET 版本的 Web 应用程序来说,情况会有些粗糙以上 4.5.1.目前,我建议在此之前只使用 dnx451(如果您不依赖于 .NET 4.5.2/4.6 功能),但我将在下面提供一些有关如何使这项工作今天工作的说明如果您需要使用 4.5.2 或更高版本.

In a future version of the VS Tooling, we're going to do a better job of detecting that but until then, things are a little rough for Web Applications that want to target .NET versions above 4.5.1. For now, I suggest just using dnx451 until then (if you aren't depending on .NET 4.5.2/4.6 functionality), but I'll provide some instructions below on how to make this work today if you need to use 4.5.2 or higher.

注意:dnx452dnx46 在控制台应用程序和使用 IIS 以外的服务器(例如 Kestrel 或 WebListener)时完全支持.基本上,您可以使用本机 dnx.exe 引导程序启动的任何内容都适用于 dnx451dnx46,但其他托管环境(IIS、IIS Express)需要启动正确框架的额外提示.

Note: dnx452 and dnx46 are fully supported in Console Applications and when using servers other than IIS (such as Kestrel or WebListener). Basically anything you can launch using the native dnx.exe bootstrapper works with dnx451 and dnx46 but the other hosting environments (IIS, IIS Express) need additional hints to launch the correct framework.

今天要完成这项工作,您需要为要使用的目标框架设置环境变量 DNX_IIS_RUNTIME_FRAMEWORK.您可以在 Web 应用程序的项目属性"页面的调试"选项卡上执行此操作.只需选择 IIS Express 配置文件并添加如下环境变量:

To make this work today, you need to set an environment variable DNX_IIS_RUNTIME_FRAMEWORK to the target framework you want to use. You can do this in the Project Properties page for the web application, on the Debug tab. Just choose the IIS Express profile and add the environment variable as below:

我们将把它添加到已知问题,因为看起来我们错过了它,正如我上面所说的,我们将改进 VS 中的默认体验,因此这不是必需的 :)

We're going to get this added to the Known Issues, because it looks like we missed it, and as I said above, we're going to improve the default experience in VS so this isn't necessary :).

这篇关于VS 2015. 为 ASP.NET 5 web 项目设置正确的目标框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆