46

I've a MVC 4 application and runs well on my DEV Machine where I installed MVC 4 extension for VS 2010.

When deploying to the web server with IIS 7, do I need to install MVC 4 or should the dll included on my project is sufficient?

The reason I'm asking is we need to provide the requirement to infrastructure team.

Thanks.

Nil Pun
  • 17,035
  • 39
  • 172
  • 294

4 Answers4

80

You can run an MVC application without installing MVC on your server. There is something called deployable dependency in Visual studio. That will publish your MVC DLLs in your bin folder when you publish it.

from the msdn page,

This will add assemblies (DLL files) to a Web site project or Web application project. When you deploy your Web site or application, the files are included in the deployed project. This is useful if applications or technologies that your project depends on are not already installed on the server that will host your Web project. For example, you can use this feature to deploy an ASP.NET MVC 3 Web application to a server that does not have ASP.NET MVC 3 installed.

Right Click on Project and Select Add Deployable Dependency from the context menu

enter image description here

Select what all DLLs you want to be published

enter image description here

After clicking OK, You will see a new folder called _bin_deployableAssemblies. You can do normal Publishing procedure now and you will have the dlls in the bin folder of the publish output.

enter image description here

Check this post for more details http://haacked.com/archive/2011/05/25/bin-deploying-asp-net-mvc-3.aspx

You should have Visual Studio 2010 SP1. Otherwise it will not be shown in the context menu when you right click on the project to be published.

EDIT : As of MVC4, all necessary assemblies to run an MVC application are automatically added to the bin directory, and any MVC4 application is bin-deployable (means you can run it in a server without explicitly installing MVC) . For this reason, the Include Deployable Assemblies dialog has been removed from Visual Studio 2012

Mark Pearl
  • 7,573
  • 10
  • 47
  • 57
Shyju
  • 214,206
  • 104
  • 411
  • 497
  • 1
    Shyju I have a MVC4 application that is not adding all the needed assemblies to the bin (System.Web.Razor). Do you have information or a link to how this is controlled/accomplished in MVC4? Thank you – Joe Feb 28 '13 at 18:58
  • 2
    I figured it out. In VS 2012 you have to set the Reference's Copy Local to True in its Properties. See post: http://stackoverflow.com/questions/15145253/general-system-web-razor-error-also-postal-project Just saw that AvkashChauhan already answered that below. – Joe Feb 28 '13 at 23:50
  • 1
    I have specifically installed server-side MVC 3 and MVC 4 packages on the server to avoid copying the common MVC libraries each time (we have a lot of separate little web sites, and the common libraries sum up to gigabytes). It works perfectly with MVC 3 (no shared binaries are copied), but does not work at all with MVC 4 - if I set CopyLocal=false for shared binraies, the web site does not work. What is the point of the server-side package then? Is there a proper supported way to have MVC 4 installed globally in GAC, like there is for MVC3? – GSerg Aug 06 '14 at 11:08
6

You no longer have the option to "Add deployable dependencies" in Visual Studio 2012. So you'll have to do it manually, by bin deploying all the MVC assemblies:

Microsoft.Web.Infrastructure
System.Web.Helpers
System.Web.Mvc
System.Web.Razor
System.Web.WebPages
System.Web.WebPages.Deployment
System.Web.WebPages.Razor

A step by step guide is found here.

Bogdan Gavril MSFT
  • 20,615
  • 10
  • 53
  • 74
4

When u create a MVCx specific project in Visual Studio you will see lots of MVC.* references are added to your project and by default all of these reference property "Copy Local" is set as "True" means these references will be part of your final solution whenever you will deploy to. You can also verify that these MVC specific references are also part of your BIN folder.

Finally when you will package this solution and publish to a specific Web Server or to Windows Azure or use WebDeploy, all of these references will be part of your package also. And because these references are shipped in your package so where ever you will deploy the solution, all MVC specific references will be there and because of that you don't need to deploy MVC to those specific servers.

I would also like to add that any time when you add a specific reference to your project in Visual Studio, set its property "Copy Local" to TRUE so that reference will always be part of your final solution, and will save you from trouble in future.

AvkashChauhan
  • 20,495
  • 3
  • 34
  • 65
  • Great answer. This is very important for MVC4 since Add Deployable Dependencies has been removed from VS 2012. – Joe Mar 01 '13 at 03:55
1

You only need to have the dlls deployed into the bin of your project. For an example of how to prepare your web site for release check out the following blog post:

running-an-asp-net-mvc-3-app-on-a-web-server-that-doesn-t-have-asp-net-mvc-3-installed.aspx.

Josh Mein
  • 28,107
  • 15
  • 76
  • 87