Where to copy a 3rd party assembly in your Visual Studio project? - c#

My operating system is Widows 7. I am using Visual Studio 2015.
I have a solution Sln1 which has 2 projects Proj1 and Proj2 both projects are of Class Library type.
In Windows Explorer I can see:
I have a folder c:\MyWork\Sln1 which has the solution file named
Sln1.sln and it also has 2 folders named Proj1 and Proj2.
I have a folder c:\MyWork\Sln1\Proj1 which has the project file named
Proj1.csproj and it also has 3 folders named bin, obj and Properties.
I have a folder c:\MyWork\Sln1\Proj2 which has the project file named
Proj2.csproj and it also has 3 folders named bin, obj and Properties.
I have a 3rd party assembly (Telerik.Web.UI.dll) which is in folder C:\Program Files (x86)\Telerik\UI for ASP.NET AJAX Q3 2015\Bin45.
I want to use this 3rd party assembly in the source code of Proj2 only. But I dont want the project Proj2 to access it from its current location. Instead I want the project Proj2 to have its own copy of this 3rd party assembly. How can I do that?

Copy the dll file to the desired location for example (solution/project/lib). Then in vs2015 open the solution explorer Ctrl + Alt + L.
Then under the project, you want to add the lib to right-click on reference.
Then click on add reference. Go to the browse tab and in the right bottom side click on browse.
Here you can select the dll you want to reference in the project. The 3th party library is now ready to use in your project.

Since you want the 3rd party library in the "Proj2" project location, just copy the DLL file (i.e. Telerik.Web.UI.dll) to a folder in that section (for example under lib, etc.) then in your project(s) go to your Solution Explorer, under the References right click and choose "Add Reference...", then click on Browse and choose your DLL accordingly from the location that you copied earlier.
I hope this will be a useful tip for you.

The most important thing to take into account is version control. No matter where you put it, make sure that the library is under version control, or at least that sufficient information to retrieve it. Also, check that you reference it in your project using relative paths, so anyone can build using only files within his own working copy.
I generally use a structure like this:
\
\libraries
\lib1
\lib2
\source
\proy1
\proy2
So that it's easy to checkout the whole thing, incluiding all dependencies and use those for building everything.

Related

How to export class libraries in Visual Studio 2012

In Eclipse when I implement a class library and I'm ready to deploy, I usually export and package it into a JAR file that later you can just add to the build path in another project. Is there an equivalent feature in Visual Studio? Is there a proper way to "publish" a class library and package it into a dll file to later add as a reference in another project? Or do you just usually go and dig for it in the bin folder yourself?
Most VS projects compile into a DLL. If you want your DLL to be "published" to some particular location when you build, you can use build events which can also package up your dll (you could call a batch script, for example, that takes care of that for you).
Is there a proper way to "publish" a class library and package it into a dll file to later add as a reference in another project? Or do you just usually go and dig for it in the bin folder yourself?
Sure, just add the bin\debug\yourdll.dll or bin\release\yourdll.dll as a reference in your other project, or otherwise to the location you moved it to in your build event. No need to go digging for it every time.
Change the output type to 'release' or 'Debug'.
Go to Build, Build Solution (Or f5)
Navigate to: The Solution Bin folder for release or debug.
3a. You can quickly navigate to the solution folder by right clicking the solution in the
'Solution explorer' and selecting 'Open folder in File Explorer'.
The compiled DLL file will be in that directory. (bin\release or bin\debug)

Adding Dll to Subversion from Visual Studio

I am new to SVN though I have used TFS previously. I have ASP.Net project in VS 2010. I need to add AjaxControlToolkit dll to the project. After adding this dll, I tried to commit the changes using Subversion in VS2010. The project file appears in the list of items to commit; however the newly added dll is not listed. How can I check in the newly added dll too?
Note: I am looking for an approach involving User Interface actions; not commands. I am using Tortoise SVN
Note: BIN folder has a question mark. The dll is added into that as well. So, am I supposed to checkin the BIN? There is no questionmark for the dll file inside the BIN folder too
Here are some suggestions:
Create an "ExternalDlls" folder in your projects root folder. Place external dll's (like AjaxControlToolkit.dll) in this ExternalDlls folder. Add this folder and it's contained dll's to SVN using TortoiseSVN's Add.
Now add a reference to your external dll from within Visual Studio. You should be able to right click the "References" folder and add a reference. There will be an option to "Browse" your file system. Browse to the "ExternalDlls" folder and find the dll you want to add, in this case the AjaxControlToolkit.dll. Select the dll and add it to the references.
OK - so now you should have the DLL added to your references, and an ExternalDlls folder ready to commit to SVN!
A suggestion:
Checkout ankhsvn if you are looking for Visual Studio SVN integration. You can also check out VisualSVN, but you will have to pay for it. These are nice tools to have handy and allow you to handle SVN actions directly from Visual Studio. VisualSVN is smart enough not to add unnecessary files as well.

How can I use only a part of my assembly?

I want to split the components of my applications like:
Application A -> Component X <- Application B
without compiling Component X to a dll.
When I include the .cs, Visual Studio copies it to the application directory. I don't want that. I want to include the file and then use a part of it, like C's #define. For example if I have a ZIP library, I don't want to include the whole assembly if I need a decompression. What's the C# way to make this? Can I somehow tell VS to not copy the file and use #defines or maybe some method attributes?
An assembly is a single, complete file. If you want multiple assemblies which are only included as needed, you need to build them using multiple projects (one per assembly) and reference only the ones you want in the downstream projects you want.
Bigger question, however, is ... Why?
Don't create a problem where there isn't any.
Create a new dll, and MOVE .cs files that should be shared there. Build it, and have AppA and AppB reference and use that dll.
BTW, you can add reference from AppA to AppB, or from AppB to AppA, but not at the same time because it will create circular reference.
And if you want to stick to your idea, LINK your code files as Chris suggested, and use:
#if APPA
// code for AppA
#endif
To have pieces of code compile just in one application. Use project level #defines (project properties) to define APPA and APPB in their respective projects.
You can link to source files in Visual Studio, rather than copying them into in your project. Right click on the folder where you want to put the file, click "Add Existing Item", find the file that you want to add in the dialog, and before hitting Open, note the little down arrow next to the Open button. Click that, and click add as link.
Documentation here: http://msdn.microsoft.com/en-us/library/9f4t9t92(v=VS.100).aspx
Add Existing Item...
Browse to the file you want to include.
Instead of selecting "add", press the arrow to the right of the "Add" button and select "Link" in the drop down.
/B
May be you need Multifile Assembly?

C# SciLexer.dll question

I am using ScintillaNET a wrapper of the Scintilla control. I've edited the a lexer a bit and would like to try and see if the changes work, but the problem is I don't know which SciLexer.dll file it's using on my computer. The one in the application's directory did not seem to make a difference.
So my question is basically, how do I know which SciLexer.dll file my application is using and how can I set it to use the one in the application's directory?
Using Visual Studio, check to see which DLL your project references:
With your project/solution open, expand the "References" folder in the Solution Explorer, and locate the name of the SciLexer.dll you are currently referencing.
Double-click on the relevant assembly to display it in the Object Browser.
In the bottom-right pane of the Object Browser, you will see the full path on disk to the specific DLL that your project is referencing.
This is the DLL that you need to change/update. Or, you could remove the existing reference and add a new one to the DLL in the directory that you want your application to use.

ClickOnce & References

I have created a ClickOnce Solution with VS2008.
My main project references another project who references COM dll as "links".
When I build my solution in VS the dlls from the orther projects are moved in my bin folder but when I publish and launch the project these files are not presents in my Local Settings\Apps\2.0... folder.
I know that I can add each dll of the other project as a reference of my main project but I'd like a cleaner solution ...
Is it possible ?
First add those files to your project directly.
Then goto Application properties -> Publish -> Application files
Select "show all files" if you do not see the files you need and then set their
publish status to "Include" NOT "Include (Auto)". This is important or they will not be added.
Please note if you update the files, you will have to remove them and add them again
and set their publish Status again. This is a small bug.
See a previous question of mine for more info:
ClickOnce - Overwriting content files
You need to open the "Application Files" dialog in the Publish tab of your project. From there you can set the publish type (Include, Prerequisite, etc.) of each of your files.
If it's an unmanaged DLL, you'll need to add the actual .dll as a file to your project and mark its build action as "Data". You can then set the Publish Type of that file to Include.
I had the same issue.... and the only way to fix this after going through many options, was by adding those dlls to References.
It works, but I hope there would be a cleaner solution to it in future.

Categories