简体   繁体   中英

Using a C# library

I've made a C# class library and am trying to use it in another project. I followed these instructions but am getting the following errors:

The type or namespace name 'TF2Reader' could not be found (are you missing a using directive or an assembly reference?)

The type or namespace name 'Log' could not be found (are you missing a using directive or an assembly reference?)

I'm copying the DLL to the project's own directory but when viewing the reference in the Object Browser there are no classes when expanded. Why is this library not loading?

The instructions in the page you linked to recommend that you browse to the compiled DLL for the library when adding the reference. I don't know why they would recommend that. It's weird. You should use that only if the compiled binary of the library is all you've got.

The normal, recommended practice is to add both projects (the library and the project that uses the library) to the same solution, so you can edit them both in Visual Studio together, and compile them together. Then, in the Add Reference dialog, instead of the Browse tab you use the Projects tab, which will list your library.

This way, your code will always know about all your up-to-date changes in the library. If you declare a new type in the library, you can immediately use it in the other project; no need to recompile the library first and make sure that DLL files are copied to the appropriate places etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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