简体   繁体   English

在C#中使用第三方代码

[英]Use third party code in C#

I would like to use the following code in my program ( http://sshnet.codeplex.com/ ) SFTP 我想用下面的代码在我的程序( http://sshnet.codeplex.com/SFTP

I downloaded it and put into the same folder where my C# project is. 我下载了它,并将其放入C#项目所在的文件夹中。 I aslo added code: 我也添加了代码:

using Renci.SshNet;
using Renci.SshNet.Sftp;

Now I need to tell Visual Studio where to look for it. 现在,我需要告诉Visual Studio在哪里寻找它。 I tried "Add Reference", but what I downloaded contains only files with extension .cs no .dll. 我尝试了“添加引用”,但是下载的文件仅包含扩展名为.cs而不是.dll的文件。

What do I do next? 接下来我该怎么办?

I read a couple of books about C# (By Troelsen and Michaelis), but all this assebly business is not clear to me. 我读过几本有关C#的书(由Troelsen和Michaelis撰写),但是所有这些繁琐的业务对我来说都不是很清楚。

Instead of downloading the source (the link entitled SshSource ), try a binary link (either the 4.0 or 3.5, depending on what .NET CLR version you are targeting). 而不是下载源代码(名为SshSource的链接), SshSource尝试使用二进制链接(4.0或3.5,具体取决于您要定位的.NET CLR版本)。

The binary links will provide dlls. 二进制链接将提供dll。 Then, you can use Add Reference to link the dll in your project. 然后,您可以使用“ Add Reference来链接项目中的dll。

Binary distributions are what 3rd-party projects make available for use. 二进制发行版是第三方项目可使用的。 These are usually versioned by the project and stabilized before large public release. 这些通常由项目进行版本控制,并在大规模公开发布之前稳定下来。 These distributions give you the most stable component to use. 这些发行版为您提供了最稳定的组件。

The source distribution provides all the source files. 源代码分发提供了所有源文件。 You can use/modify the source (depending on the license), however, this requires you to compile before use. 您可以使用/修改源(取决于许可证),但是,这需要您在使用之前进行编译。

NuGet is a great way to use and manage packages for .NET. NuGet是使用和管理.NET软件包的好方法。 SSH.NET also has a NuGet Package . SSH.NET也有一个NuGet软件包 If you use NuGet, this would be the preferred way to consume the binary distribution. 如果使用NuGet,这将是使用二进制分发的首选方法。

Compile the code in order to get an assembly (.dll/.exe file). 编译代码以获取程序集(.dll / .exe文件)。 Then use "Add Reference". 然后使用“添加参考”。 Good luck! 祝好运!

The source contains a .csproj . 源包含一个.csproj Just add the project to your solution and then Add Reference > Solution > Projects 只需将项目添加到您的解决方案中,然后Add Reference > Solution > Projects

Instead of downloading source code, you need a compiled dll assembly, which can be found on Downloads tab. 除了下载源代码,您还需要一个已编译的dll程序集,该程序集可在“下载”选项卡上找到。 Grab either 'SshNet 4.0 Binary' or 'SshNet 3.5 Binary' depending on .NET Framework version you're using. 根据您使用的.NET Framework版本,获取“ SshNet 4.0 Binary”或“ SshNet 3.5 Binary”。

All the other steps you mentioned are correct. 您提到的所有其他步骤都是正确的。

I would use nuget to download and install this package within visual studio. 我将使用nuget在Visual Studio中下载并安装此软件包。 Looks like they have a package for it. 看起来他们有一个包装。

https://www.nuget.org/packages/SSH.NET/ https://www.nuget.org/packages/SSH.NET/

If you are not familiar with NuGet it is a package management system for visual studio that will automatically download and install the references for you. 如果您不熟悉NuGet,则它是Visual Studio的软件包管理系统,它将自动为您下载并安装参考。 Check it out here: 在这里查看:

https://www.nuget.org/ https://www.nuget.org/

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

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