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 6:44 AM
# 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 7:25 AM
# 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 03, 2008 5:13 PM
# 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 03, 2008 7:48 PM
# 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 03, 2008 9:17 PM
# 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 03, 2008 11:10 PM
# 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 03, 2008 11:44 PM
# 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 1: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 7:59 AM
# 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 1: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 12: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 12: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 12: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 09, 2008 9:14 PM
# re: Bin Deploying ASP.NET MVC
A little off topic:

Could I do the same with Dynamic Data?

Thanks.
Requesting Gravatar... Jason Nov 12, 2008 9:55 PM
# 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 26, 2009 7:32 PM
# 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 27, 2009 4:55 PM
# 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 7:53 AM
# re: Bin Deploying ASP.NET MVC
Awesome article. I finally published my MVC personal website.
Requesting Gravatar... Alex Scordellis Feb 02, 2009 12: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 02, 2009 10:03 PM
# 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 1: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 12: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 12: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 3:24 PM
# re: Bin Deploying ASP.NET MVC
t
Requesting Gravatar... Jeff Brown Feb 14, 2010 1: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 27, 2010 10:17 PM
# 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 11, 2010 6:51 PM
# re: Bin Deploying ASP.NET MVC
That really helps me in publishing my MVC site.
Requesting Gravatar... L6zi75 Aug 30, 2010 4:00 AM
# 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 1:58 PM
# re: Bin Deploying ASP.NET MVC
Nice~! Thanks~! Solved My Problem~! ^_^
Requesting Gravatar... Paul Jones Sep 07, 2010 2:26 PM
# re: Bin Deploying ASP.NET MVC
Yeah, MVC is the way. Checkout RoR. kettlebell exercises
Requesting Gravatar... Slava Nov 08, 2010 8:03 PM
# re: Bin Deploying ASP.NET MVC
Nice post, now I know ASP.NET MVC deployment kung fu.
Requesting Gravatar... Jack Dec 30, 2010 7:34 PM
# re: Bin Deploying ASP.NET MVC
i generate a sample MVC application thru the VS Express 2010 without changing any code, it works fine in my local PC. When i try to upload the project to hosting server(production server) for testing, i got an error:

Could not load type 'System.Web.Mvc.UrlParameter' from assembly 'System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.

Using asp.net 4, IIS 7.0

With Bin deploy also not working. :(
Requesting Gravatar... Arturito.NET Jan 20, 2011 7:38 PM
# re: Bin Deploying ASP.NET MVC
Deploying MVC2:

arturito.net/...
Requesting Gravatar... Jekke Feb 10, 2011 3:18 PM
# re: Bin Deploying ASP.NET MVC
This works well with MVC 2. With MVC 3, you need to add a half-dozen more files to your "copy local" list including some that aren't in the references for the default project. If you walk through the "file not found" exceptions, it's pretty straightforward which ones you need.
Requesting Gravatar... ahmad Mar 07, 2011 9:23 PM
# re: Bin Deploying ASP.NET MVC
i not understand byyyyyyyyyye
Requesting Gravatar... Victor Juri Mar 29, 2011 12:08 PM
# re: Bin Deploying ASP.NET MVC
I am hosting with Godaddy and this worked great for me. I love MVC, find it very intuitive. Appreciate all your work on it, videos, tutorials, post like these.

Thanks Phil
Requesting Gravatar... Chaaya Apr 03, 2011 2:56 PM
# re: Bin Deploying ASP.NET MVC
Thanks a Million, Saved a lot of my time.

Chaaya
Requesting Gravatar... Azure Diagnostics Apr 20, 2011 11:18 PM
# re: Bin Deploying ASP.NET MVC
Thanks so much, that made all the difference. I did find that I had to publish to GoDaddy using FTP and it did not work when I first published to the hard drive and manually ftp'd. I am not sure what the difference was though...
Requesting Gravatar... Mihai Jun 01, 2011 4:36 PM
# re: Bin Deploying ASP.NET MVC
worked for MVC3
Requesting Gravatar... Sudipta Manna Sep 12, 2011 7:52 PM
# having problem uploding mvc in web server
Sir, I am very new to MVC application. I ve build a small, MVC project and have bought domain. BUT i am getting error for uploding the file..and it creating problem in web config saying


Parser Error Message: It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS.

Source Error:


Line 20: </assemblies>
Line 21: </compilation>
Line 22: <authentication mode="Forms">
Line 23: <forms loginUrl="~/Account/LogOn" timeout="2880" />
Line 24: </authentication>


Source File: D:\inetpub\vhosts\itorbital.diademtech.com\httpdocs\medclinapplication\medclinapplication\web.config Line: 22
can any 1 help me???
Requesting Gravatar... Kenan Bek Sep 25, 2011 3:33 PM
# re: Bin Deploying ASP.NET MVC
kenanbek.com/...
also this may be useful
Requesting Gravatar... Doc Nov 04, 2011 8:53 AM
# re: Bin Deploying ASP.NET MVC
Thanks very much!!!

What do you have to say?

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