Skip to content

CSScriptLib: allow referencing assemblies with aliases #465

Description

@oleg-shilo

Triggered by #464

What?

It should be possible to specify an alias when referencing the assembly so it can be used in the script code to allo mapiing very specific version of teh ref assembly:

var scriptCode = @"
  extern alias util_v1;
  using Util_1 = util_v1::Util;
  using System;
  public class Script
  {
	public string GetGreeting(string name) => new Util_1().GetGreeting(name);
  }";

dynamic script = CSScript.Evaluator
            .ReferenceAssembly(asmFile, "util_v1")
            .LoadCode(scriptCode);

How?

In PrepareRefAssemblies(), will need to replace AddReferences(assembly) path with explicit metadata ref creation:

var mdRef = MetadataReference.CreateFromFile(
    assembly.Location(),
    new MetadataReferenceProperties().WithAliases(new[] { "util_v1" })
);

CompilerSettings = CompilerSettings.AddReferences(mdRef);

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions