简体   繁体   English

如何运行添加到VB.NET现有解决方案中的C#类库?

[英]How to run C# class library which is added to VB.NET existing solution?

Hi I have console application which is written in VB.NET. 嗨,我有用VB.NET编写的控制台应用程序。 For this I added c# class library with existing solution. 为此,我在现有解决方案中添加了c#类库。 I wrote code in c# class library. 我在c#类库中编写了代码。 Now when I try to run, it is going to VB.NET console application by default. 现在,当我尝试运行时,默认情况下它将进入VB.NET控制台应用程序。 I am not able to run my c# class library. 我无法运行我的C#类库。

For clear understanding lets call VB.NET project as classVB and class library as classC# 为了清楚理解,我们将VB.NET项目称为classVB,将类库称为classC#

I tired these methods to make it work : 我厌倦了这些方法来使其工作:

1) Added classC# reference to my classVB project and made classVB as startup project. 1)在我的classVB项目中添加了classC#引用,并将classVB作为启动项目。 I used using statement also to refer to my classVB project as Using classVB . 我还使用using语句将我的classVB项目称为Using classVB And I put break point in my classC#.But still it is pointing to classVB project 我在classC#中放置了断点,但仍然指向classVB项目

2) Tried to made classC# as startup project( Even I knew this doesn't gonna work). 2)试图将classC#设为启动项目(甚至我都知道这行不通)。 For this I am getting usual error which says " A project with an output Type of class library cannot be started directly ." 为此,我遇到了通常的错误,该错误是“ 无法直接启动具有类库输出类型的项目 ”。

3) Right click on solution and start up project option -> Single startup project and selected classVB. 3)右键单击解决方案并启动项目选项->单个启动项目,然后选择classVB。

But none of this is working. 但是,这些都不起作用。 It is always pointing to my classVB project even after I put breakpoint on c#class library code. 即使将断点放在c#class库代码上,它也始终指向我的classVB项目。

Its the first time I am working on library class, so any help on this would be appreciated. 这是我第一次从事图书馆课程工作,因此对此提供的任何帮助将不胜感激。

You can't directly run a class library. 您不能直接运行类库。 It is not executable. 它不是可执行文件。 You can reference the code from it in your VB project, but a class library can never run by itself. 您可以在VB项目中引用其中的代码,但是类库永远不能单独运行。 To access a public method in your class library from VB, refer to it by Namespace.ClassName.MethodName . 若要从VB访问类库中的公共方法,请通过Namespace.ClassName.MethodName对其进行引用。

Change the compilation output of the library to the same path where you added the reference in the VB.NET application. 将库的编译输出更改为在VB.NET应用程序中添加引用的路径。 Generate the library and check the build is successful. 生成库并检查构建是否成功。

Do not forget to change the library class to configuration debug in the solution to generate the PDB file that will allow you debugging. 不要忘记在解决方案中将库类更改为配置调试 ,以生成允许您调试的PDB文件。 Put a breakpoint and try again. 设置一个断点,然后重试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM