How do I use a C# Class Library in a project?

后端 未结 9 1900
北恋
北恋 2020-11-28 05:23

I\'ve created a new Class Library in C# and want to use it in one of my other C# projects - how do I do this?

相关标签:
9条回答
  • 2020-11-28 05:56

    There are necessary steps that are missing in the above answers to work for all levels of devs:

    1. compile your class library project
    2. the dll file will be available in the bin folder
    3. in another project, right click ProjectName and select "Add" => "Existing Item"
    4. Browser to the bin folder of the class library project and select the dll file (3 & 4 steps are important if you plan to ship your app to other machines)
    5. as others mentioned, add reference to the dll file you "just" added to your project
    6. as @Adam mentioned, just call the library name from anywhere in your program, you do not need a using statement
    0 讨论(0)
  • 2020-11-28 05:58

    Add it as a reference.

    References > Add Reference > Browse for your DLL.

    You will then need to add a using statement to the top of your code.

    0 讨论(0)
  • 2020-11-28 05:59

    I'm not certain why everyone is claiming that you need a using statement at the top of your file, as this is entirely unnecessary.

    Right-click on the "References" folder in your project and select "Add Reference". If your new class library is a project in the same solution, select the "Project" tab and pick the project. If the new library is NOT in the same solution, click the "Browse" tab and find the .dll for your new project.

    0 讨论(0)
提交回复
热议问题