引用应用程序项目的类项目 [英] class project referencing to application project

查看:107
本文介绍了引用应用程序项目的类项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个名为DAL的项目,其中包含用于访问数据的Class文件和另一个Web应用程序项目(在同一个sln文件中)以使用上述class项目.我的班级项目需要从配置文件中获取连接字符串,然后建立连接.

我将对我的班级项目文件的引用添加到我的应用程序项目文件中,并添加了

使用System.Data.SqlClient;
使用System.Configuration; "

仍然无法访问我的应用程序项目中的类文件.您能看看还有什么遗漏吗?

我应该从类向应用程序添加引用还是以其他方式添加?

I have created a project called DAL with Class file for accessing data and another web application project (inside same sln file)to consume the above mentioned class project. my class project needs to take connection string from config file and then establish the connection.

i add a reference on my class project file to my application project file and added

"using System.Data.SqlClient;
using System.Configuration; "

still im unable to access my class file inside my application project. Can you please see what else is missing?

should i add reference from class to application or is it the other way??

推荐答案

您显示的名称空间可能与您引用的自己的项目无关.您是否在这些名称空间之一下放置了自己的课程?如果不是,则这些uses子句无关.

将.NET库添加到其他项目时,请在解决方案资源管理器"树上双击引用.您将能够浏览反映的参考装配件.您看到您想要使用的班级及其成员了吗?如果不是,请检查是否对需要使引用程序集可访问的每种类型和成员使用public访问说明符.当您需要的所有声明均可用时,请使用具有完全限定名称(包括其名称空间名称)的声明.或添加using声明(适当的声明).

—SA
They name spaces you show probably has nothing to do with your own project you reference. Did you put your own class under one of these name spaces? If not, these uses clauses are irrelevant.

When you add your .NET library to your other project, double click your reference on the Solution Explorer tree. You will be able to browse reflected referenced assembly. Do you see your class and its members you want to use? If not, check up if you use public access specifier for each type and member you need to make accessible to referencing assembly. When all declarations you need are available, use your declarations with fully-qualified names including their name space names. Or add using declarations, appropriate ones.

—SA


您需要向应用程序项目添加类项目引用.
另外,请确保您的课程是public 而不是internal.
You need to be adding a class project reference to the application project.
Also, make sure your class is public and not internal.


这篇关于引用应用程序项目的类项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆