简体   繁体   English

在C#中构建类库项目

[英]Building class library project in C#

I am working on a existing c# class library project. 我正在开发一个现有的c#类库项目。 I want to add few more class to it. 我想为它添加更多的课程。 This is then used in a new project. 然后将其用于新项目。 I have added the required classes to the existing typelib project, but when I refer the typelib in the next project and try to access the newly added methods it showing error 我已将所需的类添加到现有的typelib项目中,但是当我在下一个项目中引用typelib并尝试访问新添加的方法时,它显示错误

The type or namespace name 'abc' does not exist in the name space xyz.TypeLib.core (are you missing assembly reference) 名称空间xyz.TypeLib.core中不存在类型或命名空间名称'abc'(您是否缺少程序集引用)

but I can access all those classes which existed previously in that project. 但我可以访问之前在该项目中存在的所有类。 I am having issue with newly added files. 我遇到了新添加文件的问题。

Here are the steps I did, 这是我做的步骤,

  1. added new classes to the existing project. 在现有项目中添加了新类。
  2. Build the project 建立项目
  3. Added dll to next project from the bin folder of the class library project 从类库项目的bin文件夹中将dll添加到下一个项目

Also, as a test I also tried adding a new method in one of the classes which I can access, but this method is not avaiable! 另外,作为测试,我也尝试在我可以访问的其中一个类中添加一个新方法,但是这个方法不可用!

How can I do this properly? 我该怎么做呢?

1.) Make sure you have added the correct DLL to the project. 1.)确保已将正确的DLL添加到项目中。 Therefore, clean the library project, build it, and use that DLL. 因此,清理库项目,构建它,并使用该DLL。

2.) (this will most likely be the problem): In Visual Studio, click on the DLL and in the properties, make sure that "Copy to output directory" is set to "Copy if newer". 2.)(这很可能是问题):在Visual Studio中,单击DLL并在属性中,确保“复制到输出目录”设置为“如果更新则复制”。

3.) Re-add the reference to the file. 3.)重新添加对文件的引用。

4.) Clean and then build again your new project that uses the library. 4.)清理然后再次构建使用该库的新项目。

If the two projects are in the same Visual Studio Solution, the correct approach is to add the class library project directly as a reference. 如果这两个项目在同一个Visual Studio解决方案中,那么正确的方法是直接添加类库项目作为参考。 This will bypass any possible dll mismatching that can be caused by other approaches. 这将绕过可能由其他方法引起的任何可能的dll不匹配。

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

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