Using C# .NET with COM interop in VS2012, I'm developing a common library for use in several other programs. To keep the integration simple, I would like to keep the entire library down to one DLL. One of the features of this library is localization. It has string tables with messages in multiple languages, each language having it's own ResX file.

Presently, a MyLibrary.resources.dll is being created for each language and placed in its own subdirectory, like this:

Release\MyLibrary.dll
Release\ja\MyLibrary.resources.dll
Release\fr\MyLibrary.resources.dll

What I want to see is just this:

Release\MyLibrary.dll

Here are my current ResX settings.

ResX settings

I have tried using ResXFileCodeGenerator and GlobalResourceProxyGenerator for the "Custom Tool" generators. I also tried a few options for "Build Action" including Compile, but so far only Embedded Resource works. Other than that I'm not sure what else to try or if I'm on the right track. There aren't really that many settings to work with.

I am aware that there are a variety of tools that may work to do this after building the DLL, but I'm looking for a compile-time solution. Third party tools are challenging from a maintenance standpoint -- I will not be the only one updating this library.

有帮助吗?

解决方案

There are two main ways of embedding libraries into a single DLL or executable. The first uses ILMerge, combines all assemblies as if it was a single assembly; the second is dynamically loading dependencies from embedded resource(s) at runtime (offers a bit more flexibility, but has its own set of pros and cons). The sample project is intended to be portable (the only dependency is Powershell -- all required libraries are included in the project).

It's important to know the difference between the two techniques. I've written articles outlining both approaches with a sample project on github for both approaches.

Articles:

Assembly Loading: Combine Assemblies & Executables Using ilMerge

AND

Assembly Loading: Dynamic Assembly Loading & Compression

Sample Project:

Application Demonstrating Both ILMerge and Runtime Loading of Embedded Assemblies

If you have any questions regarding either approach, don't hesitate to get in touch. I'll gladly refine the posts based on your feedback.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top