assembly-rewriter 0.9.0

There is a newer version of this package available.
See the version list below for details.
dotnet tool install --global assembly-rewriter --version 0.9.0                
This package contains a .NET tool you can call from the shell/command line.
dotnet new tool-manifest # if you are setting up this repo
dotnet tool install --local assembly-rewriter --version 0.9.0                
This package contains a .NET tool you can call from the shell/command line.
#tool dotnet:?package=assembly-rewriter&version=0.9.0                
nuke :add-package assembly-rewriter --version 0.9.0                

assembly-rewriter

Rewrites .NET assemblies with Mono.Cecil, to allow two different versions of the same assembly to be referenced within an application.

It assumes that the assembly DLL name is the top level namespace and rewrites

  1. the top level namespace for all types within the assembly
  2. assemblies in the order of dependencies first
  3. IL ldstr op codes if they start with the namespace
  4. compiler generated backing fields

This small program was written to allow different versions Elasticsearch .NET clients to be rewritten for benchmark comparisons. Your mileage may vary rewriting other assemblies 😃

Installation

Distributed as a .NET tool so install using the following

dotnet tool install assembly-rewriter

Run

dotnet assembly-rewriter

You can omit dotnet if you install this as a global tool

Examples

Rewrite NEST, the Elasticsearch .NET high level client, version 6.2.0

assembly-rewriter -i C:/Nest.dll -o C:/Nest620.dll

Now, Nest620.dll and another version of Nest.dll can be referenced in the same project.

There's a small issue here however; both versions of NEST rely on Elasticsearch.Net.dll, so we should also rewrite this dependency at the same time, and update the references to Elasticsearch.Net within NEST to reference the new rewritten assembly

assembly-rewriter -i C:/Nest.dll -o C:/Nest620.dll -i C:/Elasticsearch.Net.dll -o C:/Elasticsearch.Net620.dll

Great! Now we can reference both in the same project.

If there are other direct dependencies that may version clash, these can be passed as well

assembly-rewriter -i C:/Nest.dll -o C:/Nest620.dll -i C:/Elasticsearch.Net.dll -o C:/Elasticsearch.Net620.dll -i C:/Newtonsoft.Json.dll -o C:/Newtonsoft.Json620.dll

Rewrite validation

You can check to see if everything expected has been rewritten using IL Disassembler

ildasm <rewritten>.dll /OUT=<rewritten>.il /NOBAR
Select-String -Path <rewritten>.il -Pattern '<original namespace>\.' -AllMatches | ft LineNumber,Line

License

Apache 2.0

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.0 is compatible.  netcoreapp3.1 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

Version Downloads Last updated
0.13.0 2,214 6/30/2023
0.12.0 58,015 11/16/2020
0.11.0 1,761 9/18/2020
0.10.0 2,549 5/19/2020
0.9.1 491 5/15/2020
0.9.0 494 5/1/2020