How do I merge multiple .net assemblies into a single assembly?
Try ILMerge. NuGet package here
Try ILMerge. NuGet package here
Yes there is – sort of. Use the excellent little utility by by Einar Egilsson, InjectModuleInitializer. Run this executable as a post build step to create a small .cctor function (the module initializer function) that calls a static void function of yours that takes no parameters. It would be nice if compiler gave us the … Read more
No, there’s no shortcut for this, although LINQ makes it relatively easy. For example, in C# the raw “set of namespaces” would be: var namespaces = assembly.GetTypes() .Select(t => t.Namespace) .Distinct(); To get the top-level namespace instead you should probably write a method: var topLevel = assembly.GetTypes() .Select(t => GetTopLevelNamespace(t)) .Distinct(); … static string GetTopLevelNamespace(Type … Read more
This seems to be a reliable, simple way to get the “entry” or main assembly for a web app. If you put controllers in a separate project, you may find that the base class of ApplicationInstance is not in the same assembly as your MVC project that contains the Views – but, this setup seems … Read more
There are 2 parts of your question: How to configure solutions to build assemblies/EXE into folders of your choice – this is configured through properties of the project in VS (project properties -> build -> output path). Also value of check “copy local” property on each reference. How to load assemblies files from non-default locations … Read more
I work on the CLR/BCL team and just answered your email. Here it is pasted below: Jared’s answer on Stack Overflow is right on. mscorlib.dll is tightly bound to the CLR for the reasons he mentions. Note that mscorlib.dll itself doesn’t contain any native code (as Scott suggests), but there are many places where it … Read more
I used the advice from this article to get an assembly from the GAC. Get DLL Out of The GAC DLLs once deployed in GAC (normally located at c:\windows\assembly) can’t be viewed or used as a normal DLL file. They can’t be directly referenced from VS project. Developers usually keep a copy of the original … Read more
Thanks to leppie’s suggestion of using the AppDomain.AssemblyResolve event, I was able to solve a similar problem. Here’s what my code looks like: public void LoadStuff(string assemblyFile) { AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve); var assembly = Assembly.LoadFrom(assemblyFile); // Now load a bunch of types from the assembly… } Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args) { var name … Read more
The .NET Framework defers loading assemblies into the current AppDomain until they’re needed. For example, if you call into a third-party library only from SomeMethod(), the third-party DLL normally won’t be loaded until the first time SomeMethod() runs. AppDomain.GetAssemblies() gives you all assemblies which have already been loaded into the current AppDomain. BuildManager.GetReferencedAssemblies() (This method … Read more
This is a shameless copy-paste from I Note It Down and is a simple way to get the FQN for the project output: Open Visual Studio Go to Tools –> External Tools –> Add Title: Get Qualified Assembly Name Command: Powershell.exe Arguments: -command “[System.Reflection.AssemblyName]::GetAssemblyName(\”$(TargetPath)\”).FullName” Check “Use Output Window”. The new tool appears under Tools –> … Read more