How to create .dll file from multiple files with different extension - c#

Can I create a single dll file of my project which contain other dependent dlls and some other subfolders which contains file which are not .cs file but use to make calculation in my project.
My project look like this:
Above image first arrow shows reference which comes after adding dll ex. abc.dll.
And arrows 2 and 3 shows folders in my project which contains file which are used in code. And those are not .cs (C# files).
Is it possible to create single dll which contain all this dlls and files in folders so that I can distribute to anyone.
Or is there any other way I have to follow.
Let me suggest

You can use ILMerge to solve combining multiple DLL's into one, found here: http://research.microsoft.com/en-us/people/mbarnett/ilmerge.aspx also found in nuget. For the other items, you can add them as resources: https://support.microsoft.com/en-us/kb/319292

Yes you can make a single interface (ONE DLL) that is using other DLL and your own source code.
But you need to ship other DLLs too with your DLL. Because without it other people will get error when consuming other DLL functions.

You'll have to package up all the dependencies as resources in your project.

Related

How to merge a subset of linked dll files with one exe file (C#, WinForms)?

I have a solution with two C# projects: One WinForms application (exe) and one library (dll). Multiple external dll files are referenced. I would like to merge the output of my projects into one exe file, while keeping the other dll files separately, i.e. instead of
myApp.exe
myLib.dll
externalLib1.dll
externalLib2.dll
...
I would like to have
myMergedAppAndLib.exe
externalLib1.dll
externalLib2.dll
...
Is this actually possible?
I am aware of the ILMerge tool, but it seems to be deprecated and I don't know whether it is ok not to include all referenced dll files.
I am also aware of the publishing option in Visual Studio Produce single file, but to my understanding this will also merge the external dll files, right?
I cannot merge the two projects, because the library project is also used for a third project (another WinForms exe).
Related SO question: merge-dll-into-exe

VS project referenced from two excluded libraries

I have two versions of my application. The first one use references of library LIB_A, the second one use references of library LIB_B. (LIB_A and LIB_B are in fact to versions of the same product, but they differ from each other, even namespaces are different.There can't be installed two versions in the one machine on the same time).
Sourcecodes of my application in both versions are almost the same so I need to have one solution, that can switch which library to use.
How can I do that?
Since you specified VS2010 in your comment, I'm adding this answer separately, so that users of VS2015 can refer to the other answer, which is a lot cleaner.
In VS2010, you can use source code sharing between the two projects. Let's say that you have created AppA, which is the app project that references LibA, and contains all the sources for the app.
You can create an app project, AppB, that references LibB. It also shares all the sources of AppA. This can be done in one of two ways:
Linking All Sources Manually
In AppB, you can create the same folder structure (if any) as AppA. Right click each subfolder and click Add->Existing Item... Navigate to the corresponding folder of AppA and select all the C# files. Now click on the dropdown to the right of the Add button and select "Add as Link". You'll notice that the added sources have a little "shared" arrow in their icons, and that their paths point back to the original.
Linking All Sources Dynamically
If you have lots of files in AppA, or add/remove files regularly, the previous approach can get tiring. There's another way to do this that involves hand-editing AppB.csproj. Open AppB.csproj and create an ItemGroup that imports all the files from AppA. This code assumes that AppA and AppB are subfolders of the solution folder. If not, change the relative paths appropriately.
<ItemGroup>
<Compile Include="..\AppA\\**\*.cs">
<Link>%(RecursiveDir)%(FileName)%(Extension)</Link>
</Compile>
</ItemGroup>
Now when you open the solution, you will see that AppB's contents match that of AppA. The sources are linked, so AppB's conditional build settings (if any) will apply.
You can also exclude files from being included by adding an Exclude attribute to the Compile tag. See the VS documentation for more details.
The only downside of this approach is that you need to hand-edit the csproj file. Also, if you accidentally delete or move linked files, VS will hard-code the list of linked files into the project. The files themselves will still be linked.
It so happens that Visual Studio 2015 (you can download the Release Candidate, which I've found much more powerful and faster than VS2013) has a feature that is designed for this very purpose - Shared Projects. Here's a Channel9 video that describes it.
A shared project contains source files that are compiled directly into projects that reference it. Let's say a shared project Shared has a file foo.cs, and projects AppA and AppB both reference project Shared, then file foo.cs is compiled directly into AppA and AppB - it uses any conditional settings of those projects. So foo.cs could have code that looks like this
#if APPA
// do something
#elif APPB
// do something else
#endif
So to summarize:
Within a single solution, create a Shared Project with all your app sources.
Create two projects AppA and AppB, that represent the two flavors of your app.
AppA references Shared and Lib_A. AppB references Shared and Lib_B.
If needed, add compile variables that control differences in the sources as described above.

Remove DLL dependency for an Application

In my application, I need to Zip and Unzip some files. For that I have used DotNet Zip Library (Ionic.Zip.dll-- DotNet Zip Lib )
Everything works fine but when I take EXE of my file and try to run it from different folder, it fails to run. I have to keep Ionic.Zip.dll in the folder where my application resides.
Is there any way out? I just want an EXE file without any strings attached....
Or is there any other option other than DotNet Zip Lib.
When you add a reference to another assembly (e.g. a third-party DLL) to your C# project, the compiler doesn't add the contents of that assembly into your EXE; it just creates a link that says your program will need to load that DLL when it runs. It's quite normal to distribute a .NET program as an EXE file plus the DLL files that it needs.
But if you'd prefer, you can combine them into one EXE file. There are a few different tools that can merge multiple .NET assemblies into one. Have a look at ILMerge or .NETZ.
Have a look at this pure C# libraries without external dependencies:
ZipStorer
It can be included into your application and compiled directly into your single EXE - no external ZIP libraries needed.
You can use .net for that, have a look at Packaging namespace or if you can use gzip format you gave a class for that too. Using this you'll remove the dependency from your project.
If it is an opensource project, you can just include the source code in your project without adding a reference to the "dll".

How to merge all dlls into one for an application?

My case: I have an app.exe and several dlls for it -- a.dll, b.dll, c.dll, etc (they come from single VS solution which consists of many projects). I would like to merge (ilmerge) all dlls into one so I would have: app.exe + x.dll.
Now, there is a problem -- the application expects to have all dlls so when I put just single file x.dll it won't run. So how to "redirect" application to use one x.dll -- is it possible at all?
The one solution I am aware is deleting all references to projects in Visual Studio and add instead reference to merged dll. But this would disable dependency chaining while recompiling solution.
Btw. I cannot merge exe and dlls together because this is a wpf app, and ilmerge cannot handle it.
You could instead of creating 3 DLLs you could create 3 .NetModules and turn them into one DLL. It would require some editing of the actual CSPROJ files because creating .NetModules is not currently integrated into the MSBuild system, but it can be done.
You can think of a .NetModule as a kind of static library in C/C++. Of course there are differences but overall the concept is similar. They are most common when trying to make a single DLL containing multiple .NET languages, but they will work for you as well. Check them out here.
I'll recommend if you read this blog. Its an alternative to ILMerge when you need to merge WPF assemblies.
http://blogs.msdn.com/b/microsoft_press/archive/2010/02/03/jeffrey-richter-excerpt-2-from-clr-via-c-third-edition.aspx

Team Foundation Server - Add rereference to existing dll to a new class library project

I've just started using Team Foundation Server and have added a new Solution that contains a project of type class library. I need to add a reference to the new class library project to an existing class library (dll) that we have created. What is the best way to do this? I've noticed that if I try to add it from the original location as an existing dll, it keeps the original location of the dll. I think what I want is to actually copy the dll to the new project, and add a reference to it locally - but I can't figure out how to do that.
Write a MSbuild/Nant script that build's and copies the dll to a common lib directory. Then reference the lib\foo.dll in 2nd project. Also create the build order.
Can you include both the old and new projects in the same solution? If so, you can reference the project directly (primary artifact) instead of the .dll output (secondary output). This 'just works' when you need to build multiple configurations, such as debug, release, etc.
If that dll is something that will be shared among different libraries and applications, you may want to consider putting it in the GAC. This will also help avoid versioning issues of putting it in a common lib directory (although you could just put folders in the common lib directory for different versions)
MSDN article on the GAC: http://msdn.microsoft.com/en-us/library/yf1d93sz.aspx
Another way that doesn't involve copying the whole project or messing with the GAC would be to:
Add a reference to the DLL to your project
Open the references folder in your project
Right click the DLL -> Properties
Find Copy Local and set it to "True"

Categories