Nuget Package: Use Different MVC Version When Available - asp.net-mvc

I've got an open source nuget package AttributeRouting. Currently the packaged assemblies reference System.Web.Mvc version 2. I'd like to reference MVC 3/4 in MVC 3/4 projects, so that users of Windows 8/VS 2011 don't have to install MVC 2 to use the package. Anyone know of a way to do this? Google has not been my friend.

Current, Nuget can't do this. This is why there are separate MVC2 and MVC3 packages of libraries in the Nuget gallery.
So you have to create a separate Nuget package for MVC3 and MVC4 (if necessary)

You can add into your Nuget package the assemblies for all supported versions of MVC and then use install.ps1 script to remove unnecessary ones and leave only the assembly which is compatible with MVC version used in the target project.
You will find more detailed instructions and an example of install.ps1 script here:
http://blogs.korzh.com/2013/12/nuget-package-different-mvc-versions.html

Related

Why does my NuGet package not add some referenced NuGet packages as dependencies?

I am currently trying to create a NuGet package from an ASP.NET MVC project (let's call it Library) I created, that should act as a base for other ASP.NET MVC projects.
Almost everything works fine so far, the only problem I ran into is, that NuGet only includes some of the NuGet references of my "Library" project, most notably the ASP.NET MVC NuGet packages seem to be missing.
This is the list of packages in my "Library" project:
And this is the dependencies created for the NuGet package:
Does anyone have an idea why bootstrap, Microsoft.AspNet.Mvc and others are not included?
I just debugged the NuGet.exe and found out why this happens: apparently NuGet does not take ALL dependencies but only a minimal set. This minimal set consists only of top-level packages (=> packages that are not referenced by another package in the project).
So for example the Autofac.Mvc5 package depends on Microsoft.AspNet.Mvc and therefore only Autofac.Mvc5 is used as a dependency.

Moving ASP.NET MVC project folder in VS 2013 changes System.Web.Mvc version to 4.0.0

When starting a new Web Application empty MVC project in VS 2013 using .NET 4.5.2, initially, VS 2013 will be referencing Microsoft.AspNet.Mvc 5.1.2 which contains System.Web.Mvc 5.1.0. But I typically change the directory of the MVC project so I remove the project from the solution, change the directory of the project using Windows Explorer, and then add the existing project again in the solution using VS 2013.
However, upon doing this, when I look on the version of System.Web.Mvc, it is now changed to 4.0.0. I've checked the repositories.config and it has the correct path for packages.config of the project. The packages config on the project also contains version="5.1.2" although the referenced System.Web.Mvc is 4.0.0.
Furthermore, as I am trying to use IAuthenticationFilter, the interface cannot be detected by Intellisense anymore (with red squiggly line) but I can still compile and run!
Do you guys know any workaround for this? I can use NuGet to update MVC to the latest (5.2.2 I think) and the reference would be fixed but I want to use the default 5.1.2.
you can target a specific version of MVC using the Nuget Package Manager Console:
Go to
Tools > NuGet Package Manager > Package Manage Console
At the prompt you can type
update-package Microsoft.AspNet.Mvc -version 5.1.2
I believe this is the easiest way to accomplish what you are trying to achieve. You may need to remove existing references to the MVC and WebPages dlls, sometimes references stick when moving from local/GAC references to those determined by nuget.

Whats going on with MVC5+ Assemblies?

I was planning to upgrade my project from MVC 4 to MVC5. I followed this article: http://www.asp.net/mvc/tutorials/mvc-5/how-to-upgrade-an-aspnet-mvc-4-and-web-api-project-to-aspnet-mvc-5-and-web-api-2. I did all the steps successfully, but got errors that the 5.0 dll could not be loaded.
The article, however, has no mention of where to get the DLLs. So I started looking for the DLLs everywhere, my file system, online, Google, etc.
Then I created my own MVC5 test project and noticed that the MVC 5.1 DLLs got added from nuget.
So, is Microsoft only distributing MVC dlls from nuget?
Also, I can find the MVC4 dlls from the file system and MVC5.1 dlls from the nuget package, where are the MVC5.0 dlls?
If you want a specific version from NuGet, open the Package Manager Console and type:
Install-Package Microsoft.AspNet.Mvc -Version 5.0.1
Which is the latest in the 5.0 series.

Can I use npm to manage an ASP.NET MVC Project's Javascript?

I'm developing a large client-side javascript app, which requires a complex tree of Javascript dependencies, all of which are available as npm modules. Most modules I require are not available as nugets, I'd like to get it so adding npm modules to my webapp is as simple as adding nugets.
Is it possible/reasonable to use npm to install packages "into" my ASP.NET MVC project?
You can check Bower. That is client package manager. It suits for asp.net mvc. Here some help:
http://chodounsky.net/2014/03/18/using-bower-in-asp-dot-net-mvc/
Javascript dependency management : npm vs bower vs volo?
npm support has been added to Visual Studio as of 2013 update 3:
http://www.hanselman.com/blog/IntroducingGulpGruntBowerAndNpmSupportForVisualStudio.aspx
You can now install packages by adding "Package.json" into your ASP MVC project and then add the packages you need. Visual Studio will install based on the packages included in your "Package.json" file.
Microsoft provide a tutorial for using NPM modules in visual studio projects: https://learn.microsoft.com/en-us/visualstudio/javascript/npm-package-management?view=vs-2022#aspnet-core-projects
Notice that, for ASP.NET projects, guidance is only given for Core projects and not MVC projects, showing that MVC projects don't natively support NPM.
I have not managed to use any other packages to set up NPM inside ASP.NET MVC projects, and have found that the best solution is to migrate the project over to Core, which Microsoft give a tutorial for (references to ASP.NET on its own generally refer to the MVC version) : https://learn.microsoft.com/en-us/aspnet/core/migration/proper-to-2x/?view=aspnetcore-7.0

Physical installation of MVC

When I install ASP.NET MVC, am I installing a different run-time, compiler, etc? Or, is it just GACing some managed assemblies for the framework?
It is installing System.Web.Abstractions.dll, System.Web.Routing.dll and System.Web.Mvc.dll assemblies into the GAC and depending on the type of install it could also install a VS project template.
MVC uses the same runtime and same compiler. It will add new project templates, page and controller templates to Visual Studio template folders. Also assemblies are added to the GAC.

Resources