BradleyB's WebLog

  • Tips to optimize design-time build performance for Web Sites in Visual Studio 2005

    Move App_Code files into a separate class library project
    I'm repeating this tip because even if you don't change the default build options you can improve build performance by moving the files from App_Code into a separate class library project.

    Check for conflicting dependencies
    If you do have conflicting dependencies, the web site project will do a full clean rebuild on every build even if only a page changes.  The problem is when you add a file based references that have a common dependency but to different versions of that dependency.   A file based references have a .dll.refresh file in the bin folder.  The .refresh file has the path to the original assembly.  These paths are checked on every build.

    In this example we have two assemblies, A.dll and B.dll both dependent on Foo.dll.

        A.dll -> dependent on Foo.dll
        B.dll -> dependent on Foo.dll

    When A.dll is refreshed the project system will discover the dependency on Foo.dll and copy it into bin. Likewise when B.dll is refreshed Foo.dll will be copied if different than the one already in bin. The problem is that when a class library is built by a class library project in VS it caches the dependencies. So as you can see here Class Libraries A and B both have a private copy of Foo.

    ClassLibraryA
        A\bin\debug\A.dll
        A\bin\debug\Foo.dll

    ClassLibraryB
        B\bin\debug\B.dll
        B\bin\debug\Foo.dll

    ClassLibraryFoo
        Foo\bin\debug\Foo.dll

    If ClassLibraryFoo is updated and only ClassLibraryB is recompiled then ClassLibraryB has a updated copy for Foo.dll but ClassLibraryA does not. When the web project is built, the refresh of A is copying in it's copy of Foo and the refresh of B is copying in it's copy. Each time Foo is copied because it's different than the one already in bin.

    Because the bin is changing with every VS build the ASP.Net compilation cache is invalidated forcing a full build.  Thus every build is a full build.

    To fix this problem do one of the following: