简体   繁体   English

如何在关联类库中添加对Web应用程序项目的引用?

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

I'm working on an internet application that has been set up as a web SITE project (I know...) in Visual Studio. 我正在开发一个Internet应用程序,该应用程序已在Visual Studio中设置为Web SITE项目(我知道...)。 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. 现在出现该问题是因为我需要利用位于网站项目的App_Code目录中的核心对象,但是该项目似乎不像Web应用程序/代码库项目那样公开其DLL。 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. 我无法将这些内容移出App_Code,因此我正在寻找一种从新类库引用网站项目dll的方法。 Can anyone suggest a workaround? 谁能建议解决方法? All help v. gratefully received :-) 所有帮助v。非常感谢:-)

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. 我很好奇为什么您不能将内容移出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. 我会将您网站的App_Code目录中的任何类移到新的类库程序集中。 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. 您可以告诉Visual Studio Tu为您的网站代码生成固定名称程序集并对其进行引用。

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? 为什么无法将app_code移出webapp项目?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何获得对 class 库项目的引用才能工作? - How do I get a reference to a class library project to work? 如何在ASP Net Core项目中添加类库项目的引用 - How to add reference of class library project in asp net core project 如何公开由类库引用的类库,该类库随后作为项目引用包含在Visual Studio中? - How do I expose class libraries referenced by a class library, which is then included as a project reference in Visual Studio? 如何从C#可移植类库(PCL)添加对F#可移植库的引用 - How do I add a reference to F# Portable Library from C# Portable Class Library (PCL) 如何将.NET类库的引用添加到vNext项目 - How to add a reference of a .NET class library to a vNext Project 如何在.NET核心类库中引用Visual Studio共享项目 - How do I reference a Visual Studio Shared Project in a .NET Core Class Library 如何从Webforms Web应用程序项目中使用Razor类库 - How to use Razor Class Library from a Webforms Web Application Project 如何在SQL CLR项目中添加C#类库/类dll? - How do I add c# class library/ class dll in SQL CLR project? 如何在我的项目中添加对库的引用? - How can I add a reference to a library to my project? 为什么我们需要将类库项目继承的程序集的引用添加到使用者项目中? - Why do we need to add a reference to an assembly, from which a class library project inherits, into a consumer project?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM