Beispiel #1
0
        public void RegFreeComManifestCorrectlyIncludesComHostFile()
        {
            using TestDirectory directory = TestDirectory.Create();
            JObject clsidMap = new JObject
            {
            };

            string clsidmapPath = Path.Combine(directory.Path, "test.clsidmap");
            string json         = JsonConvert.SerializeObject(clsidMap);

            string comHostName = "comhost.dll";

            File.WriteAllText(clsidmapPath, json);

            string regFreeComManifestPath = Path.Combine(directory.Path, "test.manifest");

            RegFreeComManifest.CreateManifestFromClsidmap("assemblyName", comHostName, "1.0.0.0", clsidmapPath, regFreeComManifestPath);

            using FileStream manifestStream = File.OpenRead(regFreeComManifestPath);

            XElement manifest = XElement.Load(manifestStream);

            XElement fileElement = manifest.Element(regFreeComManifestNamespace + "file");

            Assert.NotNull(fileElement);
            Assert.Equal(comHostName, fileElement.Attribute("name").Value);
        }
            public SharedTestState()
            {
                if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    // COM activation is only supported on Windows
                    return;
                }

                using (var assemblyStream = new FileStream(ComLibraryFixture.TestProject.AppDll, FileMode.Open, FileAccess.Read, FileShare.Delete | FileShare.Read))
                    using (var peReader = new System.Reflection.PortableExecutable.PEReader(assemblyStream))
                    {
                        if (peReader.HasMetadata)
                        {
                            string regFreeManifestPath = Path.Combine(BaseDirectory, $"{ ComLibraryFixture.TestProject.AssemblyName }.X.manifest");

                            MetadataReader reader = peReader.GetMetadataReader();
                            RegFreeComManifest.CreateManifestFromClsidmap(
                                ComLibraryFixture.TestProject.AssemblyName,
                                Path.GetFileName(ComHostPath),
                                reader.GetAssemblyDefinition().Version.ToString(),
                                ClsidMapPath,
                                regFreeManifestPath,
                                TypeLibraries
                                );
                        }
                    }

                string testDirectoryPath = Path.GetDirectoryName(NativeHostPath);
                string comsxsName        = RuntimeInformationExtensions.GetExeFileNameForCurrentPlatform("comsxs");

                ComSxsPath = Path.Combine(testDirectoryPath, comsxsName);
                File.Copy(
                    Path.Combine(RepoDirectories.Artifacts, "corehost_test", comsxsName),
                    ComSxsPath);
                File.Copy(
                    ComHostPath,
                    Path.Combine(testDirectoryPath, Path.GetFileName(ComHostPath)));
                File.Copy(
                    ComLibraryFixture.TestProject.AppDll,
                    Path.Combine(testDirectoryPath, Path.GetFileName(ComLibraryFixture.TestProject.AppDll)));
                File.Copy(
                    ComLibraryFixture.TestProject.DepsJson,
                    Path.Combine(testDirectoryPath, Path.GetFileName(ComLibraryFixture.TestProject.DepsJson)));
                File.Copy(
                    ComLibraryFixture.TestProject.RuntimeConfigJson,
                    Path.Combine(testDirectoryPath, Path.GetFileName(ComLibraryFixture.TestProject.RuntimeConfigJson)));
            }
Beispiel #3
0
        public void EntryInClsidMapAddedToRegFreeComManifestIncludesProgId()
        {
            using TestDirectory directory = TestDirectory.Create();
            string  guid            = "{190f1974-fa98-4922-8ed4-cf748630abbe}";
            string  assemblyName    = "ComLibrary";
            string  typeName        = "ComLibrary.Server";
            string  progId          = "CustomProgId";
            string  assemblyVersion = "1.0.0.0";
            JObject clsidMap        = new JObject
            {
                {
                    guid,
                    new JObject()
                    {
                        { "assembly", assemblyName }, { "type", typeName }, { "progid", progId }
                    }
                }
            };

            string clsidmapPath = Path.Combine(directory.Path, "test.clsidmap");
            string json         = JsonConvert.SerializeObject(clsidMap);
            string comHostName  = "comhost.dll";

            File.WriteAllText(clsidmapPath, json);

            string regFreeComManifestPath = Path.Combine(directory.Path, "test.manifest");

            RegFreeComManifest.CreateManifestFromClsidmap(assemblyName, comHostName, assemblyVersion, clsidmapPath, regFreeComManifestPath);

            using FileStream manifestStream = File.OpenRead(regFreeComManifestPath);

            XElement manifest = XElement.Load(manifestStream);

            XElement fileElement = manifest.Element(regFreeComManifestNamespace + "file");

            Assert.Single(fileElement.Elements(regFreeComManifestNamespace + "comClass").Where(cls => cls.Attribute("clsid").Value == guid && cls.Attribute("progid").Value == progId));
        }
            public SharedTestState()
            {
                if (!OperatingSystem.IsWindows())
                {
                    // COM activation is only supported on Windows
                    return;
                }

                string comsxsDirectory     = BaseDirectory;
                string regFreeManifestName = $"{ ComLibraryFixture.TestProject.AssemblyName }.X.manifest";
                string regFreeManifestPath = Path.Combine(comsxsDirectory, regFreeManifestName);

                using (var assemblyStream = new FileStream(ComLibraryFixture.TestProject.AppDll, FileMode.Open, FileAccess.Read, FileShare.Delete | FileShare.Read))
                    using (var peReader = new System.Reflection.PortableExecutable.PEReader(assemblyStream))
                    {
                        if (peReader.HasMetadata)
                        {
                            MetadataReader reader = peReader.GetMetadataReader();
                            RegFreeComManifest.CreateManifestFromClsidmap(
                                ComLibraryFixture.TestProject.AssemblyName,
                                Path.GetFileName(ComHostPath),
                                reader.GetAssemblyDefinition().Version.ToString(),
                                ClsidMapPath,
                                regFreeManifestPath,
                                TypeLibraries
                                );
                        }
                    }

                string comsxsName = RuntimeInformationExtensions.GetExeFileNameForCurrentPlatform("comsxs");

                ComSxsPath = Path.Combine(comsxsDirectory, comsxsName);
                File.Copy(
                    Path.Combine(RepoDirectories.Artifacts, "corehost_test", comsxsName),
                    ComSxsPath);

                ManagedHostFixture_FrameworkDependent = new TestProjectFixture("ManagedHost", RepoDirectories)
                                                        .EnsureRestored()
                                                        .PublishProject(selfContained: false, extraArgs: "/p:RegFreeCom=true");
                File.Copy(regFreeManifestPath, Path.Combine(ManagedHostFixture_FrameworkDependent.TestProject.BuiltApp.Location, regFreeManifestName));

                ManagedHostFixture_SelfContained = new TestProjectFixture("ManagedHost", RepoDirectories)
                                                   .EnsureRestored()
                                                   .PublishProject(selfContained: true, extraArgs: "/p:RegFreeCom=true");
                File.Copy(regFreeManifestPath, Path.Combine(ManagedHostFixture_SelfContained.TestProject.BuiltApp.Location, regFreeManifestName));

                // Copy the ComLibrary output and comhost to the ComSxS and ManagedHost directories
                string[] toCopy =
                {
                    ComLibraryFixture.TestProject.AppDll,
                    ComLibraryFixture.TestProject.DepsJson,
                    ComLibraryFixture.TestProject.RuntimeConfigJson,
                    ComHostPath,
                };
                foreach (string filePath in toCopy)
                {
                    File.Copy(filePath, Path.Combine(comsxsDirectory, Path.GetFileName(filePath)));
                    File.Copy(filePath, Path.Combine(ManagedHostFixture_FrameworkDependent.TestProject.BuiltApp.Location, Path.GetFileName(filePath)));
                    File.Copy(filePath, Path.Combine(ManagedHostFixture_SelfContained.TestProject.BuiltApp.Location, Path.GetFileName(filePath)));
                }
            }