ILMerge | ILMerge is a static linker for .NET Assemblies | Code Editor library

 by   dotnet C# Version: Current License: MIT

kandi X-RAY | ILMerge Summary

kandi X-RAY | ILMerge Summary

ILMerge is a C# library typically used in Editor, Code Editor, Unity applications. ILMerge has no bugs, it has no vulnerabilities, it has a Permissive License and it has medium support. You can download it from GitHub.

ILMerge is a utility that merges multiple .NET assemblies into a single assembly. It is freely available for use and is available as a NuGet package. If you have any problems using it, please get in touch. (mbarnett at microsoft dot com). But first try reading the documentation. ILMerge takes a set of input assemblies and merges them into one target assembly. The first assembly in the list of input assemblies is the primary assembly. When the primary assembly is an executable, then the target assembly is created as an executable with the same entry point as the primary assembly. Also, if the primary assembly has a strong name, and a .snk file is provided, then the target assembly is re-signed with the specified key so that it also has a strong name. ILMerge is packaged as a console application. But all of its functionality is also available programmatically. There are several options that control the behavior of ILMerge. See the documentation that comes with the tool for details. The current version is 3.0.29 (released on 10 April 2019). NOTE: There is no longer a version of ILMerge that runs in the v1.1 runtime. ILMerge runs in the v4.0 .NET Runtime, but it is also able to merge assemblies from other framework versions using the /targetplatformoption. Please see the documentation. (However, it can merge PDB files only for v2 (and later) assemblies.). Currently, ILMerge works only on Windows-based platforms. It does not yet support Rotor or Mono. If you use ASP.NET v2.0, then it provides a tool (based on ILMerge) to combine assemblies created during precompilation. You can get more details from the ASP.NET web site.
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              ILMerge has a medium active ecosystem.
              It has 1121 star(s) with 151 fork(s). There are 110 watchers for this library.
              OutlinedDot
              It had no major release in the last 6 months.
              There are 51 open issues and 23 have been closed. On average issues are closed in 225 days. There are 1 open pull requests and 0 closed requests.
              It has a neutral sentiment in the developer community.
              The latest version of ILMerge is current.

            kandi-Quality Quality

              ILMerge has 0 bugs and 0 code smells.

            kandi-Security Security

              ILMerge has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              ILMerge code analysis shows 0 unresolved vulnerabilities.
              There are 0 security hotspots that need review.

            kandi-License License

              ILMerge is licensed under the MIT License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              ILMerge releases are not available. You will need to build from source code and install.
              Installation instructions, examples and code snippets are available.

            Top functions reviewed by kandi - BETA

            kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.
            Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of ILMerge
            Get all kandi verified functions for this library.

            ILMerge Key Features

            No Key Features are available at this moment for ILMerge.

            ILMerge Examples and Code Snippets

            No Code Snippets are available at this moment for ILMerge.

            Community Discussions

            QUESTION

            .NET Core 6.0 standalone binary compilation
            Asked 2022-Feb-16 at 22:07

            I'm trying to create a .NET Core 6.0 binary as a standalone, with all dependencies packaged in one .exe file.

            The trouble I am having is that whilst the binary compiles ok it is reliant on the DLLs placed in the Release/Debug folder.

            I have tried compiling from the command line with

            ...

            ANSWER

            Answered 2022-Feb-16 at 21:24

            I'd suggest looking at https://docs.microsoft.com/en-us/dotnet/core/deploying/single-file which should hopefully be up to date. I believe the key bit is true in the .csproj.

            Source https://stackoverflow.com/questions/71149379

            QUESTION

            ILMerge - "Unresolved assembly reference not allowed", RestSharp Nuget package in the packages folder
            Asked 2022-Jan-27 at 23:51

            Context: I'm writing a CRM Plugin, trying to use a recent version of RestSharp. I'm trying to use ILMerge to merge in RestSharp (and its dependencies such as the listed error) into the Plugin DLL.

            Merged assemblies: ... source\repos\MyCRMVSSolution\packages\System.Runtime.CompilerServices.Unsafe.5.0.0\lib\net45\System.Runtime.CompilerServices.Unsafe.dll; ...

            error : Unresolved assembly reference not allowed: System.Runtime.CompilerServices.Unsafe.

            See above, the "merged assemblies" command shows that it knows where the file is under /packages/, and it knows to try to Merge it. Yet it says it's an unresolved reference.

            Why could it come back saying "Unresolved" for it? Not sure what to even review or debug. It's apparently reading it right where I want it to, under packages. But somehow not.

            Using the Nuget package MSBuild.ILMerge.Task, with default/OOTB configuration.

            ...

            ANSWER

            Answered 2022-Jan-27 at 23:48

            Downgrade to a RestSharp version that has 0 dependencies. That way, you'll avoid ILMerge trying to find and manage all its dependencies.

            Example RestSharp Nuget package that has 0 dependencies:

            Comments:

            Overall with ILMerge for CRM Plugins, it's wise to put as little dependence on it as possible to do the right thing... limit 3rd party DLL's that need to be Merged as much as possible. Take that very seriously to avoid wasted battles with ILMerge.

            Source https://stackoverflow.com/questions/70856236

            QUESTION

            SQL Server database project in VS. Order of sql script generation step in build process
            Asked 2021-Jun-24 at 14:18

            I have a SQL Sever database project in my solution and several dependencies projects.

            When I compiling (in VS) this database project I've get a SQL script and a .dacpac file as result.

            But also I want to aggregate all my dependencies projects in one dll and make SQL script/.dacpac file only for this result dll.

            I'm using ILMerge.MSBuild.Tasks.ILMerge to aggregate all dll on AfterBuild event in sqlproj. But this aggregation happens after generating SQL script.

            How can I enforce SQL script generation in the end?

            Build log:

            ...

            ANSWER

            Answered 2021-Jun-23 at 15:21

            Interesting question. I don't know of any easy way to do this, or if it's even possible in the first place. However, there are two options that I know of for altering the build process:

            Option 1

            Inject a build step / target. SSDT is missing at least two build steps/targets — "BeforeSqlBuild" and "BeforePublish" — because the "AfterBuild" target is too late in the process (as you have discovered).

            To get around the "CLR strict security" debacle introduced in SQL Server 2017 (documented in the following post of mine: SQLCLR vs. SQL Server 2017, Part 3: “CLR strict security” – Solution 2), I updated the .sqlproj file by placing the following at the end, just before the closing tag (to sign the assembly with a certificate):

            Source https://stackoverflow.com/questions/68088045

            QUESTION

            Some metadata tokens for local variable types invalid after rewrite with dnlib
            Asked 2021-May-16 at 10:18

            What I am doing (partly for fun and learning, partly hopefully as a serious virtualization effort someday) is merging my VM dll with a target assembly via ILMerge.

            Only afterwards I modify the newly created file with dnlib to replace the method bodies of selected methods with a call to my VM function. I pass the required metadata that is now absent in the method itself via a base64 encoded binary string and obviously the arguments and the old method body too (in the future I want to implement my own bytecode instruction set for that, but so far its just the original code base64-encoded).

            Since .initlocals is from my experience always set in a .NET method, what I want to do is save the type of every local as data in such a way that I can initialize my local array in the Virtualizer runtime with it.

            My current approach is just to save the MDToken writer.Write(local.Type.ToTypeDefOrRef().GetNonNestedTypeRefScope().MDToken.ToInt32());

            I write my changes to the assembly with the PreserveAll flag opts.MetadataOptions.Flags = dnlib.DotNet.Writer.MetadataFlags.PreserveAll;

            and in the runtime resolve the MDToken via

            ...

            ANSWER

            Answered 2021-May-16 at 10:18

            However, a metadata token is not a persistent identifier. Rather it is scoped to a specific metadata binary.

            What it's saying is that the metadata token is only meaningful within the scope of the module, you can't take the metadata token from one module and use it in another or even within a modified version of the same module (or at least not reliably).

            The reason for this makes more sense when you consider what the metadata token really is. The metadata token is a reference to a record in a metadata table within the module, and that record contains further details; the high-order byte of the metadata token indicates the type of token (and thus the table containing the record), while the remaining 3 bytes indicate the row number.

            If you take a metadata token from one module and try to use it in another module, you are assuming that the same record in each module represents the same thing. If you compile the same code with the same compiler, then this assumption may hold; but if you change the source or use a different compiler (or different version of the same compiler) then the row numbers may change for any number of reasons.

            And why does this problem not occur at all in the method body instructions? Many instructions encode an InlineType and Module.ResolveType has never failed there.

            Because the compiler emitting the IL with the metadata token is also emitting the tables into the same file. The compiler is able to keep these things in sync.

            And, more importantly, how to fix? How do I save a reliable type identifier in a binary form for the locals of a method?

            The only reliable way to reference a type between modules, is with the full type name and scope (the containing assembly, module or type in the case of a nested type).

            Source https://stackoverflow.com/questions/67456382

            QUESTION

            CRM using ILMerge to merge framework library with plugin projects
            Asked 2021-Apr-07 at 12:28

            I have two assemblies:

            1. Main plugin assembly - Plugin used for my project
            2. Framework assembly - I want to merge this assembly with the main plugin so I can reuse some common methods used a lot in different projects.

            I installed ILMerge on the main plugin assembly and referenced the built out framework dlls while simultaneously setting project build order on the solution.

            Now, this looks okay before I deploy. The main problem comes when I try to debug using my unit tests project.

            In my unit tests project, I have a reference to the main plugin assembly which allows me to use fakexrmeasy to run my unit tests. However, now that the assemblies have been merged I expect that I should be able to use the framework methods within my unit tests project. I cant seem to access those methods when referencing the main plugin assemblies in the test classes.

            All of the projects mentioned above exist within the same solution.

            Im fairly new to ILMerge so might be doing something wrong thats glaringly obvious. I just compile using the built in visual studio compiler.

            Can anyone suggest what could be going wrong?

            ...

            ANSWER

            Answered 2021-Apr-07 at 12:28

            First, my advice is to use ILRepack, since ILMerge is no longer being actively maintained. ILRepack is based on ILMerge and is open source. Add NuGet package ILRepack.Lib.MSBuild.Task to your project.

            Then add this file to your project and name it ILRepack.targets:

            Source https://stackoverflow.com/questions/66815639

            QUESTION

            ILMerge - use wildcard and specify main assembly
            Asked 2021-Feb-17 at 20:42

            I have main assembly MyAssembly.dll and a lot of libraries which I want to merge into main assembly. Because there are lots of them, I wanted to include them all using wildcard, something like this:

            ILMerge.exe /wildcard /allowDup /out:MyAssembly.Merged.dll MyAssembly.dll *.dll

            The problem with this approach is that it merges MyAssembly.dll twice, resulting in duplicated type names, so need to use /allowDup option. But this option renames duplicated types, and I don't want that (my DLL is a plugin for other application and all types must have original names). I could omit MyAssembly.dll in command line, but because ILMerge merges assemblies alphabetically, it treats the first one as a main assembly (for example Autofac.dll) which results in final assembly having wrong metadata (version etc.). Is it possible to exclude certain assembly name with wildcard option?

            ...

            ANSWER

            Answered 2021-Feb-17 at 20:42

            Is it possible to exclude certain assembly name with wildcard option?

            No. You could write a batch file that builds the command line though, using for for example. You could also write a script in another language.

            However ilmerge is an artefact of the past and it has a whole slew of problems. Since it copies the code into one assembly it changes how run-time loading works, which can easily break lazy-loaded programs like WPF or ASP.NET Core.

            Nowadays we have .Net5 which provides first-class support for single-assembly binaries, both that run under the installed environment (like your assembly used to need) or self-contained (it includes the .net5 runtime as well). It doesn't mash together the code into one assembly, it sticks to separate assemblies loaded at run-time directly from your generated large "assembly", so your actual code doesn't change.

            Source https://stackoverflow.com/questions/66249568

            QUESTION

            Consume all source code (non-compiled) from one project into another (PDFSharp)
            Asked 2021-Jan-12 at 21:38

            As the title says, I want to consume all of PDFSharp's source code into my own project. But let me explain why I came to this scenario, so if there is something else I can do, maybe there are other options.

            Goal: Compile my project into a single .exe file to use. No installers. Problem: It uses PDFSharp.dll which is causing me issues.

            What I am trying to do, is use ILMerge to create the .exe. I've used this successfully in the past for other projects.

            The issue I think is that ILMerge is requiring references to other assemblies that PDFSharp uses. The first being Microsoft.ApplicationInsights. So to by-pass this, I installed Microsoft.ApplicationInsights into my project via Nuget. Then removed the actual reference from the project, but referenced the library in my ILMerge command as below:

            ...

            ANSWER

            Answered 2021-Jan-12 at 21:38

            I have this working now, so I just wanted to place my results here since it is already posted.

            My initial problem was that I mistakenly thought the PDFSharp.dll was causing the issue, but it was actually another group of 3rd Party dlls I was referencing.

            I tried for hours to get iLMerge to work with the only success being it would kick out a single .exe file but it would have runtime errors.

            Errors that I encountered:

            Error: Unresolved assembly reference not allowed: Custom.Assembly.

            Solution: Reference the assembly if possible. If you have many, you can reference a folder with the /lib:"C:\folderpath" switch.

            Error: Unresolved assembly reference not allowed: ADotNetFramework.dll.

            Solution: You can reference the desired .Net Framework path where iLMerge will search for missing references. Example: /targetplatform:"v4,C:.NETFramework\v4.8"

            Error: The assembly 'xyz.dll' was not merged in correctly. It is still listed as an external reference in the target assembly.

            Solution: You can get past this error with the /closed switch. However, I don't think I should even have gotten this error because 'xyz.dll' was a referenced dll to be combined.

            Also - use the /log switch, it is extremely helpful in seeing exactly what iLMerge is doing and figuring out your issue. Example: /log:mylog.txt

            This allowed me to see that iLMerge was finding duplicate namespaces, in the 3rd Party assemblies and automatically renaming them. Here is an example from my log:

            Merging assembly 'My.Assembly.Name' into target assembly. Duplicate type name: modifying name of the type '<>f__AnonymousType02' (from assembly 'My.Assembly.Name') to 'My.Assembly.Name.<>f__AnonymousType02' Duplicate type name: modifying name of the type '<>f__AnonymousType12' (from assembly 'My.Assembly.Name') to 'My.Assembly.Name.<>f__AnonymousType12' Duplicate type name: modifying name of the type '' (from assembly 'My.Assembly.Name') to 'My.Assembly.Name.

            Finally - the solution that I found was not to use iLMerge. I found this Answer: https://stackoverflow.com/a/40786196/2596309 which used Costura.Fody I installed the nuget package with:

            Source https://stackoverflow.com/questions/65671458

            QUESTION

            Embedded a DLL into the exe through ILMerge, I can't access the dll
            Asked 2020-Dec-03 at 02:40

            Problem: I embedded a DLL into the exe through ILMerge, but this dll has no dependency relationship with the exe. Now I want to find the dll in the exe, what do I need to do?
            Details:
            I embedded all resources into the DLL, all logic code is EXE. I don't want to compile exe again, only modify the resource dll to change the exe's skin.
            Then , I meet the problem.

            ...

            ANSWER

            Answered 2020-Dec-03 at 02:39
            1. To find the DLL in the EXE using the EXE code, use reflection on the EXE's assembly and look for the DLL's entry point class.

            2. To not compile the EXE again when merging a different DLL, keep the original EXE around and when the DLL changes, ilmerge the changed DLL instead (carefully still keeping the original EXE around). Note that ILMerging the changed DLL into the EXE the original DLL was merged into almost works but not quite.

            Source https://stackoverflow.com/questions/65118838

            QUESTION

            'Could not load assembly', but the assembly is already loaded
            Asked 2020-Nov-24 at 13:12

            I am working on a simple WPF app which makes use of two external DLLs, Nancy.dll and Nancy.Hosting.Self.dll to send some data over http. I'd like to keep the .exe file standalone so I'm trying to merge the two .dll files into the application. I tried multiple post-build merging methods such as NetZ and ILMerge, but both seem to have problems with wpf applications and didn't output a working executable.

            There is this post which has multiple suggestions for going about this problem, although they all boil down to the same two things:

            1. Use a post-build merger. This doesn't work well in my case.
            2. Put the DLL into the application as an embedded resource, and make use of the AppDomain.CurrentDomain.AssemblyResolve event to load it when necessary.

            The second option seemed promising: the event gets triggered, it finds the embedded resource, makes a datastream out of it and loads it as an assembly. I can verify the assembly is loaded in multiple ways:
            Visual Studio's Debug -> Windows -> Modules shows the loaded assembly, and
            AppDomain.CurrentDomain.GetAssemblies() also shows the assembly being loaded.

            However, when it comes to using the assemblies (in this case calling Nancy.Hosting.Self.NancyHost host = new NancyHost();) I still get the following error:

            ...

            ANSWER

            Answered 2020-Nov-24 at 13:12

            I didn't really want to go and look for something else, as Nancy's just working fine for me. What I ended up doing instead was writing the dll to where I knew nancy was going to look for it, initialize that bootstrapper, and remove the data again:

            Source https://stackoverflow.com/questions/64909350

            QUESTION

            Dual project solution, one is dll- embed code into main project?
            Asked 2020-Sep-02 at 03:07

            I writing and open-source winforms app, and my program depends on another open-source project called ObjectListView.

            ObjectListView is its own project in my solution and referenced as such, but its output is set as a .DLL.. It's just an enhanced ListView control. Is there any way that the project ObjectListView can be embedded in my own assembly without having to ILMerge or use some form of packer? (Defeating the purpose of an open-source project)

            My initial thought was just to manually drop all the source files and whatnot into my own project, but that seems rather clunky and far from an idea solution.

            PS; I did try searching for this but I didn't come across much that wasn't related to embedding DLLs into an output assembly.. Not merging projects like this. I apologize in advance if this question has been answered before.

            ...

            ANSWER

            Answered 2020-Sep-02 at 03:07

            If you don't want a separate DLL, and you don't want an embedded DLL, then perhaps a "Shared Project" project type is what you're looking for. The docs state:

            A Shared Project does not get compiled on its own, it exists purely as a grouping of source code files that can be included in other projects. When referenced by another project, the code is effectively compiled as part of that project. Shared Projects cannot reference any other project type (including other Shared Projects).

            While I don't think your project is exactly what it's intended for, I think it will work in your scenario.

            See What is the difference between a Shared Project and a Class Library in Visual Studio 2015? for more information.

            Source https://stackoverflow.com/questions/63684900

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install ILMerge

            As noted on the ilmerge NuGet page, the package can be installed from the Visual Studio environment. Expand the project container in the Solution Explorer view. Right click on references and select Manage NuGet Packages. Ensure the Package source is set to nuget.org. Next, click on Tools - NuGet Package Manager - Package Manager Console. Ensure the Package source is also set to nuget.org.

            Support

            For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            CLONE
          • HTTPS

            https://github.com/dotnet/ILMerge.git

          • CLI

            gh repo clone dotnet/ILMerge

          • sshUrl

            git@github.com:dotnet/ILMerge.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link