VS 2008 C#:在同一解决方案中的另一个类库中无法访问类库

时间:2023-01-17 10:22:58

I have a solution in VS 2008 which has one web project and 3 Class libraries as 3 different Projects. One project is for DataAccess and one is for BusinessLogic.

我在VS 2008中有一个解决方案,它有一个Web项目和3个类库作为3个不同的项目。一个项目用于DataAccess,一个用于BusinessLogic。

I have a class in DataAccessLayer. From there when I am trying to access the Class of BusinessLogic class library (project) it is not coming in the IntelliSense when I type. I used the same namespace in both projects. Still same results.

我在DataAccessLayer中有一个类。从那里,当我尝试访问Class of BusinessLogic类库(项目)时,当我键入时,它不会进入IntelliSense。我在两个项目中使用了相同的命名空间。结果仍然相同。

Do I need to to create DLLs for the first project and add as reference to second?

我是否需要为第一个项目创建DLL并添加为第二个项目的引用?

4 个解决方案

#1


You need to add reference to this project in another project in your soultion. Visual studio has an option to add project as a reference, so you don't have to add assembly files directly

您需要在灵魂中的另一个项目中添加对此项目的引用。 Visual Studio有一个选项可以添加项目作为参考,因此您不必直接添加程序集文件

#2


You need to reference the library in the other projects.

您需要在其他项目中引用该库。

To do that, right-click the references folder in the Solution Explorer, click Add Reference, go to the Projects tab, and select the library that you want to reference.

为此,右键单击解决方案资源管理器中的references文件夹,单击“添加引用”,转到“项目”选项卡,然后选择要引用的库。

EDIT: Also, make sure that the class you are trying to use is declared as public (eg, public class MyClass).

编辑:此外,请确保您尝试使用的类声明为公共(例如,公共类MyClass)。

If you leave out the public modifier (which is the default), the class will only be usable in its project. To expose classes and members to other projects, add the public modifier to their declaration

如果省略public修饰符(这是默认值),则该类只能在其项目中使用。要将类和成员公开给其他项目,请将public修饰符添加到其声明中

#3


You'll need to add a reference to the project containing the BusinessLogic class in the DataAccess project. Otherwise, the compiler doesn't have anyway of finding the implementation of your BusinessLogic class, even if it does use the same namespace.

您需要在DataAccess项目中添加对包含BusinessLogic类的项目的引用。否则,编译器无论如何都无法找到BusinessLogic类的实现,即使它确实使用了相同的命名空间。

#4


This may sound silly, but have you specified the class in question as Public or Friend? They'll need to be "shared" in that sense in order to be properly picked up and used within the other applications, even when the project reference is specified.

这可能听起来很愚蠢,但您是否将该课程指定为公共或朋友?在这种意义上,它们需要“共享”才能在其他应用程序中正确地拾取和使用,即使指定了项目引用也是如此。

#1


You need to add reference to this project in another project in your soultion. Visual studio has an option to add project as a reference, so you don't have to add assembly files directly

您需要在灵魂中的另一个项目中添加对此项目的引用。 Visual Studio有一个选项可以添加项目作为参考,因此您不必直接添加程序集文件

#2


You need to reference the library in the other projects.

您需要在其他项目中引用该库。

To do that, right-click the references folder in the Solution Explorer, click Add Reference, go to the Projects tab, and select the library that you want to reference.

为此,右键单击解决方案资源管理器中的references文件夹,单击“添加引用”,转到“项目”选项卡,然后选择要引用的库。

EDIT: Also, make sure that the class you are trying to use is declared as public (eg, public class MyClass).

编辑:此外,请确保您尝试使用的类声明为公共(例如,公共类MyClass)。

If you leave out the public modifier (which is the default), the class will only be usable in its project. To expose classes and members to other projects, add the public modifier to their declaration

如果省略public修饰符(这是默认值),则该类只能在其项目中使用。要将类和成员公开给其他项目,请将public修饰符添加到其声明中

#3


You'll need to add a reference to the project containing the BusinessLogic class in the DataAccess project. Otherwise, the compiler doesn't have anyway of finding the implementation of your BusinessLogic class, even if it does use the same namespace.

您需要在DataAccess项目中添加对包含BusinessLogic类的项目的引用。否则,编译器无论如何都无法找到BusinessLogic类的实现,即使它确实使用了相同的命名空间。

#4


This may sound silly, but have you specified the class in question as Public or Friend? They'll need to be "shared" in that sense in order to be properly picked up and used within the other applications, even when the project reference is specified.

这可能听起来很愚蠢,但您是否将该课程指定为公共或朋友?在这种意义上,它们需要“共享”才能在其他应用程序中正确地拾取和使用,即使指定了项目引用也是如此。