Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
285 views
in Technique[技术] by (71.8m points)

c# - Is there a way to change .net mvc bin dir location?

I have a fairly standard and simple MVC4 website.

In root dir we have: bin, content, scripts, views. Using default settings the project's DLL, let's call it "web.dll" and all the necessary extras go in the bin dir.

Somehow, ASP.NET dev server and IIS7.5 both know to look for "web.dll" in the bin folder when hosting the site, and if it's not there they throw error: "Could not load type 'CVD.Web.MvcApplication'". The standard solution for that error is to build directly into bin folder, which doesn't work for me because...

For debugging purposes, I'd like to be able to build Debug & Release configurations into into bin/Debug and bin/Release respectively and then deploy both dirs, then change a setting either in IIS, web.config, global.asax, or anywhere else to pick whether Debug or Release build should be loaded and executed by the server.

I haven't been able to find if that's possible or if .net webapps have a silly hard-coded rule saying all code must live in the bin dir.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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="bindebug" />
        </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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...