Where are dll libraries stored in VS .Net? - c#

I wonder where dll files are stored in Visual Studio and whether its the best way to keep them there or consolidate elsewhere for the following cases:
1) My solution includes a c# library project which other projects in the same solution reference to. My understanding is that the library project stores the dll in its own directory /bin folder. So do I need to establish the reference to that library by pointing to the dll in that external folder? Problem is that this dll should later be shipped with the projects referencing to the dll file. Will the projects who reference to the dll file create a copy of the dll in their own project /bin folders or how does it work?
2) where should I copy external libraries to that are referenced by projects I like to ship in compiled fashion? Should a dll be copies and referenced to into each project's bin folder that utilizes such external library?
I am a bit confused by how going practice is and could not find straightforward answers in other posts here.
Thanks

If you can set two solutions one for your dll referenced and another for your project that reference them after
create a dependencies folder where you will set all binaries that are dll you need
set path to this dependencies folder on all your projects that will create dll you want to reference
set build order on your solution to first build your dll and after build your project that reference your dll
when you deploy it, make sure that you create dependencies folder
For your information, your application first see on GAC folder (windows\assembly), after see on your current path, and after use PATH environment variable.

Related

How to force a .NET tests project to use System.Net.Http.dll from bin folder instead of from the shared folder?

I have a .NET tests project that uses HttpClient from System.Net.Http.dll that is loaded from shared folder:
C:\Program Files\dotnet\shared\Microsoft.NETCore.App\System.Net.Http.dll (example for netcoreapp3.1 tests project target framework).
I need the tests project to use a modified version of System.Net.Http.dll from the bin folder instead of from the shared folder or instead of from the GAC.
Is it possible by configuring the tests project?
Another option could be to modify tests project dll via dnlib library. I loaded a list of references via dnlib but could not change reference for System.Net.Http.
Is there a way to force project dll to use System.Net.Http.dll from the bin folder by modifying project dll via dnlib library or by any other similar library?
Thanks for your time and your help.

Why does a reference to a C/C++ DLL project from a C# class library project break in Visual Studio when building the solution?

I am in the process of creating a library to be used in Windows desktop applications. The core part of the library will be a C/C++ DLL that can be used in Win32 applications or other C/C++-based apps. I'll just call it libtest.dll for easy referencing here. I also want to make it available to Windows Forms applications (C#), so I am creating a C# class library (DLL) as a wrapper around the C/C++ library using P/invoke (DllImport) to call into the C/C++ code. I'll refer to this library as Test.dll.
Additionally, I have a Windows Forms project set up in Visual Studio for testing that depends on the C# class library project. The C# class library depends on the C/C++ library project. However, for Test.dll to find libtest.dll (in the DllImport statements), libtest.dll needs to either be in the same directory as Test.dll or in one of the DLL search paths in the system.
To make this easy when debugging in Visual Studio, I thought adding the libtest.dll project as a reference to the Test.dll project would automatically copy libtest.dll into the output directory of the Test.dll project. When I add the reference and then build the solution, the reference ends up broken and the libtest.dll file is not copied into the output directory of Test.dll.
When I add the reference to the Test.dll project in Visual Studio, the properties of the reference look fine:
"Copy Local" is set to True
The path is correct
"Resolved" is True
After building, however, the reference itself has a warning icon on it, and the path is now empty and "Resolved" is False. Any idea why, or how to fix this? How do I set up the project reference between these two library projects so the C/C++ DLL gets copied into the output directory of the C# class library project? I have verified that the build order of the two projects is correct: first libtest then Test.

c# .net: referenced dlls, do the reference paths have to remain relevant after compilation?

I'm wondering, if I reference a dll in my c# project and then compile the project, does the compiled dll remain dependent on the existence of the referenced dll?
For example, say I had referenced a dll c:/myLib/some.dll. Once I've compiled my class library that references this do I need to keep the reference dll in that location or is the dependency merged with the class library I'm creating?
I ask because I'm creating a project that references a set of dlls which will inevitably be migrated into a project directory in the future (haven't do so yet as I'm still unclear on dll usage).
Thanks/

How do I package my C# code into standalone executables?

Is there any way to package a C# project that am working on in Visual Studio 2015 Community into a stand-alone executable that doesn't need any other files or VS/.NET dependencies? Thanks in advance.
If you are developing an application with .net, it will always need the .net dependencies. Depending on any libraries that you use, you will need them as dependencies as well. If you truly want a native single exe than there are some third party vendors that can do this. They make virtual applications that package the dependencies inside of the exe. They are not free and I have not had good luck with these, but worth a shot.
One example https://turbo.net/studio
Build your project in release and you can use the output exe from bin/Release folder as a standalone executable.
If it has dependencies on assemblies which are not part of .NET framework you also need to merge all referenced dll assemblies into one exe file using ilmerge.
In both cases, users needs to have .NET framework installed on their machine.
The bin, obj, properties, etc. directories are part of your source code project not your executable. To exe application gets created in the bin directory. If you build it in debug mode, you'll find it in the bin\Debug folder. If you build it in release mode, you will find it in the bin'Release directory, etc.
That exe file should be good to run in any other computer.

How to put a DLL file into the .NET framework

Sorry if this is an obvious question, but I'm new to C# and am trying to use 2 dll's for a project. Where do I put them?
I tried to add SoundTouch.dll as a reference in an empty C# project, but Visual Studio said to make sure that the file is accessible and that it is a valid assembly or COM component. I was suggested to put the dll's into the \bin\debug path, but where is that? Thanks for your help.
Each project should have it's own \bin\debug (and \bin\release) directory structure under it's project directory, but they will not be created until you Build the project. As for the invalid assembly, it sounds like your dll has either become corrupted or is not a valid .NET assembly.
Edit: Looking at the SoundTouch website, someone has already created a wrapper for this dll suitable for use with C# and it can be found here
If your DLL is a .NET or COM DLL, you can simply add a reference in Visual Studio. For details on that procedure see
http://msdn.microsoft.com/en-us/library/wkze6zky(v=vs.110).aspx
If the DLL is a Win32 DLL (does not expose a COM interface) you can interface with it via the Platform Invoke (P/Invoke) mechanism.
http://msdn.microsoft.com/en-us/library/aa288468(v=vs.71).aspx
When using P/Invoke the DLL must reside in a location that can be resolved by the .NET runtime, and you use the DllImport attribute to "pull" entry points from the DLL into your C# code, e.g.
[DllImport("msvcrt.dll", EntryPoint="puts")]
.NET will search for the Win32 DLL in the same directory where the .exe is located. If you build under Visual Studio, a folder will be created under your project folder
bin\debug
for a debug build, or for a release build
bin\release

Categories

Resources