VB无法访问来自不同项目的类,相同的解决方案 [英] VB Cannot access class from different project, same solution

查看:34
本文介绍了VB无法访问来自不同项目的类,相同的解决方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 VB for Visual Studio 中工作,并且项目中有一个类需要将变量声明为另一个项目中的类.对于可视化:解决方案 A 包含 Project1 和 Project2.在 Project1 中的一个类中,我需要将一个变量声明为 Project2 的类名.我需要访问的类是 Friend 类,我知道我必须做一些涉及导入、声明、引用和类库的事情.如果有人能为我拼出这一点,我将不胜感激.我是 VB 新手.

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.

推荐答案

朋友类只能从同一个程序集中访问,除非您使用 InternalsVisibleTo 属性.如果这些程序集未声明为朋友程序集",则需要将类设为公开.鉴于您开始学习 VB.NET,我会坚持公开课程.

A friend class can only be accessed from the same assembly, unless you muck around with the InternalsVisibleTo attribute. 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.

您还需要将项目引用从 Project1 添加到 Project2.在解决方案资源管理器中右键单击引用"并在弹出的对话框中选择 添加引用,选择解决方案"/项目"并选择 Project2.

You also need to add a project reference from Project1 to Project2. In the solution explorer right click "References" and choose Add Reference in the dialog that pops open, select "Solution"/"Project" and select Project2.

这篇关于VB无法访问来自不同项目的类,相同的解决方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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