My project structure looks like this:
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.
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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With