Code Monkey home page Code Monkey logo

dotnet-assembly-alias's Introduction

Alias

Build status NuGet Status NuGet Status

Rename assemblies and fixes references. Designed as an alternative to Costura, ILMerge, and ILRepack.

See Milestones for release notes.

Designed to mitigate scenarios where an assembly is run in a plugin scenario. For example Unity extensions, MSBuild tasks, or SharePoint extensions. In these scenarios an assembly, and all its references, are loaded into a shared AppDomain. So dependencies operate as "first on wins". So, for example, if two addins assemblies use different versions of Newtonsoft, the first addin that is loaded defines what version of Newtonsoft is used by all subsequent addins assemblies.

This project works around this problem by renaming references and preventing name conflicts.

dotnet tool

https://www.nuget.org/packages/Alias/

.net 6 or higher is required to run this tool.

For a given directory and a subset of assemblies:

  • Changes the assembly name of each "alias" assembly.
  • Renames "alias" assemblies on disk.
  • For all assemblies, fixes the references to point to the new alias assemblies.

Installation

Ensure dotnet CLI is installed.

Install Alias

dotnet tool install --global Alias

Usage

assemblyalias --target-directory "C:/Code/TargetDirectory"
              --suffix _Alias
              --assemblies-to-alias "Microsoft*;System*;EmptyFiles"

Arguments

Target Directory

-t or --target-directory

Optional. If no directory is passed the current directory will be used.

Internalize

-i or --internalize

Optional. To internalize all types in the aliased assemblies. Defaults to false.

Prefix/Suffix

Either a prefix or suffix must be defined.

Prefix

-p or --prefix

The prefix to use when renaming assemblies.

Suffix

-s or --suffix

The suffix to use when renaming assemblies.

Assemblies to alias

-a or --assemblies-to-alias

Required. A semi-colon separated list of assembly names to alias. Names ending in * are treated as wildcards.

Assemblies to exclude

-e or --assemblies-to-exclude

Optional. A semi-colon separated list of assembly names to exclude.

Key

-k or --key

Path to an snk file.

Optional. If no key is passed, strong naming will be removed from all assemblies.

References

-r or --references

Optional. A semi-colon separated list of paths to reference files.

Reference File

--reference-file

Optional. A path to a file containing references file paths. One file path per line.

Default Reference File

By default the target directory will be scanned for a reference file named alias-references.txt

It can be helpful to extract reference during a build using msbuild and write them to a file accessible to Alias:

<Target Name="WriteReferenceForAlias" AfterTargets="AfterCompile">
  <ItemGroup>
    <ReferenceForAlias Include="@(ReferencePath)" Condition="'%(FileName)' == 'CommandLine'" />
  </ItemGroup>
  <WriteLinesToFile File="$(TargetDir)/alias-references.txt" Lines="%(ReferenceForAlias.FullPath)" Overwrite="true" />
</Target>

snippet source | anchor

dotnet-assembly-alias's People

Contributors

bchavez avatar bruno-garcia avatar foxyseta avatar simoncropp avatar tyrrrz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

dotnet-assembly-alias's Issues

Aliasing Marc Gravell's protobuf-net

Environment

Alias 0.4.3+82222e7b7486be0ad379f4e0a9fb9adfb1107278

Steps to Reproduce

  1. dotnet tool install --global Alias
  2. dotnet add package protobuf-net --version 3.2.26
  3. assemblyalias.exe --suffix _Alias --assemblies-to-alias "protobuf-net*"

Expected Result

The last command gets executed successfully. All the "protobuf-net*" assemblies get aliased correctly ("_Alias" is added to the end of their namespaces) and all the references to them are patched accordingly.

Actual Result

Internalize: False
Suffix: _Alias
AssembliesToAlias:
 * protobuf-net*
Resolved assemblies to alias:
 * protobuf-net.Core
 * protobuf-net

Could not load assembly: System.Xml. It may need to exist in the target directory, or be added to the reference list.

Issues with .net framework project

Hey Simon, thanks a lot for this project - DLL hell is a very familiar issue, as our project has several plugins for various applications.

We've successfully used Alias on a .net standard project (this one called Core), but we're running into issues when running it on a .net framework project (this one, for example, which actually references Core).

Are there any known limitations with .net framework?

Curiously, the error I'm getting is thrown when the ModuleReaaderWriter is processing Sentry.dll (reference in Core) and it complains that "System.dll" is not found, as a matter of fact, it's not present in the bin folder, but afaik it is not needed there.

If you'd like to reproduce it yourself, you need to:

  • build this project
  • use my Fork so it can properly exclude some mixed code assemblies (will improve my PR soon!)
  • run it with --target-directory "[...]\bin\Debug" --suffix _Speckle --assemblies-to-alias "Serilog*" --assemblies-to-exclude "lib*;e_sqlite*;Tmds*;Revit*"

I tried manually copying System.dll in the bin folder, and this made Alias run correctly, but we got other exceptions about methods missing when running our plugin.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.