添加项目参考 [英] Add reference to project

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

问题描述


我在同一解决方案下有两个项目文件夹.一个是ChatServer,另一个是ChatClient.在ChatServer项目中,有两个.cs文件和一个.cs文件一起自动生成,另外一个.cs文件由我添加,称为ChatServerClass.cs.现在如何从我的ChatClient项目中添加对此ChatServerClsss.cs的引用.如果右键单击以添加引用,我会得到ChatServer引用,而不是chatserverclass.我该怎么做请帮助

Hi
I have two project folders under the same solution. One is ChatServer and other is ChatClient. In ChatServer project in have two .cs file one generated automatically along with form and other .cs file is added by me called ChatServerClass.cs. Now how to add reference to this ChatServerClss.cs from my ChatClient project. If right click go to add reference i get ChatServer reference but not chatserverclass. How can i do this pls help

推荐答案

您都需要添加对dll的引用.
完成后,包括该类的名称空间,并且该名称空间应可供使用(尽管类型的访问权限应为public ).
You all need to add a reference to the dll.
Once that is done, include the name space for the class and it should be available for use (the access of the type should have been public though).


您不能通过添加引用直接引用代码文件....但是,您可以通过:-
解决问题 1)创建新项目,选择类库模板选项
2)将ChatServer.cs文件的代码粘贴到该文件中
3)现在建立项目,它将为您提供.dll文件
4)现在回到您的主项目中添加引用....
选择浏览"选项卡并获取.dll文件
现在您需要使用dll文件中的名称空间
使用< namespace_in_dll_file>
现在您可以在项目中使用该类的功能

祝你好运.............
You can''t directly reference code files through Add Reference.... However you can solve your problem by :-
1)Create new project select class library template option
2)Paste code of ChatServer.cs file into this file
3)now Build the project It will give you the .dll file
4)Now back to your main project Add Reference....
Select Browse tab and get the .dll file
now you need to use the namespace in the dll file
using <namespace_in_dll_file>
Now you can use the class''s functionality in the project

Best of Luck.............


如果ChatServer是
添加引用 在文件顶部,将ChatServer导入为
Add the reference if ChatServer
on top of file import the ChatServer as
using ChatServer;


现在您可以在函数或方法中访问该类


and now you can access the class in the function or method

MyClass cls = new MyClass();
cls.propertyName



确保该类的访问修饰符为public



make sure the class has access modifier as public


这篇关于添加项目参考的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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