TheChaseMan's Frenetic SoapBox

Always looking for better ways to do things...

UPDATE - ASP.NET 2.0: References and Bin

Two weeks ago I posted about how Visual Studio .NET 2005 automatically "references" assemblies added to the \Bin folder. I took the opportunity to ask about this issue in one of Scott Guthrie's blog posts and he was gracious enough to provide an answer.

Hi Sean,

The new web project system using the <assemblies> section within your web.config file to control references and assembly load behavior. One nice aspect of this is that it unifies the development time and runtime settings into one so that you always get consistent results.

By default (since ASP.NET V1) there was been a reference in the root machine.config to * compile and load all assemblies in the \bin directory. You can override this behavior, though, in your app's web.config. Just clear this entry and manually specify the assemblies you want VS 2005 and ASP.NET to reference and use automatically. You can then use Assembly.Load to manually load others based on your own algorithm.

Hope this helps,

Scott

So basically I was able to test this out by creating a Web app and a class lib called "MathLib." I added the following to the Web.config...

<compilation debug="true">
 <assemblies>
    <remove assembly="MathLib" />
 </assemblies>
</compilation>

...and MathLib was no longer available for intellisense as expected. You could also do a <remove assembly="*"> and manually add references. By manually adding references, that doesn't mean you have to type anything into the Web.config yourself. I tried adding a reference by right-clicking on the Web project and then clicking the Add Reference menu option and set a reference to System.Drawing and Visual Studio automatically added the item for me...

<compilation debug="true">
 <assemblies>
  <remove assembly="*"/>
  <add assembly="System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/></assemblies>
</compilation>


Digg!

posted on Sunday, August 14, 2005 5:31 PM

Feedback

No comments posted yet.