private void ResolveAssemblyReferenceByFullPath()

in vsintegration/src/FSharp.ProjectSystem.Base/Project/AssemblyReferenceNode.cs [468:562]


        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 
        }