Exemple #1
0
        public void CheckAddMissingTlbReference()
        {
            TYPELIBATTR      axAttr, tlbAttr, piaAttr, notInProjectAttr;
            ComReferenceInfo axRefInfo, tlbRefInfo, piaRefInfo;

            CreateTestReferences(out axRefInfo, out tlbRefInfo, out piaRefInfo,
                                 out axAttr, out tlbAttr, out piaAttr, out notInProjectAttr);

            var rcr = new ResolveComReference();

            rcr.BuildEngine = new MockEngine();

            // populate the ResolveComReference's list of project references
            rcr.allProjectRefs = new List <ComReferenceInfo>();
            rcr.allProjectRefs.Add(axRefInfo);
            rcr.allProjectRefs.Add(tlbRefInfo);
            rcr.allProjectRefs.Add(piaRefInfo);

            rcr.AddMissingTlbReferences();

            Assert.Equal(4, rcr.allProjectRefs.Count); // "There should be four references now"

            ComReferenceInfo newTlbInfo = (ComReferenceInfo)rcr.allProjectRefs[3];

            Assert.Equal(axRefInfo.primaryOfAxImpRef, newTlbInfo);                                                                       // "axRefInfo should hold back reference to tlbRefInfo"
            Assert.True(ComReference.AreTypeLibAttrEqual(newTlbInfo.attr, axRefInfo.attr));                                              // "The added reference should have the same attributes as the Ax reference"
            Assert.Equal(newTlbInfo.typeLibName, axRefInfo.typeLibName);                                                                 // "The added reference should have the same type lib name as the Ax reference"
            Assert.Equal(newTlbInfo.strippedTypeLibPath, axRefInfo.strippedTypeLibPath);                                                 // "The added reference should have the same type lib path as the Ax reference"

            Assert.Equal(newTlbInfo.taskItem.ItemSpec, axRefInfo.taskItem.ItemSpec);                                                     // "The added reference should have the same task item spec as the Ax reference"
            Assert.Equal(newTlbInfo.taskItem.GetMetadata(ComReferenceItemMetadataNames.wrapperTool), ComReferenceTypes.primaryortlbimp); // "The added reference should have the tlbimp/primary wrapper tool"

            rcr.AddMissingTlbReferences();
            Assert.Equal(4, rcr.allProjectRefs.Count); // "There should still be four references"
        }
 public void TestStripTypeLibNumber()
 {
     Assert.Equal(@"C:\test\typelib1.dll", ComReference.StripTypeLibNumberFromPath(@"C:\test\typelib1.dll", new FileExists(FileExistsMock)));
     Assert.Equal(@"C:\test\typelib2\2.dll", ComReference.StripTypeLibNumberFromPath(@"C:\test\typelib2\2.dll", new FileExists(FileExistsMock)));
     Assert.Equal(@"C:\test\typelib3.\3dll", ComReference.StripTypeLibNumberFromPath(@"C:\test\typelib3.\3dll", new FileExists(FileExistsMock)));
     Assert.Equal(@"C:\test\typelib4.dll", ComReference.StripTypeLibNumberFromPath(@"C:\test\typelib4.dll\4", new FileExists(FileExistsMock)));
     Assert.Equal(@"C:\test\typelib5.dll", ComReference.StripTypeLibNumberFromPath(@"C:\test\typelib5.dll\555", new FileExists(FileExistsMock)));
     Assert.Equal(@"", ComReference.StripTypeLibNumberFromPath(@"C:\test\typelib6.dll", new FileExists(FileExistsMock)));
     Assert.Equal(@"", ComReference.StripTypeLibNumberFromPath(@"C:\test\typelib7.dll\7", new FileExists(FileExistsMock)));
 }
Exemple #3
0
        public void TestStripTypeLibNumber()
        {
            if (!NativeMethodsShared.IsWindows)
            {
                return; // "COM is only found on Windows"
            }

            Assert.Equal(@"C:\test\typelib1.dll", ComReference.StripTypeLibNumberFromPath(@"C:\test\typelib1.dll", new FileExists(FileExistsMock)));
            Assert.Equal(@"C:\test\typelib2\2.dll", ComReference.StripTypeLibNumberFromPath(@"C:\test\typelib2\2.dll", new FileExists(FileExistsMock)));
            Assert.Equal(@"C:\test\typelib3.\3dll", ComReference.StripTypeLibNumberFromPath(@"C:\test\typelib3.\3dll", new FileExists(FileExistsMock)));
            Assert.Equal(@"C:\test\typelib4.dll", ComReference.StripTypeLibNumberFromPath(@"C:\test\typelib4.dll\4", new FileExists(FileExistsMock)));
            Assert.Equal(@"C:\test\typelib5.dll", ComReference.StripTypeLibNumberFromPath(@"C:\test\typelib5.dll\555", new FileExists(FileExistsMock)));
            Assert.Equal(@"", ComReference.StripTypeLibNumberFromPath(@"C:\test\typelib6.dll", new FileExists(FileExistsMock)));
            Assert.Equal(@"", ComReference.StripTypeLibNumberFromPath(@"C:\test\typelib7.dll\7", new FileExists(FileExistsMock)));
        }
Exemple #4
0
        /// <summary>
        /// Helper method that will new up an AX and matching TLB reference, and verify that the AX reference
        /// sets its RCW appropriately.
        /// </summary>
        private void CheckAxReferenceRCWTlbExists(RcwStyle rcwStyle, bool includeVersionInInteropName)
        {
            Guid             axGuid = Guid.NewGuid();
            ComReferenceInfo tlbRefInfo;

            var rcr = new ResolveComReference();

            rcr.BuildEngine = new MockEngine();
            rcr.IncludeVersionInInteropName = includeVersionInInteropName;
            rcr.allProjectRefs = new List <ComReferenceInfo>();

            TaskItem         axTaskItem = CreateComReferenceTaskItem("ref", axGuid.ToString(), "1", "2", "1033", ComReferenceTypes.aximp);
            ComReferenceInfo axRefInfo  = CreateComReferenceInfo(axTaskItem, "RefLibName", "RefLibPath");

            rcr.allProjectRefs.Add(axRefInfo);

            switch (rcwStyle)
            {
            case RcwStyle.GenerateTlb: break;

            case RcwStyle.PreexistingTlb:
            {
                TaskItem tlbTaskItem = CreateComReferenceTaskItem("ref", axGuid.ToString(), "1", "2", "1033", ComReferenceTypes.tlbimp, "true");
                tlbRefInfo = CreateComReferenceInfo(tlbTaskItem, "RefLibName", "RefLibPath");
                rcr.allProjectRefs.Add(tlbRefInfo);
                break;
            }

            case RcwStyle.PreexistingPia:
            {
                TaskItem tlbTaskItem = CreateComReferenceTaskItem("ref", axGuid.ToString(), "1", "2", "1033", ComReferenceTypes.primary, "true");
                tlbRefInfo = CreateComReferenceInfo(tlbTaskItem, "RefLibName", "RefLibPath");
                rcr.allProjectRefs.Add(tlbRefInfo);
                break;
            }
            }

            rcr.AddMissingTlbReferences();

            Assert.Equal(2, rcr.allProjectRefs.Count); // "Should be two references"

            tlbRefInfo = rcr.allProjectRefs[1];
            var embedInteropTypes = tlbRefInfo.taskItem.GetMetadata(ItemMetadataNames.embedInteropTypes);

            Assert.Equal("false", embedInteropTypes);                                       // "The tlb wrapper for the activex control should have EmbedInteropTypes=false not " + embedInteropTypes);
            Assert.True(ComReference.AreTypeLibAttrEqual(tlbRefInfo.attr, axRefInfo.attr)); // "reference information should be the same"
            Assert.Equal(TlbReference.GetWrapperFileName
                         (
                             axRefInfo.taskItem.GetMetadata(ComReferenceItemMetadataNames.tlbReferenceName),
                             includeVersionInInteropName,
                             axRefInfo.attr.wMajorVerNum,
                             axRefInfo.attr.wMinorVerNum
                         ),
                         TlbReference.GetWrapperFileName
                         (
                             tlbRefInfo.typeLibName,
                             includeVersionInInteropName,
                             tlbRefInfo.attr.wMajorVerNum,
                             tlbRefInfo.attr.wMinorVerNum
                         )); //                     "Expected Ax reference's RCW name to match the new TLB"
        }
        private static void DigestBuildItems(Project project, ProjectDigest projectDigest, string projectBasePath, ICollection <ProjectReference> projectReferences, ICollection <Reference> references, ICollection <Compile> compiles, ICollection <None> nones, ICollection <WebReferenceUrl> webReferenceUrls, ICollection <Content> contents, ICollection <Folder> folders, ICollection <WebReferences> webReferencesList, ICollection <EmbeddedResource> embeddedResources, ICollection <BootstrapperPackage> bootstrapperPackages, ICollection <string> globalNamespaceImports, IList <ComReference> comReferenceList)
        {
            string targetFramework = projectDigest.TargetFramework != null?projectDigest.TargetFramework.Substring(0, 3) : "2.0";

            RspUtility rsp = new RspUtility();

            foreach (BuildItemGroup buildItemGroup in project.ItemGroups)
            {
                foreach (BuildItem buildItem in buildItemGroup)
                {
                    if (!buildItem.IsImported)
                    {
                        switch (buildItem.Name)
                        {
                        case "ProjectReference":
                            ProjectReference prjRef = new ProjectReference(projectBasePath);
                            prjRef.ProjectPath = buildItem.Include;
                            prjRef.Name        = GetProjectAssemblyName(Path.GetFullPath(prjRef.ProjectFullPath));
                            prjRef.RoleType    = buildItem.GetMetadata("RoleType");
                            projectReferences.Add(prjRef);
                            break;

                        case "Reference":
                            Reference reference = new Reference(projectBasePath);
                            //set processorArchitecture property to platform, it will be used by GacUtility in
                            // order to resolve artifact to right processor architecture
                            if (!string.IsNullOrEmpty(projectDigest.Platform))
                            {
                                reference.ProcessorArchitecture = projectDigest.Platform;
                            }
                            string hintPath = buildItem.GetMetadata("HintPath");
                            if (!string.IsNullOrEmpty(hintPath))
                            {
                                string fullHint = Path.Combine(projectBasePath, hintPath);
                                if (File.Exists(fullHint))
                                {
                                    reference.HintPath = Path.GetFullPath(fullHint);
                                }
                                else
                                {
                                    reference.HintPath = fullHint;
                                }
                                SetReferenceFromFile(new FileInfo(fullHint), reference);
                            }
                            if (string.IsNullOrEmpty(reference.HintPath) || !(new FileInfo(reference.HintPath).Exists))
                            {
                                if (buildItem.Include.Contains(","))
                                {
                                    // complete name
                                    reference.SetAssemblyInfoValues(buildItem.Include);
                                }
                                else if (!rsp.IsRspIncluded(buildItem.Include, projectDigest.Language))
                                {
                                    // simple name needs to be resolved
                                    List <string> refs = GacUtility.GetInstance().GetAssemblyInfo(buildItem.Include, null, null);
                                    if (refs.Count == 0)
                                    {
                                        Console.WriteLine("Unable to find reference '" + buildItem.Include + "' in " + string.Join("; ", refs.ToArray()));
                                    }
                                    else if (refs.Count > 1)
                                    {
                                        string best          = null;
                                        string bestFramework = "0.0";
                                        foreach (string s in refs)
                                        {
                                            try
                                            {
                                                Assembly a         = Assembly.ReflectionOnlyLoad(s);
                                                string   framework = a.ImageRuntimeVersion.Substring(1, 3);
                                                if (framework.CompareTo(targetFramework) <= 0 && framework.CompareTo(bestFramework) > 0)
                                                {
                                                    best          = s;
                                                    bestFramework = framework;
                                                }
                                            }
                                            catch (Exception e)
                                            {
                                                // skip this assembly
                                                Console.WriteLine("An error occurred loading assembly '" + s + "' - check that your PATH to gacutil matches your runtime environment: " + e.Message);
                                            }
                                        }
                                        reference.SetAssemblyInfoValues(best);
                                    }
                                    else
                                    {
                                        reference.SetAssemblyInfoValues(refs[0]);
                                    }
                                }
                            }
                            if ("NUnit.Framework".Equals(reference.Name, StringComparison.OrdinalIgnoreCase))
                            {
                                reference.Name         = "NUnit.Framework";
                                projectDigest.UnitTest = true;
                            }
                            if (!string.IsNullOrEmpty(reference.Name))
                            {
                                references.Add(reference);
                            }
                            break;

                        case "Compile":
                            Compile compile = new Compile(projectBasePath);
                            compile.IncludePath           = buildItem.Include;
                            compile.AutoGen               = buildItem.GetMetadata("AutoGen");
                            compile.DesignTimeSharedInput = buildItem.GetMetadata("DesignTimeSharedInput");
                            compile.DependentUpon         = buildItem.GetMetadata("DependentUpon");
                            compile.DesignTime            = buildItem.GetMetadata("DesignTime");
                            compile.SubType               = buildItem.GetMetadata("SubType");
                            compiles.Add(compile);
                            break;

                        case "None":
                            None none = new None(projectBasePath);
                            none.IncludePath = buildItem.Include;

                            none.Link = buildItem.GetMetadata("Link");

                            none.Generator     = buildItem.GetMetadata("Generator");
                            none.LastGenOutput = buildItem.GetMetadata("LastGenOutput");
                            none.DependentUpon = buildItem.GetMetadata("DependentUpon");

                            nones.Add(none);

                            //add included web reference when reimporting
                            if (buildItem.Include.Contains(".wsdl"))
                            {
                                string path = Path.GetDirectoryName(buildItem.Include) + "\\";

                                WebReferenceUrl webUrl = new WebReferenceUrl();
                                webUrl.UrlBehavior = "Dynamic";
                                webUrl.RelPath     = path;

                                if (!webRefExists(webUrl, webReferenceUrls))
                                {
                                    webReferenceUrls.Add(webUrl);
                                }
                            }
                            break;

                        case "WebReferenceUrl":
                            WebReferenceUrl web = new WebReferenceUrl();
                            web.UrlBehavior                 = buildItem.GetMetadata("UrlBehavior");
                            web.RelPath                     = buildItem.GetMetadata("RelPath");
                            web.UpdateFromURL               = buildItem.GetMetadata("UpdateFromURL");
                            web.ServiceLocationURL          = buildItem.GetMetadata("ServiceLocationURL");
                            web.CachedDynamicPropName       = buildItem.GetMetadata("CachedDynamicPropName");
                            web.CachedAppSettingsObjectName = buildItem.GetMetadata("CachedAppSettingsObjectName");
                            web.CachedSettingsPropName      = buildItem.GetMetadata("CachedSettingsPropName");

                            if (!webRefExists(web, webReferenceUrls))
                            {
                                webReferenceUrls.Add(web);
                            }
                            break;

                        case "COMReference":
                            ComReference comRef = new ComReference();
                            comRef.Include      = buildItem.Include;
                            comRef.Guid         = buildItem.GetMetadata("Guid");
                            comRef.VersionMajor = buildItem.GetMetadata("VersionMajor");
                            comRef.VersionMinor = buildItem.GetMetadata("VersionMinor");
                            comRef.Lcid         = buildItem.GetMetadata("Lcid");
                            comRef.Isolated     = buildItem.GetMetadata("Isolated");
                            comRef.WrapperTool  = buildItem.GetMetadata("WrapperTool");
                            comReferenceList.Add(comRef);
                            break;

                        case "Content":
                            Content content = new Content(projectBasePath);
                            content.IncludePath = buildItem.Include;
                            contents.Add(content);

                            //add web reference in <includes> tag of compile-plugin
                            if (content.IncludePath.Contains("Web References"))
                            {
                                Compile compileWebRef = new Compile(projectBasePath);
                                compileWebRef.IncludePath = buildItem.Include;
                                compiles.Add(compileWebRef);
                            }
                            break;

                        case "Folder":
                            Folder folder = new Folder(projectBasePath);
                            folder.IncludePath = buildItem.Include;
                            folders.Add(folder);
                            break;

                        case "WebReferences":
                            WebReferences webReferences = new WebReferences(projectBasePath);
                            webReferences.IncludePath = buildItem.Include;
                            webReferencesList.Add(webReferences);
                            break;

                        case "EmbeddedResource":
                            EmbeddedResource embeddedResource = new EmbeddedResource(projectBasePath);
                            embeddedResource.IncludePath = buildItem.Include;

                            embeddedResource.DependentUpon = buildItem.GetMetadata("DependentUpon");
                            embeddedResource.SubType       = buildItem.GetMetadata("SubType");
                            embeddedResource.Generator     = buildItem.GetMetadata("Generator");
                            embeddedResource.LastGenOutput = buildItem.GetMetadata("LastGenOutput");

                            embeddedResources.Add(embeddedResource);
                            break;

                        case "BootstrapperPackage":
                            BootstrapperPackage bootstrapperPackage = new BootstrapperPackage(projectBasePath);
                            bootstrapperPackage.IncludePath = buildItem.Include;
                            bootstrapperPackage.Visible     = buildItem.GetMetadata("Visible");
                            bootstrapperPackage.ProductName = buildItem.GetMetadata("ProductName");
                            bootstrapperPackage.Install     = buildItem.GetMetadata("Install");


                            bootstrapperPackages.Add(bootstrapperPackage);
                            break;

                        case "Import":
                            globalNamespaceImports.Add(buildItem.Include);
                            break;

                        case "BaseApplicationManifest":
                            projectDigest.BaseApplicationManifest = buildItem.Include;
                            break;

                        default:
                            Console.WriteLine("Unhandled ItemGroup: " + buildItem.Name);
                            break;
                        }
                    }
                }
            }
        }