/// <summary> /// Loads assembly with given identity. /// </summary> /// <param name="identity">The assembly identity.</param> /// <returns>Loaded assembly.</returns> public Assembly Load(AssemblyIdentity identity) { if (!string.IsNullOrEmpty(identity.Location)) { RegisterDependency(identity); } // don't let the CLR load the assembly from the CodeBase, which uses LoadFrom semantics (we want LoadFile): return(Assembly.Load(identity.ToAssemblyName(setCodeBase: false))); }
/// <summary> /// Loads assembly with given identity. /// </summary> /// <param name="identity">The assembly identity.</param> /// <param name="location">Location of the assembly.</param> /// <returns>Loaded assembly.</returns> public override Assembly Load(AssemblyIdentity identity, string location = null) { if (!string.IsNullOrEmpty(location)) { RegisterDependency(identity, location); } // Don't let the CLR load the assembly from the CodeBase (location), // which uses LoadFrom semantics (we want LoadFile): return(Assembly.Load(identity.ToAssemblyName())); }
public void ToAssemblyName() { var ai = new AssemblyIdentity("goo"); var an = ai.ToAssemblyName(); Assert.Equal("goo", an.Name); Assert.Equal(new Version(0, 0, 0, 0), an.Version); Assert.Equal(CultureInfo.InvariantCulture, an.CultureInfo); AssertEx.Equal(new byte[0], an.GetPublicKeyToken()); AssertEx.Equal(null, an.GetPublicKey()); Assert.Equal(AssemblyNameFlags.None, an.Flags); Assert.Null(an.CodeBase); ai = new AssemblyIdentity( "goo", new Version(1, 2, 3, 4), "en-US", RoPublicKey1, hasPublicKey: true, isRetargetable: true ); an = ai.ToAssemblyName(); Assert.Equal("goo", an.Name); Assert.Equal(new Version(1, 2, 3, 4), an.Version); Assert.Equal(CultureInfo.GetCultureInfo("en-US"), an.CultureInfo); AssertEx.Equal(PublicKeyToken1, an.GetPublicKeyToken()); AssertEx.Equal(PublicKey1, an.GetPublicKey()); Assert.Equal(AssemblyNameFlags.PublicKey | AssemblyNameFlags.Retargetable, an.Flags); Assert.Null(an.CodeBase); // invalid characters are ok in the name, the FullName can't be built though: foreach (char c in ClrInvalidCharacters) { ai = new AssemblyIdentity(c.ToString()); an = ai.ToAssemblyName(); Assert.Equal(c.ToString(), an.Name); Assert.Equal(new Version(0, 0, 0, 0), an.Version); Assert.Equal(CultureInfo.InvariantCulture, an.CultureInfo); AssertEx.Equal(new byte[0], an.GetPublicKeyToken()); AssertEx.Equal(null, an.GetPublicKey()); Assert.Equal(AssemblyNameFlags.None, an.Flags); AssertEx.Equal(null, an.CodeBase); } }
private MSB.Evaluation.ProjectItem FindReferenceItem(AssemblyIdentity identity, string filePath) { var references = _loadedProject.GetItems("Reference"); MSB.Evaluation.ProjectItem item = null; if (identity != null) { var shortAssemblyName = identity.Name; var fullAssemblyName = identity.ToAssemblyName().FullName; // check for short name match item = references.FirstOrDefault(it => string.Compare(it.EvaluatedInclude, shortAssemblyName, StringComparison.OrdinalIgnoreCase) == 0); // check for full name match if (item == null) { item = references.FirstOrDefault(it => string.Compare(it.EvaluatedInclude, fullAssemblyName, StringComparison.OrdinalIgnoreCase) == 0); } } // check for file path match if (item == null) { string relativePath = FilePathUtilities.GetRelativePath(_loadedProject.DirectoryPath, filePath); item = references.FirstOrDefault(it => FilePathUtilities.PathsEqual(it.EvaluatedInclude, filePath) || FilePathUtilities.PathsEqual(it.EvaluatedInclude, relativePath)); } // check for partial name match if (item == null && identity != null) { var partialName = identity.Name + ","; var items = references.Where(it => it.EvaluatedInclude.StartsWith(partialName, StringComparison.OrdinalIgnoreCase)).ToList(); if (items.Count == 1) { item = items[0]; } } return(item); }
private static ModuleBuilder CreateDynamicModule(AssemblyBuilderAccess access, AssemblyIdentity name, string fileName) { var assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(name.ToAssemblyName(), access); if (DisableJitOptimizations) { assemblyBuilder.SetCustomAttribute(new CustomAttributeBuilder( typeof(DebuggableAttribute).GetConstructor(new[] { typeof(DebuggableAttribute.DebuggingModes) }), new object[] { DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations })); } const string moduleName = "InteractiveModule"; if (access == AssemblyBuilderAccess.RunAndSave) { return(assemblyBuilder.DefineDynamicModule(moduleName, fileName, emitSymbolInfo: false)); } else { return(assemblyBuilder.DefineDynamicModule(moduleName, emitSymbolInfo: false)); } }
public void AddMetadataReference(MetadataReference reference, AssemblyIdentity identity) { var peRef = reference as PortableExecutableReference; if (peRef != null && peRef.FilePath != null) { var metadata = new Dictionary <string, string>(); if (!peRef.Properties.Aliases.IsDefault && peRef.Properties.Aliases.Length > 0) { metadata.Add("Aliases", string.Join(",", peRef.Properties.Aliases)); } if (IsInGAC(peRef.FilePath) && identity != null) { _loadedProject.AddItem("Reference", identity.ToAssemblyName().FullName, metadata); } else { string relativePath = FilePathUtilities.GetRelativePath(_loadedProject.DirectoryPath, peRef.FilePath); _loadedProject.AddItem("Reference", relativePath, metadata); } } }
public void ToAssemblyName_Errors() { var ai = new AssemblyIdentity("goo", cultureName: "*"); Assert.Throws <CultureNotFoundException>(() => ai.ToAssemblyName()); }
public void ToAssemblyName() { var ai = new AssemblyIdentity("foo"); var an = ai.ToAssemblyName(); Assert.Equal("foo", an.Name); Assert.Equal(new Version(0, 0, 0, 0), an.Version); Assert.Equal(CultureInfo.InvariantCulture, an.CultureInfo); AssertEx.Equal(new byte[0], an.GetPublicKeyToken()); AssertEx.Equal(null, an.GetPublicKey()); Assert.Equal(AssemblyNameFlags.None, an.Flags); Assert.Equal(null, an.CodeBase); ai = new AssemblyIdentity("foo", new Version(1, 2, 3, 4), "en-US", RoPublicKey1, hasPublicKey: true, isRetargetable: true); an = ai.ToAssemblyName(); Assert.Equal("foo", an.Name); Assert.Equal(new Version(1, 2, 3, 4), an.Version); Assert.Equal(CultureInfo.GetCultureInfo("en-US"), an.CultureInfo); AssertEx.Equal(PublicKeyToken1, an.GetPublicKeyToken()); AssertEx.Equal(PublicKey1, an.GetPublicKey()); Assert.Equal(AssemblyNameFlags.PublicKey | AssemblyNameFlags.Retargetable, an.Flags); Assert.Equal(null, an.CodeBase); // invalid characters are ok in the name, the FullName can't be built though: foreach (char c in ClrInvalidCharacters) { ai = new AssemblyIdentity(c.ToString()); an = ai.ToAssemblyName(); Assert.Equal(c.ToString(), an.Name); Assert.Equal(new Version(0, 0, 0, 0), an.Version); Assert.Equal(CultureInfo.InvariantCulture, an.CultureInfo); AssertEx.Equal(new byte[0], an.GetPublicKeyToken()); AssertEx.Equal(null, an.GetPublicKey()); Assert.Equal(AssemblyNameFlags.None, an.Flags); AssertEx.Equal(null, an.CodeBase); } }
public System.Reflection.Assembly Load(AssemblyIdentity identity) { return(System.Reflection.Assembly.Load(identity.ToAssemblyName(setCodeBase: false))); }
public override Assembly Load(AssemblyIdentity identity, string location = null) { return(Assembly.Load(identity.ToAssemblyName())); }
public System.Reflection.Assembly Load(AssemblyIdentity identity) { return System.Reflection.Assembly.Load(identity.ToAssemblyName(setCodeBase: false)); }
/// <summary> /// Loads assembly with given identity. /// </summary> /// <param name="identity">The assembly identity.</param> /// <returns>Loaded assembly.</returns> public Assembly Load(AssemblyIdentity identity) { if (!string.IsNullOrEmpty(identity.Location)) { RegisterDependency(identity); } // don't let the CLR load the assembly from the CodeBase, which uses LoadFrom semantics (we want LoadFile): return Assembly.Load(identity.ToAssemblyName(setCodeBase: false)); }
public void ToAssemblyName_Errors() { var ai = new AssemblyIdentity("foo", cultureName: "*"); Assert.Throws<CultureNotFoundException>(() => ai.ToAssemblyName()); }