@@ -16,6 +16,7 @@ open UnitTests.TestLib.ProjectSystem
1616open Microsoft.VisualStudio .FSharp .ProjectSystem
1717open Microsoft.VisualStudio .Shell .Interop
1818open Microsoft.Win32
19+ open System.Xml .Linq
1920
2021[<TestFixture>]
2122type References () =
@@ -618,4 +619,60 @@ type References() =
618619// look for the new property inside of the project file
619620let contents = File.ReadAllText( newProjFileName)
620621 AssertContains contents newPropVal
621- )
622+ )
623+
624+
625+ [<Test>]
626+ member public this. ``AddReference.COM`` () =
627+ DoWithTempFile" Test.fsproj" ( fun projFile ->
628+ File.AppendAllText( projFile, TheTests.SimpleFsprojText([], [], " " ))
629+ use project= TheTests.CreateProject( projFile)
630+
631+ let guid = Guid( " 50a7e9b0-70ef-11d1-b75a-00a0c90564fe" )
632+
633+ let selectorData = VSCOMPONENTSELECTORDATA(
634+ `` type `` = VSCOMPONENTTYPE.VSCOMPONENTTYPE_ Com2,
635+ guidTypeLibrary= guid,
636+ wTypeLibraryMinorVersion= 0 us,
637+ wTypeLibraryMajorVersion= 1 us,
638+ bstrTitle= " Microsoft Shell Controls And Automation" )
639+ let refContainer = GetReferenceContainerNode( project)
640+
641+ let comReference = refContainer.AddReferenceFromSelectorData( selectorData)
642+
643+ // check reference node properties
644+ Assert.IsNotNull comReference
645+ Assert.IsInstanceOf( typeof< ComReferenceNode>, comReference)
646+ let comRef = comReference:?> ComReferenceNode
647+ Assert.AreEqual( 1 , comRef.MajorVersionNumber)
648+ Assert.AreEqual( 0 , comRef.MinorVersionNumber)
649+ Assert.AreEqual( guid, comRef.TypeGuid)
650+ Assert.AreEqual( " Microsoft Shell Controls And Automation" , comRef.Caption)
651+ let sysDirectory = Environment.GetFolderPath( Environment.SpecialFolder.SystemX86)
652+ StringAssert.AreEqualIgnoringCase( Path.Combine( sysDirectory, " shell32.dll" ), comRef.InstalledFilePath)
653+
654+ // check node exists under references
655+ let l = new List< ComReferenceNode>()
656+ project.FindNodesOfType( l)
657+
658+ Assert.AreEqual( 1 , l.Count)
659+ let referenceNode = l.[ 0 ]
660+ Assert.AreSame( comRef, referenceNode)
661+
662+ // check saved msbuild item
663+ SaveProject( project)
664+ let fsproj = XDocument.Load( project.FileName)
665+ printfn" %O " fsproj
666+ let xn s = fsproj.Root.GetDefaultNamespace() .GetName( s)
667+ let comReferencesXml = fsproj.Descendants( xn" COMReference" ) |> Seq.toList
668+
669+ Assert.AreEqual( 1 , comReferencesXml|> List.length)
670+
671+ let comRefXml = comReferencesXml|> List.head
672+
673+ Assert.AreEqual( " Microsoft Shell Controls And Automation" , comRefXml.Attribute( XName.Get( " Include" )) .Value)
674+ Assert.AreEqual( guid, Guid( comRefXml.Element( xn" Guid" ) .Value))
675+ Assert.AreEqual( " 1" , comRefXml.Element( xn" VersionMajor" ) .Value)
676+ Assert.AreEqual( " 0" , comRefXml.Element( xn" VersionMinor" ) .Value)
677+ Assert.AreEqual( " 0" , comRefXml.Element( xn" Lcid" ) .Value)
678+ )