Use third party code in C# - c#

I would like to use the following code in my program (http://sshnet.codeplex.com/)SFTP
I downloaded it and put into the same folder where my C# project is. I aslo added code:
using Renci.SshNet;
using Renci.SshNet.Sftp;
Now I need to tell Visual Studio where to look for it. I tried "Add Reference", but what I downloaded contains only files with extension .cs no .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.

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).
The binary links will provide dlls. Then, you can use Add Reference to link the dll in your project.
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. SSH.NET also has a NuGet Package. If you use NuGet, this would be the preferred way to consume the binary distribution.

Compile the code in order to get an assembly (.dll/.exe file). Then use "Add Reference".
Good luck!

The source contains a .csproj. Just add the project to your solution and then Add Reference > Solution > Projects

Instead of downloading source code, you need a compiled dll assembly, which can be found on Downloads tab. Grab either 'SshNet 4.0 Binary' or 'SshNet 3.5 Binary' depending on .NET Framework version you're using.
All the other steps you mentioned are correct.

I would use nuget to download and install this package within visual studio. Looks like they have a package for it.
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. Check it out here:
https://www.nuget.org/

Related

Is my .csproj using the .NET project-system or the Common Project System

I was reading through the documentation on the .NET foundation's GitHub repository for the .NET project-system and saw that the latest system used to run C# projects on Visual Studio is the new Project System by default; however, as the older system, Common Project System (CPS), is being phased out what are some signs to help me discern which version of the Project System my project is using?
Is this determined by Visual Studio or will I be able to look at the .csproj file and know which system is being utilized to manage my projects?
I am not looking for the version of the .NET SDK but rather which project system is running my solution's file organization and project manifest.
Thanks to concise and enlightening comments from Jonathan Tyson and Ian Mercer there are a few ways to tell which version of Project System a solution is using.
1. As according to the Project System Documentation (link provided by Jonathan), you can tell based on the formatting of the project file.
In the project file, when the Target Framework is formatted like this:
net45
the project is using the new Project System. When formatted like this: v4.6.1
The project is utilizing the legacy Common Project System.
2. A quick way to tell without opening the project file is to right-click on the file and if you can select Edit .csproj without having to unload the project it is using the new Project System (provided by Ian).
Thank you guys for your insights!

Should I use NuGet or DLL reference?

I have a project in C# for usiversity. I want to use SQLite in it, but how should I include it, knowing that I will have to give my teacher the full VS2015 project folder ?
I also use 2 computers with github to transfer the sources.
Since I don't know a lot about NuGet or external library (DLL) reference with Visual Studio, i have no idea what I should use.
Will NuGet install SQLite in the project folder, or should I choose the DLL (from here), and put it in the project folder ?
Also on a side question, should I ignore the SQLite files when commiting ?
You should use NuGet, and yes you should add your packages folder to the .gitignore.
I'd definitely suggest NuGet as well. NuGet can be set to automatically restore the files when a new person builds. (Package Restore, by the way, just means that NuGet will download the necessary files automatically). That way you don't have to pass around DLLs. It also helps make sure that everyone's on the correct version.
In general, it's considered a bad practice to check executable code into source control if you can avoid it. Doing so can make it much more difficult to track history and version differences, for example.

PetaPoco core .cs file not visible in ASP.NET 5 Class Library package

I am building a new project in ASP.NET 5.
In my solution I have added a new Class Library (Package) project.
I right click on this project and choose for Manage Nuget packages to install PetaPoco.Core.
When I install everything seems fine except that the PetaPoco.cs file is not in my project.
In my references I se the PetaPoco version 5.1.171 installed.
Is this something different then a normal class library and do I need to use something else in order to use the installed PetaPoco class or is it a problem during the installation?
I have removed and reinstalled this but still the same.
Someone that can help me out?
/Michael
It looks like the PetaPoco.Core package isn't setup to be used in portable class libraries (PCLs).
Including content files in PCLs like the Models folder that PetaPoco.Core creates requires a different NuGet setup than a regular project. Documentation on this can be found on NuGet. I downloaded their package directly and can confirm that it is not setup in the way the linked resource describes.
It may be that the project requires features that are not available yet cross-platform, or they simply haven't had time to make changes to support PCLs, or some other reason that I am not aware of.
NuGet packages are usually installed as DLLs in the bin folder of your project, with the needed references also added automatically to the project. They usually don't include source files. You may find sources - if available - on the package/project website.
Visual Studio IntelliSense will pick up the DLLs and show what it can about the classes and methods inside, including comments and method signatures.
See here for a tutorial, including how to build your own NuGet packages.
EDIT: PetaPoco is the exception that does add a .cs file... see comment below.

Using/handling bitcoin in Unity3d game

I need to handle bitcoin in my unity project
I tried to install some nuget packages to support that
like this for example : https://github.com/blockchain/api-v1-client-csharp
but I always get this error
Could not install package 'BlockchainAPI 2.0.0'. You are trying to
install this package into a project that targets
'.NETFramework,Version=v4.0', but the package does not contain any
assembly references or content files that are compatible with that
framework. For more information, contact the package author.
unfortunately - no current unity3d plugins that support bitcoin yet
any suggestions , solutions ?
The plugin is using .NET version that is > Unity's supported .NET version.
The easiest solution I know about is to download the project directly from the link you posted.Delete any file that is NOT a C# file(.cs). Extract those folders with the remaining files and put them in your Unity project. Now look for errors. If you find any script with an error or script that uses C# 4 classes, modify it and fix the errors by hand.
This is easier than trying to implement your own bitcoin API from scratch.
NOTE: The only reason I recommend this method is because I looked inside the project and there were no DLL files inside it. So it is possible to port it if there is no DLL file in the API. Assuming there were DLL files compile with C# 4, then that would be a problem.
There's a beta edition of Unity that now supports a newer Mono version, which can let you compile .NET 4.5.2 (or older) projects.
I recommend you Nicolas Dorier's NBitcoin library for this then.

How do you install a Windows Runtime Component built in C++/CX into a C# project?

I have a library called foo, which is written in C++/CX. I chose a Windows Runtime Component because I want it to be projected into C#, C++ and JavaScript. Also, I want to be able to distribute the library, and I don't want to require/allow the consumer to load my project, along with the source files, in the same solution as their project.
The instructions on MSDN only demonstrate how to include the Windows Runtime Component project in a solution with the consuming C# project. I know there is a way to only distribute the binary, but I don't know how.
This question has been asked a thousand times, but the answer always has the two projects in the same solution, is incomplete or a workaround.
I'm using Visual Studio 2013.4 on Windows 8.1.
One way to do it is to create a VSIX package of your component. See Walkthrough: Creating an SDK using C++ that shows exactly how to do this with a WinRT component consumed by a C# project.
I researched and found the answer... It is not documented well, it is not intuitive, but it's worth the trouble when you see how well a Windows Runtime Component works.
Compiling the C++/CX library:
Make sure you compile the library for all permutations of Debug and Release, in Win32, ARM, x86 and x64.
Instructions for consuming in C#:
Right-click on References in the Solution Explorer, and add a reference to the Microsoft Visual C++ Runtime Package v12.0. Then add a reference to the binary you created with the appropriate configuration for your project (i.e. Debug/ARM). This step is tricky, because the file filter prompts you for the .dll, but you need to set the filter to *.* and select the .winmd file. Then you unload the project, find the <Reference> tag for the library you just added. <Reference> will have a <HintPath> tag below it, and under <Reference> you will also need to add <IsWinMDFile>true</IsWinMDFile> and an <Implementation> tag pair loaded with the name of the .dll that was sitting in the same folder as the .winmd file.
For more detailed instructions and information, I highly recommend visiting Mike Taulty's Blog

Categories