简体   繁体   English

将ac#库项目添加到我的项目中以及如何使用它

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

i have c# library project. 我有C#库项目。 i add it (library.sln) as a existing project to my project. 我将它(library.sln)作为现有项目添加到我的项目中。 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; 但是在我尝试访问它的表单中,似乎using library;不存在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 : 当我尝试调试项目时,无法在Visual Studio中自行构建,错误是:

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. 您可以在此处http://www.codeproject.com/KB/selection/FarsiLibrary.aspx?msg=4043318#xx4043318xx看到图书馆项目,它有4个命名空间。

  1. Do not add an .sln to another solution. 不要将.sln添加到另一个解决方案中。 Add the Project (.csproj) instead. 添加项目(.csproj)。
  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. 创建一些可运行的项目(例如Condole应用程序)以使用您的库并将其设置为启动项目。 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. 即使将项目添加到解决方案中,也必须为WinForms项目添加对该项目的引用。 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. 如果您的WinForms使用.NET 4客户端配置文件,并且库需要.NET Full,则您将无法访问它,而需要更改WinForms项目以使用完整的.NET 4运行时。

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

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

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