I want to add include directories and libraries in my c# project like i can in my c++ project
C++ Project : There are options to include directories and linker dependencies.
C# Project
There does not appear to be an option in the project settings to add those settings. I added the path in reference path, but my debugger throws an error. Right now i've added all the dll in my project\bin\debug directory and its working, but i don't want to do it for all the projects. Where i can link these diretories ?
you can add reference of library files which you want to add into your project by right clicking the project under solution explorer and then "add reference" and then browse or select from the list of dlls..
You can't. You have to include references to code files and assemblies one by one.
The linker and compiler for .NET works different than you are used to with c++. That's why you can't just link an entire directory containing some code files / assemblies.
Add reference to your existing dll for every project which will be use it
http://msdn.microsoft.com/en-us/library/7314433t(v=vs.90).aspx
https://www.google.it/search?q=add+reference+c%23&es_sm=122&source=lnms&tbm=isch&sa=X&ei=P-2fU472Bcr00gX-tYAw&ved=0CAoQ_AUoAw&biw=1920&bih=955
Related
I'm building a UWP Viewer for the Pdfium library(pdfium.dll). pdfium.dll is a c++ class library.
In my Visual Studio Solution, I have two UWP projects.
First Project(PdfiumViewer) is a UWP Class Library which imports functions from pdfium.dll and creates user controls.
Eg:
[DllImport("pdfium.dll")]
public static extern void FPDF_AddRef();
The second project(PdfiumViewer.Demo) is a UWP Blank App and I referenced the first project here So that I can use its user controls in this project. I included pdfium.dll into the bin folder of my second project. But when I run the program, I get an exception saying "Unable to load pdfium.dll".
There is an existing similar Viewers developed for .Net Windows Forms and WPF apps.
I tried to add pdfium.dll as a reference by right-clicking reference -> "Add reference". In all of these cases(.Net WinForm, .Net WPF, UWP), adding it gave me an error. (ERROR : A reference to ....\pdfium.dll could not be added. please make sure that the file is accessible, and that it is a valid assembly or COM component)
I added the pdfium.dll into .Net WinForm and .Net WPF in a similar way(to the bin folder) and run them. Both types of application viewers worked fine.
My Question: Since UWP apps run in a sandbox, Is there a special location to add this dll(pdfium.dll)?
Note: I tried to add the file in different locations. (inside APPX folder, inside bin\Debug folder, inside bin\Debug\x64, etc)
When adding the dll to the VS UWP Project, follow the below steps.
First, check the dll using a dependency checker and find out whether the dll is needing additional dependencies.( Such as any other dlls)
Then,
(1). Right-click the project -> "Add" -> "Add existing item" -> Select the dll -> Choose "Add as Link" Button from the arrowhead in Add button.
(2). After adding the dll, Change the properties as "Content" and "Copy if newer".
How to add dll file into a UWP Project
Derive from this case, you need copy your dll to the project folder and set the type as content. Then in the proper cs file, using DllImport to PInvoke the dll.
I have 2 separate Visual Studio C# solutions. One solution contains projects that generate DLL files (class library projects) and the other solution contains projects that depend on the DLL files from the other solution.
I have two questions about adding the DLL files from the first solution as references to each of the projects in the second solution.
When I add the DLL files as references (using the Browse option) is
there a way to use relative directories so that if I move the
solutions to a different folder I won't have to update the
references? (Assuming the two solutions are always in the same
location relative to one another.)
For example: ....\Solution1\Project1\bin\Debug\Project1.dll
If I change the DLL solution's configuration from Release to Debug I
want the other solution projects to reference the DLLs in the Debug
folder and vice versa. When adding the DLL files to each project can
I use something like the Visual Studio macro $(ConfigurationName) in
the DLL file path so that, depending on whether I build in Debug or
Release mode, I use the correct DLL file?
For example:
....\Solution1\Project1\bin\$(ConfigurationName)\Project1.dll
Thank you.
I was looking for the output of a project as a *.dll file to add it in References, but in bin folder there where Release and Debug folders.
Is there any difrence between the output.dlls?
Where is the useable output?
please explain the folders roles.
The folders correspond to your Solution Configurations, e.g. Debug or Release. You can specify custom configurations as well, and a folder would be created for it.
Instead of referencing the .DLL file directly by browsing to it, you should reference the project that defines the .DLL. If the project is not in your solution, you can add it by right-clicking on the solution title in the Solution Explorer and choose "Add" > "Existing project...".
This will allow Visual Studio to rebuild the .DLL in case you make changes, which you can now make without leaving your other project, and automatically reference the correct version, and also reference the configuration matching your project, i.e. if your project is run in Release, it will also use the release version of the .DLL.
I have successfully added other .dll files to other C# project this way:
Right click Reference > Add Reference > Browse > Double click the .dll file
but Microsoft Visual Studio 2008 issues the following complaint:
A reference to ...\dll\FreeImage.dll could not be added.
Please make sure that the file is accessible,
and that it is a valid assembly or COM component.
I am using .NET Framework 3.5. I believe this is a 32bit dll (it downloaded with FreeImage3151Win32) so I changed the configuration of the project to x86.
What is the correct method to add FreeImage.dll to a C# project?
Use the wrapper provided in the download. There are C# samples in the \Wrapper\FreeImage.NET\cs\Samples directory.
The FreeImage.dll isn't a .Net dll. You need to write a wrapper in .Net which call the methods of the unmaged code. There is an example here but they also supply a .net wrapper in the binary distribution here
I've seen this before with files downloaded from the Internet that are "blocked" by the file system. Try going into the file's properties and clicking the "Unblock" button.
In the current release (3.15.4), have to build the project in FreeImage\Wrapper\FreeImage.NET\cs to produce the DLL for C#. Then you find it in FreeImage\Wrapper\FreeImage.NET\cs\Library\bin\Release or Debug.
Save the file into the Bin folder and click Project > Add Reference > Browse > Double click the .dll file
C# sharp helps link
I am building a project with OpenCV in C#. It requires a dll file called cvextern.dll. but, when adding this file as a reference, this message appears :-
a reference "cvextern.dll" can't be added, Please make sure that the file is accessible and that it is a valid assembly or COM component.
I get tired from searching, I spent the past 2 days in searching for a solution for that problem
the file is a native DLL which means you can't add it to a .NET project via Add Reference... you can use it via DllImport (see http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.dllimportattribute.aspx)
In my case I had to register the .dll.
To do so, open cmd.exe (the console) with admin rights and type:
regsvr32 "foo.dll"
Make sure the required dlls are exported (or copied manually) to the bin folder when building your application.
'It' requires a dll file called cvextern.dll . 'It' can be either your own cs file or some other third party dll which you are using in your project.
To call native dlls to your own cs file, copy the dll into your project's root\lib directory and add it as an existing item. (Add -Existing item) and use Dllimport with correct location.
For third party , copy the native library to the folder where the third party library resides and add it as an existing item.
After building make sure that the required dlls are appearing in Build folder. In some cases it may not appear or get replaced in Build folder. Delete the Build folder manually and build again.
I had the same program, I hope this could help.
I your using Windows 7, open Command Prompt-> run as Administrator. register your <...>.dll.
Why run as Administrator, you can register your <...>.dll using the run at the Windows Start, but still your dll only run as user even your account is administrator.
Now you can add your <...>.dll at the Project->Add Reference->Browse
Thanks
Look here for the answer by TheMattster. I implemented it and it worked like a charm. In a nutshell, his solution suggests to add the COM dll as a resource to the project (so now it compiles into the project's dll), and upon the first run write it to a file (i.e. the dll file I wanted there in the first place).
The following is taken from his answer.
Step 1) Add the DLL as a resource (below as "Resources.DllFile"). To do this open project properties, select the resources tab, select "add existing file" and add the DLL as a resource.
Step 2) Add the name of the DLL as a string resource (below as "Resources.DllName").
Step 3) Add this code to your main form-load:
if (!File.Exists(Properties.Resources.DllName))
{
var outStream = new StreamWriter(Properties.Resources.DllName, false);
var binStream = new BinaryWriter(outStream.BaseStream);
binStream.Write(Properties.Resources.DllFile);
binStream.Close();
}
My problem was that not only I had to use the COM dll in my project, I also had to deploy it with my app using ClickOnce, and without being able to add reference to it in my project the above solution is practically the only one that worked.
In my case I also have unmanaged dll's (C++) in workspace and if you specify:
<files>
<file src="bin\*.dll" target="lib" />
</files>
nuget would try to load every dll as an assembly, even the C++ libraries! To avoid this
behaviour explicitly define your C# assemblies with references tag:
<references>
<reference file="Managed1.dll" />
<reference file="Managed2.dll" />
</references>
Remark: parent of references is metadata -> according to documentation
https://learn.microsoft.com/en-us/nuget/reference/nuspec#general-form-and-schema
Documentation: https://learn.microsoft.com/en-us/nuget/reference/nuspec