Dealing with C# namespaces - c#

I am working on a project that will need to ability to download youtube videos. I found this project on github:
https://github.com/flagbug/YoutubeExtractor
My project already has a namespace. How would I import the YoutubeExtractor into my project? Do I need to change the namespace for it before (or after) importing it? Or is it up to me, in which case, what are the advantages and disadvantages to changing the namespace vs. not changing it? I am using VS Express 2012, if that matters.

My project already has a namespace. How would I import the YoutubeExtractor into my project?
You add reference to the external assembly (in this particular case you install the NuGet) and then add using statement with the correct namespace (YoutubeExtractor) in which the classes are defined.
So just follow the steps described on the home page:
Install-Package YoutubeExtractor
and then:
using YoutubeExtractor;
and finally:
// Our test youtube link
string link = "insert youtube link";
/*
* Get the available video formats.
* We'll work with them in the video and audio download examples.
*/
IEnumerable<VideoInfo> videoInfos = DownloadUrlResolver.GetDownloadUrls(link);

Open the project that exists for the YouTubeExtractor and build it.
Move the outputted assembly to a location inside your project structure.
Add a reference to that assembly.
Add a using {namespace} to the files you want to use the extractor in.
Where {namespace} is the namespace it uses.
Further, it appears that there is a nuget package for it (you see that YoutubeExtractor.nuspec file in root). I would recommend installing nuget into Visual Studio and then searching nuget for the YouTubeExtractor. It's a lot easier, and you get updates with it easier as well.

Related

Missing DLL's own dependencies in consuming projects

I created a class library project using C# and .Net.
In this project I used two external dependencies(to be more specific: Microsoft.Win32.Registry(4.6.0) and System.Data.SqlClient(4.7.0) Nuget packages).
After I build this project, I can see the generated DLL file under /bin/debug folder.
Now I want to import this generated DLL in another project and consume its methods. Once imported and I run this project, it complains about not being able to find those two external dependencies I had in class library project.
As a temporary fix, I can import these two missing references in this project and it will work fine and as expected. But this is not what I want(and I guess is not a clean solution as well).
I want to know why the dependencies of class library project is not reflected in generated dll file? And is there any way to fix this?
Many thanks for your help.
If your class library is in the same solution or source control repository as the app that's using it, you should use a project-to-project reference, rather than referencing the assembly directly. As the docs say, this way it automatically detects changes to the class library when you compile the app, but what the docs didn't say is that dependencies flow though as well.
Otherwise, as Lance Li wrote, you should create a NuGet package from your class library. Unfortunately there's a bit of a barrier to get started. Creating the package is easy, but then you need to publish the nupkg file somewhere. For early development (before the package is ready to be shared), the easiest option is to use a local file feed. You'll then need a nuget.config in the app that will use the package to add that local feed as a source, then you can install the package in your consuming project, which will bring dependencies.
As you can see, for development, this is slow and difficult because if your consuming app finds a bug in your package, or if you're trying to develop a new feature in both the consuming app and class library at the same time, it means every time you make code changes to class library, you need to increment the version number, pack a package, publish the package, then update the package version in the consuming project. It's far, far easier to use a ProjectReference which lets you simply edit code, compile, run. Nothing else to think about.
See this, the way you reference that assembly is not a recommended way when both the projects are in same machine.
You're using the file reference(Add reference => browse...). And that's why you have to import these two missing references in this project manually.
So I suggest you add the project reference, if both the two projects are in same solution, you can right-click current project=>add reference=>project tab find that assembly you need.(instead of browsing...)
If the referenced project is not in same solution. Right-click solution in solution explorer=>add existing project to import it. Then add project reference.

unable to find the namespace of a third party api

I have received a .dll file from a partner firm with an API that will be used for database logging. I have added it to the references and can see it in the Solution Explorer. The documentation provided gave me a code snippet which references the file with a different namespace than the file name. I am using Visual Studio 2013 Express.
using com.XXXXX.XXX.microsites.api;
When I want to use the EntityFramework, it is simply the name of the reference.
using Microsoft.AspNet.Identity.EntityFramework;
The reference is not even showing up with a different name when using IntelliSense.
I am using the recommend framework ASP.NET 4 in the documentation.
I am using the code snippet they provided.
I would personally use dotPeek (https://www.jetbrains.com/decompiler/) to decompile the assembly and see what the defined namespaces are. Not sure if there's anything build in to Visual Studio.
If you added the dll reference in your solution then try opening the dll in object browser and see if you see the namespaces listed there and then use the one needed.

the type or namespace name 'directx' does not exist in the namespace 'microsoft'

I have been trying to include DirectX in C sharp project (Visual Studio 2010).
I installed DirectX SDK and included the components as:
using Microsoft.DirectX;
using Microsoft.DirextX.Direct3D;
When I try to compile, I get the error: the type or namespace name 'directx' does not exist in the namespace 'microsoft'
Some blogs mentioned that I need to add 'reference' - Microsoft.DirectX under '.NET' tab. But I couldn't find it over there. Neither was any facility to add it to the tab.
Any suggestion will be highly appreciated.
This was deprecated a long time ago. The last Direct SDK that still has the managed wrappers is February 2010. The download is available here. You'll get to pick the references you are looking for after you install that one.
Better not to use it, no future, look at something like the open source SlimDX or SharpDX projects.
There are various reasons why a dll would not appear on the .Net tab.There is specific registry configuration that makes certain dlls to appear on the .Net tab.
Alternatively use the browse option to add the dll reference manually to your project.
Project >> Add Reference
This is the way to add reference for Directx in C# Program :
Go to the solution explorer
Click references
Click add reference
Click Browse
Go to : "C:\WINDOWS\Microsoft.NET\DirectX for Managed Code\1.0.2902.0\"
*usually this is the place of Directx Files located. This can be change with the installation of .net.
Select your DirectX package.
example :
(C:\Windows\Microsoft.NET\DirectX for Managed Code\1.0.2902.0\Microsoft.DirectX.dll)
Here is one way i have find. First you need to install DXSDK (i have June2010 and SDK for Windows 7). Go to "Add refference" dialog press "Browse" , go to something like this "C:\Windows\Microsoft.NET\DirectX for Managed Code\1.0.2902.0" or "C:\Windows\Microsoft.NET\Managed DirectX\v9.02.2904" then choose proper dll for example - Microsoft.DirectX.dll. So you can add "using Microsoft.DirectX" directive to your project.

How do I reference (make use of) WebKit-Sharp in OSX?

I have a C#-project in MonoDevelop and I want to use WebKit-Sharp as suggested in this tutorial: http://shana.worldofcoding.com/en/programming.html. My problem is that I don't know how to reference/install WebKit in OSX.
I found rpm's (installation files) from the given repositories but I couldn't execute them with rpm5 and when I extracted them I didn't find any file that I was able to reference from my project.
I've been looking through https://github.com/mono/webkit-sharp, but aren't sure if anything from there could do the job.
Can I reference anything from github or somewhere else to make WebKit work in MonoDevelop and OSX?
If you extract the rpm for webkit-sharp, the dll is in ./usr/lib/mono/gac/webkit-sharp/somehash/webkit-sharp.dll
You should be able to import that into your References in the project (search for it from the .Net Assembly tab after you extract it).

C# Class Library method summaries not showing in intellisense of vb.net project

(VS 2008)
I'm using a C# library for my VB.NET project. And the method summary/notes or what they are called do not show in intellisense. Is this supposed to be like that? Or is there something I must do to fix it? And if not, will VS 2010 be able to do this?
EDIT: Still unresolved. Now building library dll + xml file, but how to import the xml file in my vb project?
See image: http://i52.tinypic.com/25kh5xw.png
In C# library, go to the properties on the build tab, and check the checkbox for including XML documentation and specify the name and path. After that include the new library in your VB.Net project.
one reason could be resolved by importing the namespace needed
another reason could be due to faulty writing
if you send the code where the problem is we might be able to help you
If you're using source control (TFS or Github) then you need to the following:
Check in ( Push) for safe return point (base line)
Delete the references from the project.
Delete the custom dll's from the solution.
At this point the libs are marked as [removed], if you would add them again at this point, they will just be marked as [changed] again. This did not include the summaries for me.
Check in (push). dll's are now removed from source control as well.
Drag and drop the dll's (including xml) into the solution (I recommend using this method for including dll's
Add references to these dll's via Browse.
Check if you have summaries.
Check in (push).

Categories

Resources