VS 2015. Setting right target framework for ASP.NET 5 web project
Asked Answered
D

2

39

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

Diphase answered 28/7, 2015 at 9:5 Comment(6)
what do you have in global.json? if you right click project and choose properties, do you have a specific framework checked there? seeing more of your project.json to see the main dependencies might help diagnosing the errorBaroscope
I've updated the initial post and added the content of global.json into it. However I've already tried to change the version of "sdk" listed there - but it didn't help.Diphase
you did not show the dependencies section of project.json. beta6 was supposed to be released yesterday and it does seem to be in the nuget feed but there hasn't yet been a release announcement for it and I thought there was supposed to be a corresponding tooling update for VS 2015. for now I would use beta5 until more news about beta6 releaseBaroscope
it does matter what is in dependencies, I've seen mistakes happen where some dependencies from the main section need to be moved into dependencies below dnxcore50Baroscope
I had the same problem. Adding "Microsoft.AspNet.Server.IIS": "1.0.0-beta6" to my project.json fixed the issue. I don't know why however. Perhaps it helps you too.Engedus
Did you get anywhere with this @Sergiy? I am seeing a similar issue here: github.com/aspnet/dnx/issues/2365Malorie
G
54

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

Godsey answered 28/7, 2015 at 21:34 Comment(5)
Thank you for so detailed explanation. Good to know that it was not my fault :)Diphase
@Andrew Nurse Do i need to uninstall beta5 for this to work? apparently it keeps trying to start iis with dnx 451 despite my efforts to use a specific runtime (beta6)Disrate
Today I tried to create a new project but this error keeps happening (beta6). This solution never worked for me.Valerle
In case anyone had not stumbled on this yet -- for production, IIS won't see this setting, unless the environment variable is manually set on the server. I have actually been building more outside of vs2015 and authoring a publish powershell script; this solved the issue for me, while allowing me to keep the admins from clawing ef7 and DI from my cold, dead, handsRaimondo
Briefly, I had class libraries targeting at .NET 4.5.2 and my just updated ASP.NET 5 framework project created from scratch had DNX 4.5.1 included. As I do not depend on 4.5.2+ features, I have targeted all my class libraries to .NET 4.5.1 - rebuilt them (very important) - and then it was finally possible to reference them.Champlain
E
2
"DNX_IIS_RUNTIME_FRAMEWORK" : "DNX46"

The value is case sensitive

Elbaelbart answered 28/8, 2015 at 16:50 Comment(1)
From what I've read DNX for framework identification is going away. After reading these two articles hanselman.com/blog/….... github.com/dotnet/corefx/blob/master/Documentation/project-docs/…Earthling

© 2022 - 2024 — McMap. All rights reserved.