public SharedTestState() { if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { // COM activation is only supported on Windows return; } ComLibraryFixture = new TestProjectFixture("ComLibrary", RepoDirectories) .EnsureRestored(RepoDirectories.CorehostPackages) .BuildProject(); // Create a .clsidmap from the assembly string clsidMapPath = Path.Combine(BaseDirectory, $"{ ComLibraryFixture.TestProject.AssemblyName }.clsidmap"); 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(); ClsidMap.Create(reader, clsidMapPath); } } // Use the locally built comhost to create a comhost with the embedded .clsidmap ComHostPath = Path.Combine( ComLibraryFixture.TestProject.BuiltApp.Location, $"{ ComLibraryFixture.TestProject.AssemblyName }.comhost.dll"); ComHost.Create( Path.Combine(RepoDirectories.CorehostPackages, "comhost.dll"), ComHostPath, clsidMapPath); }
public SharedTestState() { if (!OperatingSystem.IsWindows()) { // COM activation is only supported on Windows return; } ComLibraryFixture = new TestProjectFixture("ComLibrary", RepoDirectories) .EnsureRestored() .BuildProject(); // Create a .clsidmap from the assembly ClsidMapPath = Path.Combine(BaseDirectory, $"{ ComLibraryFixture.TestProject.AssemblyName }.clsidmap"); 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(); ClsidMap.Create(reader, ClsidMapPath); } } // Use the locally built comhost to create a comhost with the embedded .clsidmap ComHostPath = Path.Combine( ComLibraryFixture.TestProject.BuiltApp.Location, $"{ ComLibraryFixture.TestProject.AssemblyName }.comhost.dll"); // Include the test type libraries in the ComHost tests. TypeLibraries = new Dictionary <int, string> { { 1, Path.Combine(RepoDirectories.Artifacts, "corehost_test", "Server.tlb") }, { 2, Path.Combine(RepoDirectories.Artifacts, "corehost_test", "Nested.tlb") } }; ComHost.Create( Path.Combine(RepoDirectories.HostArtifacts, "comhost.dll"), ComHostPath, ClsidMapPath, TypeLibraries); }