public void GetDisplayName() { var id = new AssemblyIdentity("foo"); Assert.Equal("foo, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", id.GetDisplayName()); id = new AssemblyIdentity("foo", new Version(1, 2, 3, 4)); Assert.Equal("foo, Version=1.2.3.4, Culture=neutral, PublicKeyToken=null", id.GetDisplayName()); id = new AssemblyIdentity("foo", cultureName: "en-US"); Assert.Equal("foo, Version=0.0.0.0, Culture=en-US, PublicKeyToken=null", id.GetDisplayName()); id = new AssemblyIdentity("foo", publicKeyOrToken: new byte[] { 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF }.AsImmutableOrNull()); Assert.Equal("foo, Version=0.0.0.0, Culture=neutral, PublicKeyToken=0123456789abcdef", id.GetDisplayName(), StringComparer.OrdinalIgnoreCase); id = new AssemblyIdentity("foo", isRetargetable: true); Assert.Equal("foo, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null, Retargetable=Yes", id.GetDisplayName()); id = new AssemblyIdentity("foo", contentType: AssemblyContentType.WindowsRuntime); Assert.Equal("foo, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime", id.GetDisplayName()); id = new AssemblyIdentity("Foo", publicKeyOrToken: RoPublicKey1, hasPublicKey: true); string dn1 = id.GetDisplayName(); string dn2 = id.GetDisplayName(fullKey: false); Assert.True(ReferenceEquals(dn1, dn2), "cached full name expected"); Assert.Equal("Foo, Version=0.0.0.0, Culture=neutral, PublicKeyToken=" + StrPublicKeyToken1, dn1); string dnFull = id.GetDisplayName(fullKey: true); Assert.Equal("Foo, Version=0.0.0.0, Culture=neutral, PublicKey=" + StrPublicKey1, dnFull); id = new AssemblyIdentity("Foo", cultureName: "neutral"); Assert.Equal("Foo, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", id.GetDisplayName()); id = new AssemblyIdentity("Foo", cultureName: " '\t\r\n\\=, "); Assert.Equal(@"Foo, Version=0.0.0.0, Culture="" \'\t\r\n\\\=\, "", PublicKeyToken=null", id.GetDisplayName()); }
public ModuleData( AssemblyIdentity identity, OutputKind kind, ImmutableArray <byte> image, ImmutableArray <byte> pdb, bool inMemoryModule ) { this.Id = new ModuleDataId(identity.Name, identity.GetDisplayName(), GetMvid(image)); this.Kind = kind; this.Image = image; this.Pdb = pdb; this.InMemoryModule = inMemoryModule; }
public override void ReportDuplicateMetadataReferenceWeak( DiagnosticBag diagnostics, Location location, MetadataReference reference, AssemblyIdentity identity, MetadataReference equivalentReference, AssemblyIdentity equivalentIdentity ) { diagnostics.Add( ErrorCode.ERR_DuplicateImportSimple, location, identity.Name, reference.Display ?? identity.GetDisplayName() ); }
private MSB.Evaluation.ProjectItem FindReferenceItem(AssemblyIdentity identity, string filePath) { var references = _loadedProject.GetItems(ItemNames.Reference); MSB.Evaluation.ProjectItem item = null; var fileName = Path.GetFileNameWithoutExtension(filePath); if (identity != null) { var shortAssemblyName = identity.Name; var fullAssemblyName = identity.GetDisplayName(); // 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) { var relativePath = PathUtilities.GetRelativePath(_loadedProject.DirectoryPath, filePath); item = references.FirstOrDefault(it => PathUtilities.PathsEqual(it.EvaluatedInclude, filePath) || PathUtilities.PathsEqual(it.EvaluatedInclude, relativePath) || PathUtilities.PathsEqual(GetHintPath(it), filePath) || PathUtilities.PathsEqual(GetHintPath(it), 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); }
public static async Task <CodeAction> CreateAsync(Project project, AssemblyIdentity missingAssemblyIdentity, CancellationToken cancellationToken) { var dependencyGraph = project.Solution.GetProjectDependencyGraph(); // We want to find a project that generates this assembly, if one so exists. We therefore // search all projects that our project with an error depends on. We want to do this for // complicated and evil scenarios like this one: // // C -> B -> A // // A' // // Where, for some insane reason, A and A' are two projects that both emit an assembly // by the same name. So imagine we are using a type in B from C, and we are missing a // reference to A.dll. Both A and A' are candidates, but we know we can throw out A' // since whatever type from B we are using that's causing the error, we know that type // isn't referencing A'. Put another way: this code action adds a reference, but should // never change the transitive closure of project references that C has. // // Doing this filtering also means we get to check less projects (good), and ensures that // whatever project reference we end up adding won't add a circularity (also good.) foreach (var candidateProjectId in dependencyGraph.GetProjectsThatThisProjectTransitivelyDependsOn(project.Id)) { var candidateProject = project.Solution.GetRequiredProject(candidateProjectId); if (candidateProject.SupportsCompilation && string.Equals(missingAssemblyIdentity.Name, candidateProject.AssemblyName, StringComparison.OrdinalIgnoreCase)) { // The name matches, so let's see if the full identities are equal. var compilation = await candidateProject.GetRequiredCompilationAsync(cancellationToken).ConfigureAwait(false); if (missingAssemblyIdentity.Equals(compilation.Assembly.Identity)) { // It matches, so just add a reference to this return(new AddMissingReferenceCodeAction(project, string.Format(FeaturesResources.Add_project_reference_to_0, candidateProject.Name), new ProjectReference(candidateProjectId), missingAssemblyIdentity)); } } } // No matching project, so metadata reference var description = string.Format(FeaturesResources.Add_reference_to_0, missingAssemblyIdentity.GetDisplayName()); return(new AddMissingReferenceCodeAction(project, description, null, missingAssemblyIdentity)); }
public static async Task<CodeAction> CreateAsync(Project project, AssemblyIdentity missingAssemblyIdentity, CancellationToken cancellationToken) { var dependencyGraph = project.Solution.GetProjectDependencyGraph(); // We want to find a project that generates this assembly, if one so exists. We therefore // search all projects that our project with an error depends on. We want to do this for // complicated and evil scenarios like this one: // // C -> B -> A // // A' // // Where, for some insane reason, A and A' are two projects that both emit an assembly // by the same name. So imagine we are using a type in B from C, and we are missing a // reference to A.dll. Both A and A' are candidates, but we know we can throw out A' // since whatever type from B we are using that's causing the error, we know that type // isn't referencing A'. Put another way: this code action adds a reference, but should // never change the transitive closure of project references that C has. // // Doing this filtering also means we get to check less projects (good), and ensures that // whatever project reference we end up adding won't add a circularity (also good.) foreach (var candidateProjectId in dependencyGraph.GetProjectsThatThisProjectTransitivelyDependsOn(project.Id)) { var candidateProject = project.Solution.GetProject(candidateProjectId); if (string.Equals(missingAssemblyIdentity.Name, candidateProject.AssemblyName, StringComparison.OrdinalIgnoreCase)) { // The name matches, so let's see if the full identities are equal. var compilation = await candidateProject.GetCompilationAsync(cancellationToken).ConfigureAwait(false); if (missingAssemblyIdentity.Equals(compilation.Assembly.Identity)) { // It matches, so just add a reference to this return new AddMissingReferenceCodeAction(project, string.Format(FeaturesResources.Add_project_reference_to_0, candidateProject.Name), new ProjectReference(candidateProjectId), missingAssemblyIdentity); } } } // No matching project, so metadata reference var description = string.Format(FeaturesResources.Add_reference_to_0, missingAssemblyIdentity.GetDisplayName()); return new AddMissingReferenceCodeAction(project, description, null, missingAssemblyIdentity); }
/// <summary> /// Attempt to construct a <see cref="MetadataReader"/> instance for this module. /// </summary> /// <returns>Returns 'false' for modules with "bad" or missing metadata.</returns> private unsafe static bool TryGetMetadataReader(GetMetadataBytesPtrFunction getMetaDataBytesPtrFunction, AssemblyIdentity assemblyIdentity, out IntPtr ptr, out int size, out MetadataReader reader) { var assemblyName = assemblyIdentity.GetDisplayName(); try { uint uSize; ptr = getMetaDataBytesPtrFunction(assemblyIdentity, out uSize); size = (int)uSize; reader = new MetadataReader((byte *)ptr, size); return(true); } catch (Exception e) when(MetadataUtilities.IsBadOrMissingMetadataException(e, assemblyName)) { ptr = IntPtr.Zero; size = 0; reader = null; return(false); } }
public override PortableExecutableReference ResolveMissingAssembly(MetadataReference definition, AssemblyIdentity referenceIdentity) { // look in the GAC: if (GacFileResolver != null && referenceIdentity.IsStrongName) { var path = GacFileResolver.Resolve(referenceIdentity.GetDisplayName()); if (path != null) { return(CreateResolvedMissingReference(path)); } } // look into a directory containing CorLib: if (_useCoreResolver) { var result = ResolveTrustedPlatformAssemblyCore(referenceIdentity.Name, s_resolvedMissingAssemblyReferenceProperties); if (result != null) { return(result); } } // look in the directory of the requesting definition: string definitionPath = (definition as PortableExecutableReference)?.FilePath; if (definitionPath != null) { string pathWithoutExtension = PathUtilities.CombinePathsUnchecked(PathUtilities.GetDirectoryName(definitionPath), referenceIdentity.Name); foreach (string extension in AssemblyExtensions) { string fullPath = pathWithoutExtension + extension; if (File.Exists(fullPath)) { return(CreateResolvedMissingReference(fullPath)); } } } return(null); }
PEAssemblySymbol CreateAssemblyFromIdentity(MetadataReferenceResolver resolver, AssemblyIdentity identity, string basePath, List <PEModuleSymbol> modules) { PEAssemblySymbol ass; if (!_observedMetadata.TryGetValue(identity, out ass)) { // temporary: lookup ignoring minor version number foreach (var pair in _observedMetadata) { // TODO: _identityComparer if (pair.Key.Name.Equals(identity.Name, StringComparison.OrdinalIgnoreCase) && pair.Key.Version.Major == identity.Version.Major) { _observedMetadata[identity] = pair.Value; return(pair.Value); } } // string keytoken = string.Join("", identity.PublicKeyToken.Select(b => b.ToString("x2"))); var pes = resolver.ResolveReference(identity.Name + ".dll", basePath, MetadataReferenceProperties.Assembly) .Concat(resolver.ResolveReference($"{identity.Name}/v4.0_{identity.Version}__{keytoken}/{identity.Name}.dll", basePath, MetadataReferenceProperties.Assembly)); var pe = pes.FirstOrDefault(); if (pe != null) { _observedMetadata[identity] = ass = PEAssemblySymbol.Create(pe); ass.SetCorLibrary(_lazyCorLibrary); modules.AddRange(ass.Modules.Cast <PEModuleSymbol>()); } else { // TODO: diagnostics throw new DllNotFoundException(identity.GetDisplayName()); } } return(ass); }
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.IsEmpty) { metadata.Add("Aliases", string.Join(",", peRef.Properties.Aliases)); } if (IsInGAC(peRef.FilePath) && identity != null) { _loadedProject.AddItem("Reference", identity.GetDisplayName(), metadata); } else { string relativePath = FilePathUtilities.GetRelativePath(_loadedProject.DirectoryPath, peRef.FilePath); _loadedProject.AddItem("Reference", relativePath, metadata); } } }
private AssemblyName GetAssemblyName(string fullPath) { using (var stream = PortableShim.File.OpenRead(fullPath)) { using (var peReader = new PEReader(stream)) { var reader = peReader.GetMetadataReader(); var assemblyDef = reader.GetAssemblyDefinition(); var name = reader.GetString(assemblyDef.Name); var cultureName = assemblyDef.Culture.IsNil ? null : reader.GetString(assemblyDef.Culture); var publicKeyOrToken = reader.GetBlobContent(assemblyDef.PublicKey); var hasPublicKey = !publicKeyOrToken.IsEmpty; if (publicKeyOrToken.IsEmpty) { publicKeyOrToken = default(ImmutableArray <byte>); } var identity = new AssemblyIdentity( name: name, version: assemblyDef.Version, cultureName: cultureName, publicKeyOrToken: publicKeyOrToken, hasPublicKey: hasPublicKey, isRetargetable: (assemblyDef.Flags & AssemblyFlags.Retargetable) != 0, contentType: (AssemblyContentType)((int)(assemblyDef.Flags & AssemblyFlags.ContentTypeMask) >> 9)); return(new AssemblyName(identity.GetDisplayName())); } } }
private Assembly Resolve(object sender, ResolveEventArgs args) { if (!args.Name.StartsWith(_assemblyNamePrefix)) { return(null); } lock (this) { if (args.Name == dynamicAssemblyName.GetDisplayName()) { return(_dynamicModule != null ? _dynamicModule.Assembly : null); } if (_dynamicModule != null && _dynamicModule.Assembly == args.RequestingAssembly || _fallBackAssemblies != null && _fallBackAssemblies.Contains(args.RequestingAssembly)) { int comma = args.Name.IndexOf(','); return(ResolveNoLock(args.Name.Substring(0, (comma != -1) ? comma : args.Name.Length))); } } return(null); }
public void GetDisplayName() { var id = new AssemblyIdentity("foo"); Assert.Equal("foo, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", id.GetDisplayName()); id = new AssemblyIdentity("foo", new Version(1, 2, 3, 4)); Assert.Equal("foo, Version=1.2.3.4, Culture=neutral, PublicKeyToken=null", id.GetDisplayName()); id = new AssemblyIdentity("foo", cultureName: "en-US"); Assert.Equal("foo, Version=0.0.0.0, Culture=en-US, PublicKeyToken=null", id.GetDisplayName()); id = new AssemblyIdentity("foo", publicKeyOrToken: new byte[] { 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF }.AsImmutableOrNull()); Assert.Equal("foo, Version=0.0.0.0, Culture=neutral, PublicKeyToken=0123456789abcdef", id.GetDisplayName(), StringComparer.OrdinalIgnoreCase); id = new AssemblyIdentity("foo", isRetargetable: true); Assert.Equal("foo, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null, Retargetable=Yes", id.GetDisplayName()); id = new AssemblyIdentity("foo", contentType: AssemblyContentType.WindowsRuntime); Assert.Equal("foo, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime", id.GetDisplayName()); id = new AssemblyIdentity("Foo", publicKeyOrToken: RoPublicKey1, hasPublicKey: true); string dn1 = id.GetDisplayName(); string dn2 = id.GetDisplayName(fullKey: false); Assert.True(ReferenceEquals(dn1, dn2), "cached full name expected"); Assert.Equal("Foo, Version=0.0.0.0, Culture=neutral, PublicKeyToken=" + StrPublicKeyToken1, dn1); string dnFull = id.GetDisplayName(fullKey: true); Assert.Equal("Foo, Version=0.0.0.0, Culture=neutral, PublicKey=" + StrPublicKey1, dnFull); }
public override void ReportDuplicateMetadataReferenceWeak(DiagnosticBag diagnostics, Location location, MetadataReference reference, AssemblyIdentity identity, MetadataReference equivalentReference, AssemblyIdentity equivalentIdentity) { diagnostics.Add(ErrorCode.ERR_DuplicateImportSimple, location, identity.Name, reference.Display ?? identity.GetDisplayName()); }
private string GetDebuggerDisplay() => IsDefault ? "uninitialized" : Identity.GetDisplayName() + (LocationOpt != null ? " @ " + LocationOpt : "");
private AssemblyName GetAssemblyName(string fullPath) { using (var stream = PortableShim.File.OpenRead(fullPath)) { using (var peReader = new PEReader(stream)) { var reader = peReader.GetMetadataReader(); var assemblyDef = reader.GetAssemblyDefinition(); var name = reader.GetString(assemblyDef.Name); var cultureName = assemblyDef.Culture.IsNil ? null : reader.GetString(assemblyDef.Culture); var publicKeyOrToken = reader.GetBlobContent(assemblyDef.PublicKey); var hasPublicKey = !publicKeyOrToken.IsEmpty; if (publicKeyOrToken.IsEmpty) { publicKeyOrToken = default(ImmutableArray<byte>); } var identity = new AssemblyIdentity( name: name, version: assemblyDef.Version, cultureName: cultureName, publicKeyOrToken: publicKeyOrToken, hasPublicKey: hasPublicKey, isRetargetable: (assemblyDef.Flags & AssemblyFlags.Retargetable) != 0, contentType: (AssemblyContentType)((int)(assemblyDef.Flags & AssemblyFlags.ContentTypeMask) >> 9)); return new AssemblyName(identity.GetDisplayName()); } } }
public override string ToString() { return($"{Reference.Display} -> {Identity.GetDisplayName()}"); }
string Cci.IAssemblyReference.GetDisplayName() { return(MetadataIdentity.GetDisplayName()); }
public override Assembly Load(AssemblyIdentity identity, string location = null) { return(_manager.GetAssembly(identity.GetDisplayName(), reflectionOnly: false)); }
private void TestQuotingAndEscaping(string simpleName, string expectedSimpleName) { var ai = new AssemblyIdentity(simpleName); var dn = ai.GetDisplayName(); Assert.Equal(expectedSimpleName + ", Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", dn); TestParseSimpleName(dn, simpleName); }
public override void Apply(Workspace workspace, CancellationToken cancellationToken = default(CancellationToken)) { var visualStudioWorkspace = (VisualStudioWorkspaceImpl)workspace; if (!visualStudioWorkspace.TryAddReferenceToProject(_projectId, "*" + _assemblyIdentity.GetDisplayName())) { // We failed to add the reference, which means the project system wasn't able to bind. // We'll pop up the Add Reference dialog to let the user figure this out themselves. // This is the same approach done in CVBErrorFixApply::ApplyAddMetaReferenceFix var uiHierarchy = visualStudioWorkspace.GetHierarchy(_projectId) as IVsUIHierarchy; OLECMD[] command = new OLECMD[1]; command[0].cmdID = (uint)VSConstants.VSStd2KCmdID.ADDREFERENCE; if (ErrorHandler.Succeeded(uiHierarchy.QueryStatusCommand((uint)VSConstants.VSITEMID.Root, VSConstants.VSStd2K, 1, command, IntPtr.Zero))) { if ((((OLECMDF)command[0].cmdf) & OLECMDF.OLECMDF_ENABLED) != 0) { uiHierarchy.ExecCommand((uint)VSConstants.VSITEMID.Root, VSConstants.VSStd2K, (uint)VSConstants.VSStd2KCmdID.ADDREFERENCE, 0, IntPtr.Zero, IntPtr.Zero); } } } }
string IAssemblyReference.GetDisplayName() { return(_identity.GetDisplayName()); }
private CompatDifference CreateIdentityDifference(string format, string leftProperty, string rightProperty, string leftName, string rightName, AssemblyIdentity identity) => new CompatDifference(DiagnosticIds.AssemblyIdentityMustMatch, string.Format(format, leftProperty, rightProperty, leftName, rightName), DifferenceType.Changed, identity.GetDisplayName());
public override void Apply(Workspace workspace, CancellationToken cancellationToken = default(CancellationToken)) { var mdWorkspace = workspace as MonoDevelopWorkspace; if (mdWorkspace == null) { return; // no md workspace -> not a common file/ignore. } var mdProject = mdWorkspace.GetMonoProject(projectId) as MonoDevelop.Projects.DotNetProject; if (mdProject == null) { LoggingService.LogWarning("Can't find project " + projectId + " to add reference " + assemblyIdentity.GetDisplayName()); return; } var newReference = MonoDevelop.Projects.ProjectReference.CreateAssemblyReference(assemblyIdentity.GetDisplayName()); foreach (var r in mdProject.References) { if (r.ReferenceType == newReference.ReferenceType && r.Reference == newReference.Reference) { LoggingService.LogWarning("Warning duplicate reference is added " + newReference.Reference); return; } } mdProject.References.Add(newReference); IdeApp.ProjectOperations.SaveAsync(mdProject); }