http://lnbogen.com/2006/09/20/changing-the-output-path-in-your-web-applications-is-a-bad-idea/
Let’s assume we have a WebSite(the same issue applied to WebService btw) named WebApplication1.
Now, we want to put its(the website’s) output files into some other directory (!= “bin” directory) for development reasons (working as part of a team with some sophisticated复杂的 Source Safe).
What’s the first thing you (and me) do? we use our “rational”合理的 programmer nature and Right-Click on the project->Properties->Build Tab->and changing the Output path to whatever we need.
(Instead of “bin” we can write here “....infrastructure” for example)
We then build the all thing and surprise surprise, the new output pathcontains all the dlls as expected. Awesome!
Satisfied with the greatness of Visual Studio .Net 2005, we now want to Publish the WebSite so we(or the QA) can play with it.
“Think as a developer, think as a developer” I say to myself and Right-Click the WebSite project->Publish… A few really easy “decisions” and ~10 seconds later, VS.NET tells(it speaks to me, I swear) me that my site was published successfully.
Happy as a little girl with a new puppy小狗, I enter my site:http://localhost/webapp1/Default.aspx and Oops哎哟!
The page can’t find its “code behind”(The class that it inherits from)! What the hack is going on here!?
Well, it turns out that the Publish process is not as smart as you may think it should be.
Changing our Output path to another directory (!= “bin”) caused this all mess as the Publish process simply copy all the files from the bin directory into the new(Published) bin directory.
No questions asked. The Publish algorithm do not check if you actually compile your dlls into another directory via Output path and taking it into account.
Fortunately for us, the solution is pretty easy: define your Output path into the original location (“bin”) and use the Build Events(post-build in this scenario) in order to copy the output files into your “infrastructure”(or whatever) directory like this:
(The command: xcopy /Y /S ${TargetDir}*.* ....Infrastructure)
May it save you the 15 minutes it took me and my teammate Hagay to solve this one.