The following snippet does the trick:
var path = Assembly.GetAssembly(typeof(MyAssembly.SomeClass)).Location;
var asm = AssemblyMetadata.CreateFromFile(path).GetReference();
var options = ScriptOptions.Default.AddReferences(asm);
This following works too and it uses Linq to get the loaded assembly:
var asm = AppDomain.CurrentDomain.GetAssemblies()
.SingleOrDefault(assembly => assembly.GetName().Name == "MyAssembly");
This however gets the loaded assemblies. If the assembly you need is not already loaded, get them using Assembly.GetExecutingAssembly().GetReferencedAssemblies()
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…