How to embed localizations in .NET assemblies - c#

I created a .NET class library in C# with some resources for localization and already translated them to different languages and put them into different *.resx-files.
But when I compile the assembly, only the default *.resx-files are compiled into the resulting dll and the others are compiled into different dlls in different sub folders.
I know this is the default behavior of Visual Studio but for me this is not very useful, because I do not want to distribute many files in many folders but just one independent dll.
So I need to know what I have to change to compile everything into one dll.

You can use IL Merge to combine multiple assemblies into one .dll file.

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

how to use dll of same name but different version from different locations in same application?

We are trying to program a couple of plugins for another application. We have two directories each with the code it needs to run independently whcih contain all the dll's (but not the exe as its 3rd party and we have no control over it). There is some shared code in a dll, placed in each plugin directory. When introducing a new version of the plugin we need to change this shared dll in one of the plugin directories but leave the other. When we do this the old version breaks as it relies on the older version of the shared dll but it only loads one. Is there a way to force it to use a certain version of the dll?
you should use the latebinding approach System.Reflection

How to compile cs files into separate dll

I have a class library and cs files which are for different objectives. One is extension class, the other is windows form control the other is asp.net control, etc.
I want to compile all these cs files into a different dll.
PS: Some of them will need more than one class files maybe.
You may try command line compilation. (Working with the C# 2.0 Command Line Compiler)
csc /target:library /out:Something.xyz *.cs
I know this sounds too obvious, but if you want to compile them into seperate DLLs, why don't you create a project per assembly? So that's a project for the extension classes, one for the asp.net controls etc...
You have to create different projects in your solution (assuming you work in Visual Studio).
Each project can have multiple (class, resource, form, etc.) files and will be compiled into different assemblies (dll's). For each project you can specify settings (assembly name, target framework, etc.).
Classes from different projects can "use" each other by making references from one project to the other. Also, different projects can specify the same namespaces so that you can structure the aplication to your own wishes.
See Structuring Solutions And Projects
All *.cs in a single class library project will compile into the same DLL, you can not split them into individual dlls. If you want a seperate dlls for each class then each should be in a seperate class library project.

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

Compiling one C# Project into another

I have a C# Application that uses some other Assemblies, so when I compile, I end up with my .exe and 2 or 3 other .dll Files. Ideally, I only want 1 .exe file. At the moment I use ILMerge for that, but as the Assemblies that I use are Open Source (and under the same license), I wonder if there is an easy way to add them to my Solution and compile them into the .exe?
What I do not want:
Creating a Subfolder in my main .exe and copying all the other files into it
Adding it as a separate solution but then add it to my .exe Project with "Add as Link"
I suppose that ILMerge is more or less doing exactly what I want, but if I can apply the merging on a compiler level already, that would be what I want.
Needless to say, the referenced assemblies have no main() function, so no clashes are to be expected.
You could add the dependencies as embedded resources and then load them manually but this would require a code change so it's not ideal.
I think that ILMerge is your best option here.
As I never tried this, I don't know if this will work and/or meet your expectations, but, there's an option of compiling .net code to a netmodule, instead of an assembly, and then those modules, theoretically, could be added to other assemblies, You can read about it here and here.

Categories