Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can the new ASP.NET 5 (ASP.NET MVC 6) project type target regular .NET?

The new ASP.NET 5 (vNext) does some great stuff like integrate Bower, Grunt, and other client side web development tools into the project.

However, it is dawning on me (after many such projects were made and scratched) that it would seem all of this is limited to projects that can target the new 'cloud' or 'cross-platform' (KRE-CLR) stack ONLY, as opposed to the regular .NET stack. As nice as it would be to target this new stack, this severely limits what one can target at this time (basically any dll / project you reference now isn't an ASP.NET 5 class library, so it can't be referenced, so you can't rely on this?).

Am I missing something? Can the new ASP.NET 5 (ASP.NET MVC 6) project type target regular .NET?

If the answer is NO, even if this isn't possible now, do the team plan to at least add some of these client-side capabilities (bower, grunt, etc) to 'regular' ASP.NET (MVC 5) projects in the future?

like image 561
Nicholas Petersen Avatar asked Jan 22 '15 20:01

Nicholas Petersen


People also ask

What is the difference between .NET 5 and .NET 6?

NET 5.0 as . NET 6.0 has more improvement on the performance which also includes some major advantage as it has intelligent code editing and also it is called the fastest full-stack web framework. The . NET 6.0 also provides better performance in the File Stream.

Is .NET 6 backwards compatible?

NET 6 provides the delicate transition they need. Users of . NET Core likely won't run into quite as many backward compatibility issues, but it's still a possibility to keep in mind.

Is ASP.NET MVC 5 cross-platform?

The main difference between ASP.NET Core and ASP.NET MVC 5 is their cross-platform approach. ASP.NET Core can be used on Windows, Mac, or Linux, whereas ASP.NET MVC 5 can only be used for applications on Windows.


2 Answers

As per my experience with the latest version of Visual Studio CTP 5, here are few things to consider:

  1. In CTP 5 it now allows you to add a reference to a regular class library.
  2. In ASP.net vNext they target a different framework to support cross platform, and this is newly supported For example, if you only choose aspnet50 in frameworks (project.json) and runtime is CLR then it will use full .NET Framework, so you can use almost all functionality like in ASP.NET MVC 5. If you want to work with aspnetcore50 then it is possible that much functionality will not be available, or even many be under development.
  3. If you have built your own class library and you want to add a reference to it, then in VS 2015 preview and CTP5 you have to publish NUGET package and then use that package to reference that DLL.
  4. If you want to use a regular .NET assembly (for example System.DirectoryService) then make sure that you have only one framework in project.json.

Update

I assume that you are using Visual Studio 2015 CTP 5.

Here is copy of my project.json

{
    /* Click to learn more about project.json  http://go.microsoft.com/fwlink/?LinkID=517074 */
    "webroot": "wwwroot",
    "version": "1.0.0-*",
    "dependencies": {
        "EntityFramework.SqlServer": "7.0.0-beta2",
        "EntityFramework.Commands": "7.0.0-beta2",
        "Microsoft.AspNet.Mvc": "6.0.0-beta2",
        /* "Microsoft.AspNet.Mvc.WebApiCompatShim": "6.0.0-beta2", */
        "Microsoft.AspNet.Diagnostics": "1.0.0-beta2",
        "Microsoft.AspNet.Diagnostics.Entity": "7.0.0-beta2",
        "Microsoft.AspNet.Identity.EntityFramework": "3.0.0-beta2",
        "Microsoft.AspNet.Security.Cookies": "1.0.0-beta2",
        "Microsoft.AspNet.Server.IIS": "1.0.0-beta2",
        "Microsoft.AspNet.Server.WebListener": "1.0.0-beta2",
        "Microsoft.AspNet.StaticFiles": "1.0.0-beta2",
        "Microsoft.Framework.ConfigurationModel.Json": "1.0.0-beta2",
        "Microsoft.Framework.CodeGenerators.Mvc": "1.0.0-beta2",
        "Microsoft.Framework.Logging": "1.0.0-beta2",
        "Microsoft.Framework.Logging.Console": "1.0.0-beta2",
        "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-beta1"
    },
    "commands": {
        /* Change the port number when you are self hosting this application */
        "web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --server.urls http://localhost:5000",
        "gen": "Microsoft.Framework.CodeGeneration",
        "ef":  "EntityFramework.Commands"
    },
    **"frameworks": {
        "aspnet50": {
            "dependencies": {
            "MyCoolLibrary": "1.0.0-*"
            } }

    },**
    "exclude": [
        "wwwroot",
        "node_modules",
        "bower_components"
    ],
    "packExclude": [
        "node_modules",
        "bower_components",
        "**.kproj",
        "**.user",
        "**.vspscc"
    ],
    "scripts": {
        "postrestore": [ "npm install" ],
        "prepare": [ "grunt bower:install" ]
    }
}

My custom class library in MyCoolLibrary and it is added in framework dependencies not dependencies. Also I build my library using .NET Framework 4.5. ( Not 4.5.3) so it support older version as well.

If you are using Visual Studio 2015 Preview then also above thing will work.

like image 73
dotnetstep Avatar answered Oct 15 '22 09:10

dotnetstep


In a new post by Scott Guthrie, he seems to confirm that ASP.NET 5 absolutely should work with the full .NET framework, in fact, even saying:

"Your existing applications and libraries will work without modification on this [full .NET] runtime."

Here's the full citation:

ASP.NET 5 works with two runtime environments to give you greater flexibility when hosting your app. The two runtime choices are: ([a] .NET Core ... [b] .NET Framework – The API for .NET Core is currently more limited than the full .NET Framework, so you may need to modify existing apps to target .NET Core. If you don't want to have to update your app you can instead run ASP.NET 5 applications on the full .NET Framework (version 4.5.2 and above). When doing this you have access to the complete set of .NET Framework APIs. Your existing applications and libraries will work without modification on this runtime.

While I am very glad to hear this, the problems discussed in this question and by other posters here makes it seem like this target goal does not yet match the current reality. In simplest terms, we need not only to be able to target the full .NET, but to simply reference current .NET dll/assemblies. Currently, it seems the only assemblies that work are ones built against .NET Core.

The answer to this dilemma then? I believe the answer is: It's coming. This according to the new Visual Studio 2015 CTP 6 release notes:

System References are back

You can now easily add references to system assemblies using the Add References dialog, which will make the appropriate modifications to your project.json file... We are also hard at work to enable support for adding references to user assemblies for a future preview release.

enter image description here

(picture from that article)

So then, this is GREAT news! This also justifies that, according to these posts, these indeed have been shortcomings up till now (and still exist for user assemblies for the moment).

like image 21
Nicholas Petersen Avatar answered Oct 15 '22 09:10

Nicholas Petersen