vb.net VB无法访问来自不同项目的类,相同的解决方案
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21390395/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
VB Cannot access class from different project, same solution
提问by user3195786
I am working in VB for Visual Studio and have a class in a project that needs to declare a variable as a class in another project. For visualization: Solution A contains Project1 and Project2. In a class in Project1 I need to declare a variable as a classname of Project2. The class I need to access is a Friend class and I know I have to do something involving Imports, declarations, references, and maybe class libraries. If anyone can spell this out for me I'd appreciate it. I'm new to VB.
我在 VB for Visual Studio 中工作,并且在需要将变量声明为另一个项目中的类的项目中有一个类。对于可视化:解决方案 A 包含 Project1 和 Project2。在 Project1 中的一个类中,我需要将一个变量声明为 Project2 的类名。我需要访问的类是 Friend 类,我知道我必须做一些涉及导入、声明、引用和类库的事情。如果有人能为我拼出这一点,我将不胜感激。我是 VB 新手。
回答by jessehouwing
A friend class can only be accessed from the same assembly, unless you muck around with the InternalsVisibleToattribute. If these assemblies are not declared as "Friend Assemblies" you need to make the class public. Given you're beginning to learn VB.NET I'd stick with making the class public.
朋友类只能从同一个程序集中访问,除非您使用InternalsVisibleTo属性。如果这些程序集未声明为“朋友程序集”,则需要将类设为公开。鉴于您开始学习 VB.NET,我会坚持公开课程。
You also need to add a project reference from Project1 to Project2. In the solution explorer right click "References" and choose Add Referencein the dialog that pops open, select "Solution"/"Project" and select Project2.
您还需要添加一个从 Project1 到 Project2 的项目引用。在解决方案资源管理器中右键单击“参考”并Add Reference在弹出的对话框中选择“解决方案”/“项目”并选择 Project2。

