Thursday, April 14, 2005

File System Web Site reference issues in Visual Studio 2005 February CTP

Assume you are working on the following Foo application:



You've used Visual Studio 2005 to add a reference from FooServiceLayer to FooDomainLayer and from FooWebSite to FooServiceLayer.

Your classes are defined as such:







You build your solution in Visual Studio 2005 and no errors are reported. Then the fun begins.

If you try to browse to default.aspx you will get the following error:

Server Error in '/FooWebSite' Application.
Could not load file or assembly 'FooDomainLayer, Version=1.0.1929.14480, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.

Since FooWebSite depends on FooServiceLayer which depends on FooDomainLayer the FooDomainLayer.dll must be in the Bin folder of FooWebSite. This is nothing new from 1.1, except that Visual Studio 2005 no longer does it for you. To fix this issue you can add a Post Build Event by right clicking on FooDomainLayer in the solution explorer, selecting properties, then selecting Build Events from the menu that appears. Add a post build event command such as:



Note: your path may be different; therefore, assume you are in the folder where FooDomainLayer.dll is located and adjust your copy path.

Rebuild and browse to default.aspx and you will see "The method or operation is not implemented.", the exception from the Domain Layer you expected.

If you are using source control and continuous integration you should add the Bin folder of FooWebSite but ignore the contents of it and add a post build event to FooServiceLayer to copy FooServiceLayer.dll into the Bin folder of FooWebSite. While Visual Studio 2005 does copy the dll of a referenced project into the Bin folder of FooWebSite, MSBuild will not do this for you and your build will break.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.