Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot run MVC4 project if not using standard output directory

My project structure looks like this:

  • src
    -- class library 1
    -- class library 2
    -- web project
  • bin
    -- debug
    -- release

The default output directory for an MVC4 web project is .\Bin\ (i.e. within the web project's directory), but I change it to something like ..\bin\debug\ or ..\bin\release\ to fit my above project structure. It compiles fine and the binaries go to the correct places.

But when I run the project it complains that Could not load type Myproject.MvcApplication, whereas if I don't make the above changes then it works.

How do I control the location for the binaries? I want the output directory to be completely separate from the source directories - it's easier to deploy and more secure because I don't have a mixture of source and binaries in one place.

like image 339
Bobby B Avatar asked Oct 02 '12 06:10

Bobby B


2 Answers

Short answer, you can't. It has nothing to do with Visual Studio or even .NET, it's an IIS restriction.

The reason is that IIS expects the bin directory to be directly under the web site folder location. This is a security mechanism that you cannot bypass. It's purpose is to prevent a compromised web site from "escaping" from the bounds of the root directly of the site.

Why would you even WANT to do this?

like image 75
Erik Funkenbusch Avatar answered Nov 07 '22 05:11

Erik Funkenbusch


I hit this as well, it is unexpected and confusing given that separation of debug and release binaries is standard practice and MVC has an output folder setting which makes it tempting to do so. It is possible to do this, see here, but it is a bit ugly.

It seems that there is a conflict between adhering to the expectations of IIS and the need to keep debug and release separate and clearly labelled. I think that there is a need for both that the current solution doesn't satisfy very well. Debug and release are build time considerations, adhering to IIS is package/deploy time and the two have become confused.

like image 39
acarlon Avatar answered Nov 07 '22 05:11

acarlon