Add a dependency / reference to your own DLL project in Visual Studio 2013 - dll

I have been working on a few different applications and I want them all to share the same DLL library. The shared DLL is one that I created, so really I want each application to have a dependency on the DLL so that the DLL gets built in the same solution as the application. Then the DLL should copy itself to the application's bin folder before the application runs.
After figuring out how to do this, it seems that it should have only taken about 5 minutes, but unfortunately it took me an hour to figure out. That's partly because similar questions were referring to older versions of Visual Studio, or referring to 3rd party DLLs. So I thought I'd post the steps here.

You should already have one existing project and solution for your DLL. Open your solution for your new application that depends on your DLL
Highlight the top line in your Solution Explorer (your solution name), then go to the File menu and choose Add > Existing Project...
Browse to the project file for your DLL and select it. That will add the DLL project to your solution
Although your projects are now in the same solution, that didn't actually create a reference for your main project. So now right-click on your original project (should be 2nd line in your Solution Explorer) and choose Add > Reference...
The Reference Manager will appear. Be sure that you have Solution > Projects selected on the left. Then you should see your DLL project listed on the right. When you hover over it, a checkbox will appear. Select the check box. Click OK.
Last, be sure that your Project Dependencies are set correctly. Again, right-click on your Solution in Solution Explorer (top line). Choose Project Dependencies...
In the Projects drop down, make sure your main project is selected. Then in the Depends On list below, check the box for your DLL project.
Now when you Build your solution, it will first build the DLL, then copy it to your applications bin folder, then build your application. The Reference will also allow you to refer to the DLL in your code files, for example with "using MyLib;" for C#, or "Imports MyLib" for VB

Now when you Build your solution, it will first build the DLL, then copy it to your applications bin folder, then build your application.
Thank you for explaining this. I did all the steps (Visual Studio 2015) and I noticed that "Build solution" command builds all the DLLs, but it does not copy them to the right bin folder. To achieve that I need to build the active project (right-click on the active project, then "Build").

Related

How to build a project that relies on a third party COM library on a build server?

I have a project that I am developing that uses a third party COM library as a reference and I would like to build this project on a Visual Studio Team Services build client. My first idea is to create a MSBuild task that checks to see if the COM library is installed on the local computer and if it is not, go ahead and install it, but this seems like a really messy way to do this. I have searched around but it seems as though all the answers date back years and I can't seem to make the few I have found work in a VS 2013 project. How have other people solved this problem? Is there a cleaner way?
For reference I have also tried this solution, which looks really clean, to no avail.
I would go one of these routes:
Generate interop dll with tlbimp, add it to your project and reference it directly:
In VS command prompt, execute tlbimp.exe <your_dll> to generate the interop dll. You can specify the name with /out option.
put this dll somewhere with your code
reference it by going to Add reference > Browse and click Browse... to add the dll
Generate the tlb from COM dll , add it to the project and reference the tlb:
Generate the tlb (e.g. using OLE/COM Object viewer) or extract it from the dll resources,
put this tlb somewhere with your code
reference it by going to Add reference > COM and click Browse... to add the tlb reference to project
As #HansPassant noted in comments, this solution still relies on registry, but you can register it with regtlb, regtlib or similar tool, as a prebuild step, which should be easier than installing the server (though if it is just a dll, you could use regsvr32 to register it instead of full install). However, this is still more complex than the approach with interop dll

Loading 3rd party dlls for common use in Visual Studio 2012, C++

I have glut32.dll file which needs to be in the Debug folder whenever I compile a source. It's very frustrating to manually put in the Debug folder of each project file to have it run properly.
Is it possible I can put it in some folder and point the project to it?
I am a newbie with Visual Studio 2012.
Before this question being tagged as a duplicate, I want to add I keep seeing suggestions Referencing third party dlls, but I couldn't get it.
Any help appreciated !
If you add a project reference to this DLL, I believe it should be copied to the Debug folder automatically.

Visual Studio won't find references

I'm working with some application handed over by another person in which I must document the requirements, build and deploy processes.
The problem here is that Visual Studio (2005) is throwing a lot of errors since it can't find the references for the dlls.
This obviously won't let VS build the project.
Everything works fine on the persons computer but not on mine, even though the project references the same folder where the dlls are, the bin folder.
How can I circumvent these problems and get VS to properly reference the dlls?
The following printscreen shows the references screen for the project.
My guess is that your DLL uses a more recent .NET framework than your application does.
Check the properties for your DLL source (right-click on the DLL code in the solution explorer and choose Properties). Go to Application - Target .NET framework and compare the version to the one the application itself uses (right-click on the project code). Note: under your application properties check both the settings under Application - Target .NET framework AND under Publish - Prerequisites.
For what it's worth, even after changing the .vbproj file and removing many lines about hard coded values,
I eventually checked out the project again removed all references to the given DLL and then added it using the GUI.
Lesson learned, don't try to change out one DLL for a newer version without using VB2005 GUI.
The easiest solution will probably be to transfer everything to another project. It will be incredibly time consuming to find where visual studio has left the hard coded path at.
WOOT!!!! Compile the DLL file to a lower version of the .NET framework, and it will fix the problem!!!!
The paths in the project file cannot be the same or the assemblies referenced have a different version.
It might be worth unloading your project and the editing it to inspect where it's looking and for what version.
I had the same problem with an older Visual Studio Project that I opened in Visual Studio 2008. I tried to add new references to the project and got permanent errors that the dll's cannot be found. After the migration of the Project to Visual Studio 2010 I got the following error message when I tried to add a new reference:
'mySample.dll' or one of its dependencies, requires a later version of the .NET Framework than the one specified in the project. You can change ...
After changing the projects .NET Framework to a newer version everything works fine.
Good suggestions in other answers. In my case, it was because the libraries weren't copied (downloaded) successfully: the files existed, but were 0 kB.
Did a clean, which removed all the DLL's and then VS2008 complained it couldn't find the references (Duh!!!) and wouldn't rebuild....luckily I had and old version of the dll's and replaced them in the directory AND THEN did a rebuild to replace them...all references are now OK and we're back to normal....good old VS 2008

Deploying VB.NET program can't find dlls in same folder

I wrote a program in VB.NET which uses several .dlls that I programed in c++. The dlls wrap some functions from an old version of the program. On my development computer everything works fine but I build a release version, copy it and the dlls onto the target machine and the .exe starts up fine. When the program tries to use a function from the .dll it throws an exception and says "unable to load DLL "c:/the path/my.dll" the specified module can't be found."
I don't know if it makes any difference, but I am defining the dll functions in the main vb project using:
Declare Function MyFunction Lib "c:/the path/my.dll" (ByVal in1 as Double, ByRef out1 as Double) as Integer
I have checked the .net framework on the target and version 4 seems to be installed same as the development computer. Both are windows XP machines. I have no idea if it is the way I programmed the .dlls or just something with my vb.net project. Any help is appreciated.
Use a path relative to your executable, rather than an absolute path.
Or, even better, don't use the path at all and just list the name of the dll file. Then add the dlls as resources to your project. You should then be able to easily bundle the inside your setup project and they'll automatically end up in the right place for both debugging and deployment.
If I am not mistaken, you want your application to function with all the .dll files you used and worked on your machine. The simplest thing to do is to publish your Program or application. But first, you have to follow the following steps in order to include all the .dll files that you want your published program to use.
Click the Project tab and select the Add References… menu.
from the opened new window, use the Browse… tab to locate the files you want to add to your project, then click Add.
Then from the project menu, select your project property: for example, if your project is named Johns_App, then in the project tab, you will find Johns_App Properties. Click this, and it will take you to a new window.
In this new window, click the Publish tab, then from the Application Files… tab, you can check, include, and exclude the project files. Then you are all set.
I suggest using the Publish Wizard…, as it will guide you step by step.
Hope this helps
Found a link to a CodeProject page which referenced this same problem.
Basically you need to check that all dependencies of the DLL file(s) are available in the running location. Using the Microsoft Dependency Walker led me to the solution that one of the dll files used in my VB application was referencing a different dll file. After placing that other DLL with other run files no more error!

how should i organize dll libraries in vb.net

i am try to develop a small application.
Now should i organize my 3rd party dll libraries so that when i publish the project and than install that application on another computer all the libraries should move with installer...
That's what the bin folder is for. Just an FYI though, I've noticed DLLs not ending up there before and I'm like what did I do wrong?
Expand References in the Solution Explorer
Right-Click on your DLL and select properties
Make sure it says "Copy Local", I had one that wasn't showing up and it said false.