/// <summary> /// Creating AssemblyReferenceNode via VS UI ("Add Reference" or otherwise) /// </summary> private AssemblyReferenceNode(ProjectNode root, string assemblyFullPath, AddReferenceDialogTab tab) : base(root) { // Validate the input parameters. if (null == root) { throw new ArgumentNullException("root"); } if (string.IsNullOrEmpty(assemblyFullPath)) { throw new ArgumentNullException("assemblyFullPath"); } ResolveAssemblyReferenceByFullPath(assemblyFullPath, tab); this.InitializeFileChangeEvents(); }
/// <summary> /// Creating AssemblyReferenceNode via VS UI ("Add Reference" or otherwise) /// </summary> private AssemblyReferenceNode(ProjectNode root, string assemblyFullPath, AddReferenceDialogTab tab) : base(root) { // Validate the input parameters. if (null == root) { throw new ArgumentNullException("root"); } if (string.IsNullOrEmpty(assemblyFullPath)) { throw new ArgumentNullException("assemblyFullPath"); } ResolveAssemblyReferenceByFullPath(assemblyFullPath, tab); this.InitializeFileChangeEvents(); }
private void ResolveAssemblyReferenceByFullPath(string assemblyFullPath, AddReferenceDialogTab tab) { if (this.ProjectMgr == null || this.ProjectMgr.IsClosed) { return; } bool isValidPath = false; try { isValidPath = Path.IsPathRooted(assemblyFullPath); } catch (ArgumentException) { } Debug.Assert(isValidPath, string.Format("Expected assemblyFullPath to be a full path, but it was {0}", assemblyFullPath)); // AddComPlusReferenceByFullPath Action<string> Trace = (s) => FSharpTrace.PrintLine("ProjectSystemReferenceResolution", () => "ResolveAssemblyReferenceByFullPath: " + s); Trace("starting: \""+assemblyFullPath+"\""); this.msbuildProjectionInfo.WantHintPath = false; this.msbuildProjectionInfo.WantFusionName = false; this.msbuildProjectionInfo.WantSpecificVersion = null; try { var simpleName = System.IO.Path.GetFileNameWithoutExtension(assemblyFullPath); AddToProjectFileAndTryResolve(simpleName); } catch (Exception) { } if (!this.resolvedInfo.WasSuccessfullyResolved) { Trace("simple name resolution did not succeed"); this.msbuildProjectionInfo.WantHintPath = true; AddToProjectFileAndTryResolve(assemblyFullPath); } else { this.myAssemblyPath = assemblyFullPath; Trace("simple name resolution succeeded"); // we successfully resolved it via simple name if (!this.resolvedInfo.IsPlatformAssembly) { Trace("not a platform assembly"); if (resolvedInfo.AssemblyName != null) { // Project file contains different reference than picked/shown in UI // code in this class tries to mimic the behavior in vsproject\langbuild\langref.cpp\785480\langref.cpp // it also uses simple name for initial resolution attempt // however after that it repopulates ComPlus attributes from the source assembly via SetComPlusAttributesFromFullPath // this part was previously skipped - as a result AssemblyName contained invalid data var assemblyName = AssemblyName.GetAssemblyName(assemblyFullPath); resolvedInfo.AssemblyName = assemblyName; resolvedInfo.ResolvedAssemblyName = assemblyName; } if (tab == AddReferenceDialogTab.DotNetTab) { Trace("from .Net tab"); this.msbuildProjectionInfo.WantFusionName = true; this.msbuildProjectionInfo.WantSpecificVersion = true; } else { Debug.Assert(tab == AddReferenceDialogTab.BrowseTab); Trace("not from .Net tab"); this.msbuildProjectionInfo.WantHintPath = true; } } else { // platform assemblies can just resolve to simple name Trace("it was a platform assembly"); } } // TODO - not accounting for case described below // if <re-resolving fusion name with SpecificVersion fails> then // { // this is possible if this reference is being added through automation // in which case the file passed may have a different fusion name than // the assembly in the target framework/fx extensions. // in that case just add with a hint path // wantHintPath = true; // } if (this.msbuildProjectionInfo.WantHintPath) { this.msbuildProjectionInfo.WantSpecificVersion = false; } if (this.myAssemblyPath == null) { this.myAssemblyPath = assemblyFullPath; } if (!this.resolvedInfo.WasSuccessfullyResolved) { this.ProjectMgr.AddReferenceCouldNotBeAddedErrorMessage(assemblyFullPath); } Trace("finished: \"" + assemblyFullPath + "\""); }
internal static AssemblyReferenceNode CreateFromFullPathViaUIAddReference(ProjectNode root, string assemblyFullPath, AddReferenceDialogTab tab) { return new AssemblyReferenceNode(root, assemblyFullPath, tab); }
/// <summary> /// Creates an assembly reference node from a file path. /// </summary> internal virtual AssemblyReferenceNode CreateAssemblyReferenceNode(string assemblyInclude, AddReferenceDialogTab tab, bool isFullPath) { AssemblyReferenceNode node = null; try { if (isFullPath) { node = AssemblyReferenceNode.CreateFromFullPathViaUIAddReference(this.ProjectMgr, assemblyInclude, tab); } else { node = AssemblyReferenceNode.CreateFromAssemblyNameViaUIAutomation(this.ProjectMgr, assemblyInclude); } } catch (ArgumentNullException e) { Trace.WriteLine("Exception : " + e.Message); } catch (FileNotFoundException e) { Trace.WriteLine("Exception : " + e.Message); } catch (BadImageFormatException e) { Trace.WriteLine("Exception : " + e.Message); } catch (FileLoadException e) { Trace.WriteLine("Exception : " + e.Message); } catch (System.Security.SecurityException e) { Trace.WriteLine("Exception : " + e.Message); } return node; }
/// <summary> /// Creates an assemby or com reference node given a selector data. /// </summary> internal virtual ReferenceNode CreateFileComponent(VSCOMPONENTSELECTORDATA selectorData, AddReferenceDialogTab tab) { if (null == selectorData.bstrFile) { throw new ArgumentNullException("selectordata.bstrFile"); } // Support the "*<assemblyName>" format that Cider uses if (selectorData.bstrFile.StartsWith("*")) { var assemblyNameStr = selectorData.bstrFile.Substring(1); return this.CreateAssemblyReferenceNode(assemblyNameStr, tab, false /*isFullPath*/); } ReferenceNode node = null; try { node = this.CreateAssemblyReferenceNode(selectorData.bstrFile, tab, true); } catch(InvalidOperationException) { // If the selector doesn't have a guid, it means we didn't go through the COM tab. This means // that we are either adding a reference via automation, or manually browsing to a TLB. if (selectorData.guidTypeLibrary == Guid.Empty) { try { node = this.CreateComReferenceNode(selectorData.bstrFile); } catch (COMException) { // Ignore all the TLB exceptions } } else { node = this.CreateComReferenceNode(selectorData); } } if (node == null) { this.ProjectMgr.AddReferenceCouldNotBeAddedErrorMessage(selectorData.bstrFile); } return node; }
private void ResolveAssemblyReferenceByFullPath(string assemblyFullPath, AddReferenceDialogTab tab) { if (this.ProjectMgr == null || this.ProjectMgr.IsClosed) { return; } bool isValidPath = false; try { isValidPath = Path.IsPathRooted(assemblyFullPath); } catch (ArgumentException) { } Debug.Assert(isValidPath, string.Format("Expected assemblyFullPath to be a full path, but it was {0}", assemblyFullPath)); this.msbuildProjectionInfo.WantHintPath = false; this.msbuildProjectionInfo.WantFusionName = false; this.msbuildProjectionInfo.WantSpecificVersion = null; try { var simpleName = System.IO.Path.GetFileNameWithoutExtension(assemblyFullPath); AddToProjectFileAndTryResolve(simpleName); } catch (Exception) { } if (!this.resolvedInfo.WasSuccessfullyResolved) { this.msbuildProjectionInfo.WantHintPath = true; AddToProjectFileAndTryResolve(assemblyFullPath); } else { this.myAssemblyPath = assemblyFullPath; // we successfully resolved it via simple name if (!this.resolvedInfo.IsPlatformAssembly) { // not a platform assembly if (resolvedInfo.AssemblyName != null) { // Project file contains different reference than picked/shown in UI // code in this class tries to mimic the behavior in vsproject\langbuild\langref.cpp\785480\langref.cpp // it also uses simple name for initial resolution attempt // however after that it repopulates ComPlus attributes from the source assembly via SetComPlusAttributesFromFullPath // this part was previously skipped - as a result AssemblyName contained invalid data var assemblyName = AssemblyName.GetAssemblyName(assemblyFullPath); resolvedInfo.AssemblyName = assemblyName; resolvedInfo.ResolvedAssemblyName = assemblyName; } if (tab == AddReferenceDialogTab.DotNetTab) { // from .Net tab this.msbuildProjectionInfo.WantFusionName = true; this.msbuildProjectionInfo.WantSpecificVersion = true; } else { Debug.Assert(tab == AddReferenceDialogTab.BrowseTab); // not from .Net tab this.msbuildProjectionInfo.WantHintPath = true; } } else { // platform assemblies can just resolve to simple name // it was a platform assembly } } // TODO - not accounting for case described below // if <re-resolving fusion name with SpecificVersion fails> then // { // this is possible if this reference is being added through automation // in which case the file passed may have a different fusion name than // the assembly in the target framework/fx extensions. // in that case just add with a hint path // wantHintPath = true; // } if (this.msbuildProjectionInfo.WantHintPath) { this.msbuildProjectionInfo.WantSpecificVersion = false; } if (this.myAssemblyPath == null) { this.myAssemblyPath = assemblyFullPath; } if (!this.resolvedInfo.WasSuccessfullyResolved) { this.ProjectMgr.AddReferenceCouldNotBeAddedErrorMessage(assemblyFullPath); } // "finished: assemblyFullPath }
internal static AssemblyReferenceNode CreateFromFullPathViaUIAddReference(ProjectNode root, string assemblyFullPath, AddReferenceDialogTab tab) { return(new AssemblyReferenceNode(root, assemblyFullPath, tab)); }
/// <summary> /// Creates an assembly reference node from a file path. /// </summary> internal virtual AssemblyReferenceNode CreateAssemblyReferenceNode(string assemblyInclude, AddReferenceDialogTab tab, bool isFullPath) { AssemblyReferenceNode node = null; try { if (isFullPath) { node = AssemblyReferenceNode.CreateFromFullPathViaUIAddReference(this.ProjectMgr, assemblyInclude, tab); } else { node = AssemblyReferenceNode.CreateFromAssemblyNameViaUIAutomation(this.ProjectMgr, assemblyInclude); } } catch (ArgumentNullException e) { Trace.WriteLine("Exception : " + e.Message); } catch (FileNotFoundException e) { Trace.WriteLine("Exception : " + e.Message); } catch (BadImageFormatException e) { Trace.WriteLine("Exception : " + e.Message); } catch (FileLoadException e) { Trace.WriteLine("Exception : " + e.Message); } catch (System.Security.SecurityException e) { Trace.WriteLine("Exception : " + e.Message); } return(node); }
/// <summary> /// Creates an assemby or com reference node given a selector data. /// </summary> internal virtual ReferenceNode CreateFileComponent(VSCOMPONENTSELECTORDATA selectorData, AddReferenceDialogTab tab) { if (null == selectorData.bstrFile) { throw new ArgumentNullException("selectordata.bstrFile"); } // Support the "*<assemblyName>" format that Cider uses if (selectorData.bstrFile.StartsWith("*")) { var assemblyNameStr = selectorData.bstrFile.Substring(1); return(this.CreateAssemblyReferenceNode(assemblyNameStr, tab, false /*isFullPath*/)); } ReferenceNode node = null; try { node = this.CreateAssemblyReferenceNode(selectorData.bstrFile, tab, true); } catch (InvalidOperationException) { // If the selector doesn't have a guid, it means we didn't go through the COM tab. This means // that we are either adding a reference via automation, or manually browsing to a TLB. if (selectorData.guidTypeLibrary == Guid.Empty) { try { node = this.CreateComReferenceNode(selectorData.bstrFile); } catch (COMException) { // Ignore all the TLB exceptions } } else { node = this.CreateComReferenceNode(selectorData); } } if (node == null) { this.ProjectMgr.AddReferenceCouldNotBeAddedErrorMessage(selectorData.bstrFile); } return(node); }