简体   繁体   中英

Add references to web project from a class library

I have a class library that have folder Called "Resources" that's our convention of keeping the DLL that need to be referenced.

So there are some base DLL that are added in it.Lets name them as "BaseWork.dll".

I have a web project in the same solution that have this class library. I have added the reference of Class library in the Web project. I want to access some class through this "BaseWork.dll" in the code behind of some aspx page. I am not able to access it.

There is an easiest way to do this is Add the Resource folder for our convention Sake , add the "BaseWork.dll" to it. Then add the reference in the Web-project . That would be repetition of the same things across the solution.

Is there any better way to do this?

PS: I am working in .net framework 4.0 in Visual studio 2010.

I want to access some class through this "BaseWork.dll" in the code behind of some aspx page

2 things to do in your web.config:

  1. Add the assembly to the <assemblies> section:

     <compilation debug="true" targetFramework="4.0"> <assemblies> <add assembly="BaseWork" /> </assemblies> </compilation> 
  2. Add the namespace containing the class you need to use to the <namespaces> section:

     <pages> <namespaces> <add namespace="BaseWork.SomeNamespace" /> </namespaces> </pages> 

Now inside any WebForm you will be able to use classes within the namespace you declared. As an alternative to modifying the web.config you could also reference it inside a specific WebForm:

<%@ Assembly Name="BaseWork" %>
<%@ Import Namespace="BaseWork.SomeNamespace" %>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM