You might remember my earlier post when I was complaining about the structure of files in Visual Studio. After a little research, I have discovered how to “convince” Visual Studio to use the directory structure I would like it to. The goal of this is to turn a directory structure like this (Visual Studio's default):
to this:
- Solution/
- Project/
- bin/ ** compiler output for release builds **
- src/
- test/ ** compiler output for debug builds **
The purpose of this is to prevent the compiler output from residing in a subdirectory of the source files. In the future, this should make the source files easier to maintain (i.e. branch, merge, tag, etc.). The inspiration of the directory comes from a lot of linux projects that I have seen lately. I find it a much easier directory structure to deal with, especially in regard to source control.
It was surprisingly easy to make Visual Studio do it this way. It wasn't exactly intuitive, hence the reason for this post. I set out from the get-go to try to make Visual Studio do it this way because I already knew how to do it from the command line and in project settings. However, it is a pain-in-the-rear to add a project to a solution and then use Windows Explorer or the command line to change the directory the source files reside in and then change the solution file to point to the new directory. Not only that, but the last thing I want to do is to be forced to change the project properties everytime I add a new project to point to the new debug and release directories.
Now, for the directions. The first step is to get Visual Studio to put the project file and source files into a directory called “src” instead of a directory with the project name. The first step is to open the common.js file located in “C:\Program Files\Microsoft Visual Studio .NET 2003\VC#\VC#Wizards\1033” (I am assuming you have Visual Studio 2003 and installed it in the default directory). ** disclaimer: backup these files before altering them. I will not be responsible for anyone hosing their Visual Studio install ** Go to line 439 in the file, it should read “// Make sure user sees ui.” and should be in the function called CreateCSharpProject. Insert the following lines of code before this line and in the try block:
// Only put in src directory if this isn't a web project
if(strProjectPath.search("http://") != 0)
strProjectPath = strProjectPath + "\\src";
Save that file and close your editor. The next step is to change the default build directories for debug and release builds in the various CSharp project templates. In order to that, change the OutputPath for the debug build from ".\Bin\Debug" to "..\test". And change the OutputPath for the release build from ".\Bin\Release" to "..\bin". The OutputPath is changed in the following files (located in the "C:\Program Files\Microsoft Visual Studio .NET 2003\VC#\VC#Wizards” folder):
- default.csproj
- DefaultDll.csproj
- DefaultWinExe.csproj
I should probably say that this is probably not supported by Microsoft as I am changing the directory structure pretty significantly. In closing, I think it is pretty cool that Visual Studio is extensible enough for this to be done. I was getting kind of disappointed, thinking that I was going to have to give up and play the way Microsoft wants me to play. So, three cheers for Microsoft for all the hard work put into this product. I look forward to seeing where Orcas goes when it is released.