Although I welcome the ASP.NET vNext move by Microsoft (including the cross-platform move), I have one big question: Can the existing NuGet packages ecosystem be reused, or does vNext require specific NuGet packages due to the usage of a specific subset of the .NET Framework?
1 Answers
You can absolutely use existing NuGet packages. At the end of the day, it all depends on what framework you are targeting. If your application targets aspnet50
for example, you can happily consume existing NuGet packages which are compatible with NET 4.5 and higher (depending on which version of .NET framework you have installed). Here is a sample project.json file which indicates MongoDB .NET Client consumption from nuget.org:
{
"name": "AspNet.Identity.MongoDB",
"version": "1.0.0-beta1",
"dependencies": {
"Microsoft.AspNet.Identity": "3.0.0-*",
"mongocsharpdriver": "1.9.2"
},
"aspnet50": {
"dependencies": { }
}
}
As I only have one framework (aspnet50), it will work smoothly even if I have the mongocsharpdriver reference for all frameworks.
You can use this approach to ease your move to ASP.NET vNext (as I did with my MongoDB ASP.NET Identity implementation) since libraries like MongoDB .NET Client probably need some time to be compatible with aspnetcore50.
If I was targeting multiple frameworks, I would have the specific package installed only for that framework. Here is an example:
{
"dependencies": {
"Kestrel": "1.0.0-*",
"Microsoft.AspNet.Mvc": "6.0.0-*",
"Microsoft.AspNet.Mvc.WebApiCompatShim": "6.0.0-*",
"Microsoft.AspNet.Server.IIS": "1.0.0-*",
"Microsoft.AspNet.Server.WebListener": "1.0.0-*",
"Microsoft.AspNet.StaticFiles": "1.0.0-*",
},
"commands": {
"web": "Microsoft.AspNet.Hosting server=Microsoft.AspNet.Server.WebListener server.urls=http://localhost:5001",
"kestrel": "Microsoft.AspNet.Hosting --server Kestrel --server.urls http://localhost:5000"
},
"frameworks": {
"aspnet50": {
"dependencies": {
"Microsoft.Framework.DependencyInjection.Autofac": "1.0.0-*",
"Microsoft.Framework.ConfigurationModel.Json": "1.0.0-*"
}
},
"aspnetcore50": {
"dependencies": { }
}
},
"webroot": "wwwroot"
}
Notice that Microsoft.Framework.DependencyInjection.Autofac package is only installed for aspnet50. It won't be available when you are compiling the application under aspnetcore50. Of course with this approach, you will need to ifdef for your way to victory depending on the use case as done here.
-
Problem is (I think) that vnext targets Microsoft.Net framework AND Mono .Net framework. Only packages that will run on both are reuseable. So for packages that are dependent on for example system.web will not work. How do we know which packages work, and which packages don't work... So most packages need to add another target... but ok, was the same case with .net 3.5 and .net 4. – Serge van den Oever Oct 27 '14 at 15:16
-
Multiple things you mention are untrue. You are as compatible as your dependencies are. If your dependencies don't run on mono then you won't, it doesn't mean it has to work to use it. If your package depends on System.Web then it probably won't work, but it might depending on how it uses it (HttpUtility works for example). As for how you know which ones will and wont work, trial and error. – davidfowl Oct 29 '14 at 08:24