14

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.

4

2 回答 2

11

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?

于 2012-10-02T06:25:21.497 回答
2

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.

于 2013-08-09T02:09:48.340 回答