2

Has anyone tried packing an entire ASP.NET MVC application with Nuget and did it work for him? I have a bunch of controllers, views, helpers and utilities that I would like to bring in into another MVC project.

The problem is, routes don't work and I don't whether they should or not. The thing is, the project for the package we brought in had its own global.asax.cs and its own routes. How does that get combined with our current project's global.asax and its routes?

So if anyone had any experience with such packages, please reply.

3 Answers 3

1

You should try to use the MVC Area feature to allow routes to be registered from multiple places. To see what that looks like, right click an MVC project and choose Add / Area; then look at the AreaRegistration file that gets created.

UPDATE: using WebActivator provides another approach to executing code at startup without having to modify global.asax.

Sign up to request clarification or add additional context in comments.

2 Comments

Hey David, I actually discovered your WebActivator package and it allowed me to do exactly what I wanted - by placing my route registration in the Pre or Post start method, depending on what I need. However, there is only one issue and that is the interaction with the global.asax.cs that is already in the project in which we pull our package. Being that we have to be careful that route names don't duplicate because then we get the "route already in the collection" error at runtime. Now the only solution to this is to prefix the route names in my package or do you have another idea?
You will indeed need to make sure that route names are unique globally, or MVC will blow up. You could have a route registration helper that automatically does the prefixing. In any case, having to 'uniquize' the route names is not that painful :)
1

Your routes will not get merged so you will need to combine the routes yourself to make this work. You could use areas which have their own routes if you wanted to keep them separate but if you are just pulling in a bunch of controllers and views you'll need to edit the routes in your project so they make sense in the new application.

Comments

0

There is a scriptable application that can help you with copying the required files, see: https://nugetpackager.codeplex.com

This work well with an Area / Webactivator setup.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.