开发者

How do I add a reference to a Web Application Project in an Associated Class Library?

开发者 https://www.devze.com 2022-12-30 08:18 出处:网络
I\'m w开发者_StackOverflow社区orking on an internet application that has been set up as a web SITE project (I know...) in Visual Studio. I need to add additional features/functionality so have added a

I'm w开发者_StackOverflow社区orking on an internet application that has been set up as a web SITE project (I know...) in Visual Studio. I need to add additional features/functionality so have added a class library to the project and referred to it in the main web site project.

The issue now arises because I need to make use of core objects which live inside the App_Code directory in the web site project but this project doesn't appear to expose its DLL like web app/ code library projects do. Because of this I can't add a reference to the web site project in the class library to leverage the common site-wide code/objects.

I can't move the stuff out of App_Code so I'm looking for a way to refer to the website project dll from the new class library. Can anyone suggest a workaround? All help v. gratefully received :-)


You won't be able to do that. It would create a circular reference.

I'm curious as to why you can't move stuff out of App_Code. The "proper" way to do what you need would be to create a 3rd "shared" library with the classes that need to be used both in the web site and in the new library, and reference it from both.


I would move any of the classes in your web site's App_Code directory into the new class library assembly. If you have common functionality that is not specific to that we site (which it sounds like you have if you want to make a reference to that code from the class library), the proper place to keep these classes is in this common repository anyway. If you keep them in the same namespace, the code should recompile just fine.


You can tell visual studio tu generate fixed name assembly for your web site code and reference it.

Anyway IMHO it's a bad (really bad) practice to do such things on your projects, since it would generate a circular reference. Why can't you move your app_code out of the webapp project?

0

精彩评论

暂无评论...
验证码 换一张
取 消