Bin Deploying ASP.NET MVC

With the release of ASP.NET MVC Beta, the assemblies distributed with ASP.NET MVC are automatically installed into the GAC.

  • System.Web.Mvc
  • System.Web.Routing
  • System.Web.Abstractions

While developing an application locally, this isn’t a problem. But when you are ready to deploy your application to a hosting provider, this might well be a problem if the hoster does not have the ASP.NET MVC assemblies installed in the GAC.

Fortunately, ASP.NET MVC is still bin-deployable. If your hosting provider has ASP.NET 3.5 SP1 installed, then you’ll only need to include the MVC DLL. If your hosting provider is still on ASP.NET 3.5, then you’ll need to deploy all three. It turns out that it’s really easy to do so.

Also, ASP.NET MVC runs in Medium Trust, so it should work with most hosting providers’ Medium Trust policies. It’s always possible that a hosting provider customizes their Medium Trust policy to be draconian.

What I like to do is use the Publish feature of Visual Studio to publish to a local directory and then upload the files to my hosting provider. If your hosting provider supports FTP, you can often skip this intermediate step and publish directly to the FTP site.

The first thing I do in preparation is to go to my MVC web application project and expand the References node in the project tree. Select the aforementioned three assemblies and in the Properties dialog, set Copy Local to True.

copy-local-true_3 

Now just right click on your application and select Publish.

 publish-project_3

This brings up the following Publish wizard.

Publish-Web

Notice that in this example, I selected a local directory. When I hit Publish, all the files needed to deploy my app are available in the directory I chose, including the assemblies that were in the GAC.

bin-assemblies

Now I am ready to XCOPY the application to my host, but before I do that, I really should test the application as a bin deployed app to be on the safe side.

Ideally, I would deploy this to some staging server, or a virtual machine that does not have ASP.NET MVC installed. Otherwise, I’m forced to uninstall ASP.NET MVC on the current machine and then test the application.

You might be wondering, as I did, why I can’t just use gacutil to temporarily unregister the assembly, test the app, then use it again to register the assembly. Because it was installed using an MSI, Windows won’t let you unregister it. Here’s a command prompt window that shows what I got when I tried.

gacutil-mvc

Notice that it says that “assembly is required by one or more applications”. In general, there shouldn’t be any difference between running your application with MVC gac’d and it ungac’d. But I wouldn’t trust me saying this, I’d test it out to be sure.

Technorati Tags:

What others have said

Requesting Gravatar... Gabriel Bogea Nov 03, 2008 2:44 PM
# re: Bin Deploying ASP.NET MVC
Thanks for the tip Phil. This is really useful since my hosting provider hasn't installed SP1 yet.
Requesting Gravatar... egor Nov 03, 2008 3:25 PM
# re: Bin Deploying ASP.NET MVC
What about deploying mvc application to host provider with medium trust? Is it going to work?

Regards,
Igor
Requesting Gravatar... Simone Nov 04, 2008 1:13 AM
# re: Bin Deploying ASP.NET MVC
Isn't the second last figure supposed to show all the dlls, including the MVC ones, and not just the mvcapplication.dll one?
Simo
Requesting Gravatar... Graeme Nov 04, 2008 3:48 AM
# re: Bin Deploying ASP.NET MVC
Hurrah, just what i was looking for. Now I can develop for ASP.NET MVC without having to get a dedicated server.
Requesting Gravatar... Salman Nov 04, 2008 5:17 AM
# re: Bin Deploying ASP.NET MVC
25% of our problems are solved when we stay up to date on software patches ... (well that's what I read somewhere so it must be true!).
Requesting Gravatar... JH Nov 04, 2008 7:10 AM
# re: Bin Deploying ASP.NET MVC
I've always thought it's important for people to understand "How the Runtime Locates Assemblies"

http://msdn.microsoft.com/en-us/library/yx7xezcf(VS.71).aspx
Requesting Gravatar... JH Nov 04, 2008 7:44 AM
# re: Bin Deploying ASP.NET MVC
I find I keep coming back to the msdn article, "How the Runtime Locates Assemblies" to explain this.

http://msdn.microsoft.com/en-us/library/yx7xezcf(VS.71).aspx
Requesting Gravatar... haacked Nov 04, 2008 9:12 AM
# re: Bin Deploying ASP.NET MVC
@egor yep, you can. I updated the post to mention that.
@simone Yep, I'll fix it.
Requesting Gravatar... Lance Fisher Nov 05, 2008 3:59 PM
# re: Bin Deploying ASP.NET MVC
Thanks for the tips. I was just doing this stuff yesterday, and I was annoyed that I couldn't remove the dlls from the GAC. I didn't want to uninstall MVC because I didn't want to lose the project templates, etc.

What I would like is to be able to test the app in IE6 from a VM, but since I had the dlls in the bin directory, I was getting some conflicts with the GAC when I ran the site in IIS.

That "copy local" is a good tip. I had created a post-build step to copy the dlls, but I'm going to do it the right way instead now.
Requesting Gravatar... Boyan Kostadinov Nov 05, 2008 9:25 PM
# Mr
Where is the NAnt task to do all this with one step? I thought you were a NAnt fan :-)
Requesting Gravatar... codejudo Nov 08, 2008 8:22 AM
# re: Bin Deploying ASP.NET MVC
you can always try to uninstall it from GAC using some brute force :-)

http://support.microsoft.com/kb/873195
Requesting Gravatar... Dylan Beattie Nov 08, 2008 8:24 AM
# Removing System.Web.Mvc from the GAC after installing the beta
It's possible, with a little registry hacking, to remove System.Web.Mvc from the GAC after installing the beta, which lets you both test your bin deployment scenario locally, and run code that's using the preview releases alongside the beta if you need to. More details are here if you're interested. (Usual caveats about the dangers of registry hacking apply!)

Requesting Gravatar... codejudo Nov 08, 2008 8:25 AM
# re: Bin Deploying ASP.NET MVC
you can always try to uninstall it from GAC using some brute force :-) more details
Requesting Gravatar... Rafael Soares Nov 10, 2008 5:14 AM
# re: Bin Deploying ASP.NET MVC
A little off topic:

Could I do the same with Dynamic Data?

Thanks.
Requesting Gravatar... Jason Nov 13, 2008 5:55 AM
# re: Bin Deploying ASP.NET MVC
o , my God ! When i post all dll to my host server, but it is not work yet ! I can't find out any reason.
Requesting Gravatar... Wayne Austin Jan 27, 2009 3:32 AM
# re: Bin Deploying ASP.NET MVC
Great article, helped me alot with uploading my new MVC site.

Thanks very much! :D
Requesting Gravatar... Sawka Jan 28, 2009 12:55 AM
# Grouping Controllers with ASP.NET MVC
i have a problem with your solution about Grouping Controllers, simply ant override FindPartialView method in ViewEngineResult

any ideas?
Requesting Gravatar... yohannes Jan 30, 2009 3:53 PM
# re: Bin Deploying ASP.NET MVC
Awesome article. I finally published my MVC personal website.
Requesting Gravatar... Alex Scordellis Feb 02, 2009 8:24 AM
# re: Bin Deploying ASP.NET MVC
Phil,

I'm wondering why each version of MVC (Preview n, Beta, RC) has the same assembly version: 1.0.0.0. As I understand it, this means that if either Beta or RC is in the GAC, no web app on that system can run the other version.

The way it is now, either all projects on a server have to use the same GAC deployed version, or they all have to bin-deploy. If they were different versions, I think we'd be able to bind to specific versions for each app.

Cheers,

Alex
Requesting Gravatar... Chad Feb 03, 2009 6:03 AM
# re: Bin Deploying ASP.NET MVC
My publish fails... doesn't give any good error message (it simply says "publish failed"). The build "builds" with no errors, just the publish fails.

This is in Visual Studio 2008 (not express dev tools).

Anyone else experience this? Any ideas?
Requesting Gravatar... Haakon Mar 03, 2009 9:07 AM
# re: Bin Deploying ASP.NET MVC
Hi, I have a problem with Windows Web Server 2008 and deploying an MVC project. I have a copy of the project from our previous server where everything worked fine, but no source code.

The problem is that I am having trouble with the Futures assembly (RC1). It is impossible (?) to install on the server using gacutil.exe because it is not a strongly typed assembly. And even though the assembly is present in the projects bin folder (that was working fine on our 2000-server) it is not working now. I get "System.NullReferenceException: Object reference not set to an instance of an object" when browsing to the web site, and a pointer to the Html.MenuItem method as the source of the exception.

What to do?
Requesting Gravatar... Dan Crowell Mar 27, 2009 8:28 AM
# re: Bin Deploying ASP.NET MVC
@RafaelSoares, you can bin deploy Dynamic Data. The list of dlls includes those applicable to Dynamic data such as: System.ComponentModel.DataAnnotations, System.Web.DynamicData, and System.Data.DataSetExtensions.
Requesting Gravatar... Clearly Apr 05, 2009 8:21 PM
# re: Bin Deploying ASP.NET MVC
How do you perform the "Publish" from the command line so it can be built into continuous integration systems? aspnet_compiler doesn't seem to work anymore. Seriously, no one (or at least a million searches through Google) seems to know if or how this is possible.
Requesting Gravatar... t Dec 29, 2009 11:24 PM
# re: Bin Deploying ASP.NET MVC
t
Requesting Gravatar... Jeff Brown Feb 14, 2010 9:35 AM
# re: Bin Deploying ASP.NET MVC
so i get this error on my hosting server...

Could not load all ISAPI filters for site 'mydomain.COM'. Therefore site startup aborted.

it works locally.
Requesting Gravatar... Robert Steward Apr 28, 2010 6:17 AM
# re: Bin Deploying ASP.NET MVC
Thanks Phil, This works great on M6.Net. I am moving from webforms after torturing myself with learning PHP, ugh. Now on to MVC.

Thanks again, you've made my day work alot faster.

Robert
Requesting Gravatar... Chicago mover Aug 12, 2010 2:51 AM
# re: Bin Deploying ASP.NET MVC
That really helps me in publishing my MVC site.
Requesting Gravatar... L6zi75 Aug 30, 2010 12:00 PM
# re: Bin Deploying ASP.NET MVC
How do you perform the "Publish" from the command line so it can be built into continuous integration systems? how to jump higher kettlebell exercises aspnet_compiler doesn't seem to work anymore. Seriously, no one (or at least a million searches through Google) seems to know if or how this is possible.
Requesting Gravatar... Clifford P. Santos Sep 01, 2010 9:58 PM
# re: Bin Deploying ASP.NET MVC
Nice~! Thanks~! Solved My Problem~! ^_^

What do you have to say?

(will show your gravatar)
Please add 1 and 4 and type the answer here: