Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
276 views
in Technique[技术] by (71.8m points)

.net - VS 2015. Setting right target framework for ASP.NET 5 web project

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.

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

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

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 '...'.

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

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

Here is my global.json now:

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

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.

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.

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:

Launch Profile

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 :).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...