ASP.NET MVC - Script Combine - asp.net-mvc

The ASP.NET team released the script combining feature in 3.5 SP1 as detailed here http://www.asp.net/Learn/3.5-SP1/video-296.aspx. Is there a similar feature already for the MVC framework? If not, is this in scope or is it possible to somehow leverage the webforms capability in MVC? I see this site uses a custom jquery.package.master which, I assume, they have rolled themselves (maybe into the build cycle, however it is not all minified therefore I think they have manually appended the scripts together rather than some automated minify & combine task). Would be interested in any ideas how to accomplish this in MVC but I dont want to begin rolling any of my own functionality in case I will be duplicating work in progress.

Here's what I do, in case it's helpful.
In my postbuild I call a command line version of Dean Edwards's Packer. It combines the scripts and packs them for me.
For now though, I keep all of my stuff seperate and use a Helper method to include my scripts, and if the debug flag is not present it will include the packed versions, otherwise it includes the unpacked.

Another option is in the Telerik Native UI Extensions for MVC (free library and open source), called ScriptRegistar. It will combine and compress javascript for you, and is fairly feature rich. There is also a class for doing the same to css as well.
I am using this to combine +20 javascript files into one file which is downloaded by the browser.
http://www.telerik.com/products/aspnet-mvc.aspx and you can get it via NuGet.

Every day there is a different way of doing things and the techniques changes.
At this time there is a very good Nuget Package released in CodePlex.
Combres - WebForm & MVC Client-side Resource Combine Library
http://combres.codeplex.com/
http://weblogs.asp.net/gunnarpeipman/archive/2009/07/04/asp-net-mvc-how-to-combine-scripts-and-other-resources.aspx

Related

Umbraco class library and Web Site

I have a project I was brought onto a few years ago and the original developer is no longer available. We have an Umbraco 6 based website. The solution has two projects, a Web Site and a class library call Umbraco.Extensions. I believe I read some conventional wisdom pertaining to Umbraco at some point where it is recommended to split it up like this but I am looking for more information about this particular style of setup and how it is supposed to work. For example right now I am dealing with a missing assembly issue, and i fixed it by copying a dll from the bin of Extensions to the bin of the Web Site. How is this handled regularly?
it's generally a good idea to keep the projects separated. You should have some kind of automation (maybe a post-build action) to copy the dll of the class library to the bin of the umbraco project. Or maybe rebuild the umbraco project with the correct references, but I dont usually do that.

Pack my ASP.NET MVC pager into NuGet package?

I've a pager functionality I use in some of my ASP.NET MVC projects. It consists of a couple of classes and interfaces (to generalize approach to paging of different datasources) and .aspx or .chtml view.
I can put my C# code into NuGet package/library assembly but what to do with view files which can be different for different projects (different pager design, for example)? One approach is to put HTML to HTML helper, written in C#, but I don't like putting bit chunks of html into C# code.
Is it possible to put views to NuGet package or should I use recipe feature?
I've wanted to push the usage of Nuget in MVC apps to reuse MVC apps themselves not just code - views too. I did manage to pack it up but it has like dozens issues and the experience is horrible.
If you have a pager functionality built inside an ASP.NET MVC Web application project then you can just pack it up and it will pick up the Views too. It does become a lot trickier when using DI, when using Areas, when using localization (resource files don't get picked up). For instance, Area routes might get compiled and included, on the other hand the main global.asax.cs will never be included in the package (so you have to manually copy the routes over if you have them in there).
But it does include stylesheets, so you can style your pager to the default stylesheet which you include in your package and that way you have also solved the issue of design modifications.
But all in all NuGet isn't best suited to pack MVC (or classic ASP.NET webforms) apps.

.net architecture for module based solution

I'm in the research/planning phase of a project (.Net c#, mvc or silverlight). It's a web project that offers certain services bundled into packages. The client can sign up for one of the different packages.
I'm looking for any suggestions on which architecture/framework to use for this kind of project. I want the ability to load or unload modules depending on the package. I also want to be able to enable and disable features within the packages themselves.
The modules have to be highly portable and plug-able into different clients. I know there are MEF and Prism but I haven't really worked with both. I also read about MVC and Areas. I would rather design everything from scratch and not depend on a third party if the task is simple enough. I just don't know where or how to start.
I appreciate the suggestions.
MG
You can forget about unloading. You have to use seperate appdomsins to be able to unload modules. And that's nothing that I would ever try with a ASP.NET website.
You have to get used to the thought that all modules are loaded at all times. You can use role based security to control if a user can use a module or not (one or more roles per plugin).
As for loading things dynamically: I've written an article about how you can create a plugin system using my Griffin.MvcContrib: http://www.codeproject.com/Articles/386674/ASP-NET-MVC-3-plug-in-architecture-using-Griffin-M

Multiple web projects, (almost) same layout in Visual Studio

Im currently developing an application with two web projects (MVC):
Frontend
Backend
These two are going to have almost the same layout (few minor changes). Therefore I thought about creating a MasterPage, they can share. But since it's two projects in two different locations, where should I put the masterpage, images and javascript?
The images and javascript (static stuff), could be placed on a CDN.
But how 'bout the ASP.NET specific stuff? Any suggestions? Any help appreciated!
A MasterPage is a UserControl under the hood, so any method of sharing UserControls would work for MasterPages. Unfortunately this isn't that great of an experience in ASP.NET as the BuildManager (what compiles and connects the app paths to classes during build-time) only recognizes & processes files within the current project.
Sharing code-behind, or base classes is easy and works well. It is the design surface (.master, .ascx, .aspx) that doesn't have a lot of ability to be shared. You can use a deployment project to compile a web app project into an Assembly that can be referenced, but you will still need some design files in your actual project.
This might also be of help:
ScottGu: Creating and Using User Control Libraries
SO: How do I share user controls between web applications in ASP.NET?
It's possible to include an existing file from another project in a new project. You can do that. So just put it in one project and include it in the other.
Alternatively, you can create a 'core' library, and put things in there, but that doesn't 'play' well with controls and so on, so I'd recommend the first approach.

Can you convert an ASP.NET MVC Application to a Web Site using ASP.NET MVC and what problems might you run into?

I would like to use a WebSite project instead of a Web Application project for an MVC project.
What is the best way to accomplish this and are there signifigant problems that I might run into?
(as a side note, my reasoning for wanting this is because I have graphic designers who put files into SVN but they don't get added to the "project" and don't show up on deployment or deployment testing. My thought was that switching to a Web Site project might prevent this)
You don't need to do anything special if you are not using CodeBehind files (if you're using them, it'll be more complex but anyway, it's an MVC app. If you're using them, don't!). Just take an MVC Web app project and put all source files (*.cs) under App_Code directory of the Web site. That said, I fail to see any advantage for it.
The application project allows you to use the Models folder to embed classes into. This would then be compiled for that web project. A web site does not provide for this directly. It would require that you use an assembly project to maintain all of your classes. Rather than converting from one project type to another (which I am not sure how you wold go about doing that) you can simply attach an assembly project to your web application and not store any classes in the model folder of your application.
Having said this, you should keep your web project as an application as there usually are view specific classes that are required such as a your view model classes that belong in the web project.

Resources