Is there a way to change .net mvc bin dir location?
OK, so with the help of few links provided by Sen Jacob and some more research I've figured out that it is possible to do it all just using web.config.
First of all we need to provide the new path and tell the assembly name since we're steering away from defaults:
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="Something.Web" />
</assemblies>
</compilation>
</system.web>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="bin\debug" />
</assemblyBinding>
</runtime>
</configuration>
Now, for some reason everywhere else people suggest specifying privatePath
relative to bin dir (i.e. privatePath="debug"
), however in my case it had to be relative to app root (i.e. as above). Maybe it's a change in .net4 or some other configuration setting I'm missing, not sure; if someone has a better idea feel free to edit/comment.
At this stage, if the server finds the file, and successfully loads the assembly and the class it will start complaining about all the missing referenced files, which I had to add right next to <add assembly="Something.Web" />
:
<assemblies>
<add assembly="Something.Web" />
<add assembly="System.Web.Mvc" />
<add assembly="System.Web.Optimization" />
<add assembly="System.Web.Helpers" />
<add assembly="System.Web.WebPages" />
</assemblies>
From what I've gathered it re-compiles the assemblies on site startup (not sure).
Sources: 1 2 3
I had the same issue. To solve it, I created a directory junction called "bin" to the target directory in the Post-Build Event:
if exist "$(ProjectDir)bin" rmdir "$(ProjectDir)bin"
mklink /J "$(ProjectDir)bin" "$(TargetDir)"
This way you can set your Output Path to somewhere else, even completely outside the source tree.
IISExpress will still run from your project folder in the source tree, but follows the bin junction to find the built DLLs. Note that the other files will be used from the source tree location.
The junction is removed and recreated each time, in case you switch build configurations.
Make sure the bin directory doesn't already exist from your old build setup, the rmdir won't work if there are files in the (real) bin directory.