Chapter 5: Creating and Building Projects

131

Normally, a full rebuild ensures that you have the most up-to-date outputs available. You could also perform a clean operation to ensure all outputs were removed and then perform a build to see which outputs were created. This might give you insight into whether the build on a solution was including all of the projects. In normal circumstances, VS manages all of your dependencies for you, as described in the next section. However, in advanced scenarios, some developers might occasionally change these dependencies. Cleaning is a tool to help you know whether a project is really being built. From a practical perspective, this is rare and you could inspect file dates to tell the same thing, but cleaning is another path you can take.

A more common use of clean is to remove outputs from the project to make it smaller. You might want to compress a project or solution and e-mail it to another person, requiring that you minimize the size of the attachment. While code files normally compress very well, *.dll and *.exe files can take up some file space, even when added to a compressed file. If you perform a clean before compressing the files, you will use much less file space.

Managing Dependencies and Build Order

A dependency describes to VS which other projects a given project depends on to operate properly. For the example in this chapter, the ProjectDemo project references ClassLibraryDemo and uses the code in ClassLibraryDemo. Therefore, ProjectDemo has a dependency on ClassLibraryDemo. VS adds this dependency automatically, which is good because when VS builds your solution, it will keep all projects up-to-date. VS manages a tree of dependencies. Whenever you perform a rebuild, VS looks at the dependency tree and builds all projects that don’t have dependencies. Then, VS builds all projects that depend on the last set of projects that were rebuilt. This process continues until the entire solution is rebuilt and all projects at the top of the tree reference updated versions of all referenced projects.

You can manually manage dependencies by right-clicking a project or the solution in Solution Explorer and selecting Project Dependencies. Figure 5-8 shows the Project Dependencies window.

In the Project Dependencies window, you can select (from the drop-down list) the project to set dependencies upon. There is a list of projects that you can set dependencies on. As shown in Figure 5-8, the ProjectDemo project has a dependency on ClassLibraryDemo. VS created this dependency automatically.

Project dependencies directly affect the build order of a project. If you recall from the previous discussion, projects that have dependencies upon them will be built before the depending projects. From the Project Dependencies window, shown in Figure 5-8, you can click the Build Order tab to manage the order of the build. You could also get to the Build Order tab by right-clicking a project or the solution in Solution Explorer and selecting Project Build Order. You can see the Build Order tab in Figure 5-9.

Page 154
Image 154
Microsoft 9GD00001 manual Managing Dependencies and Build Order, 131