简体   繁体   中英

add a c# library project to my project and how to use it

i have c# library project. i add it (library.sln) as a existing project to my project. so it comes to my solution explorer.

but in my forms when i try to access it, it seems it dose not exist using library; is noting ! where am i wrong, and what i need to do ?

it can not be build itself in visual studio when i try to debug project, the error is :

a project with an output type of class library can not be started directly

you can see the library project here http://www.codeproject.com/KB/selection/FarsiLibrary.aspx?msg=4043318#xx4043318xx and it have 4 namespace.

  1. Do not add an .sln to another solution. Add the Project (.csproj) instead.
  2. When 2 projects are in the same solution there still is no link by default. Use Add Reference in the importing project.
  3. Set an executable project as the Startup project.

You need to use the "Set as StartUp Project" option in your context menu to set a runnable project. The project "library" you created is probably a class library which is not runnable.

Create some runnable project eg Condole application to use your library and set that as startup project. Then run your project.

A library is just a collection of classes, interfaces, enums etc.. In order to debug it, you'll probably want to create a console application that calls methods on your classes that you want to debug.

In addition, just adding the library to the solution is not enough for other libraries to be able to see them. In order to do this, you have to add it as a reference. You can do this by right clicking on the References item in your project, then Add Reference.

右键单击您的引用文件夹,按“添加引用”,切换到“项目”,然后将引用添加到您的库项目中。

Even if you add the project to your solution, you have to add a reference to that project for the WinForms project. This has nothing to do with the library.

If your WinForms uses .NET 4 Client Profile and the library requires .NET Full, then you can't access it and need to change the WinForms project to use the full .NET 4 runtime.

已经有了不错的答案,但我也建议您创建一个Test项目,作为调试库的更有效方法。

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