public void Running_Publish_Output_Standalone_EXE_By_Renaming_dotnet_exe_Fails()
        {
            var fixture = sharedTestState.StandaloneAppFixture_Published
                          .Copy();

            var appExe = fixture.TestProject.AppExe;

            string hostExeName = RuntimeInformationExtensions.GetExeFileNameForCurrentPlatform("dotnet");
            string builtHost   = Path.Combine(sharedTestState.RepoDirectories.HostArtifacts, hostExeName);

            File.Copy(builtHost, appExe, true);

            int exitCode = Command.Create(appExe)
                           .CaptureStdErr()
                           .CaptureStdOut()
                           .Execute(fExpectedToFail: true)
                           .ExitCode;

            if (OperatingSystem.IsWindows())
            {
                exitCode.Should().Be(-2147450748);
            }
            else
            {
                // Some Unix flavors filter exit code to ubyte.
                (exitCode & 0xFF).Should().Be(0x84);
            }
        }
Example #2
0
        public SharedTestStateBase()
        {
            BaseDirectory    = SharedFramework.CalculateUniqueTestDirectory(Path.Combine(TestArtifact.TestArtifactsPath, "nativeHosting"));
            _baseDirArtifact = new TestArtifact(BaseDirectory);
            Directory.CreateDirectory(BaseDirectory);

            string nativeHostName = RuntimeInformationExtensions.GetExeFileNameForCurrentPlatform("nativehost");

            NativeHostPath = Path.Combine(BaseDirectory, nativeHostName);

            // Copy over native host
            RepoDirectories = new RepoDirectoriesProvider();
            File.Copy(Path.Combine(RepoDirectories.Artifacts, "corehost_test", nativeHostName), NativeHostPath);

            // Copy nethost next to native host
            // This is done even for tests not directly using nethost because nativehost consumes nethost in the more
            // user-friendly way of linking against nethost (instead of dlopen/LoadLibrary and dlsym/GetProcAddress).
            // On Windows, we can delay load through a linker option, but on other platforms load is required on start.
            string nethostName = RuntimeInformationExtensions.GetSharedLibraryFileNameForCurrentPlatform("nethost");

            NethostPath = Path.Combine(Path.GetDirectoryName(NativeHostPath), nethostName);
            File.Copy(
                Path.Combine(RepoDirectories.HostArtifacts, nethostName),
                NethostPath);
        }
Example #3
0
            public SharedTestState()
            {
                BaseDirectory = SharedFramework.CalculateUniqueTestDirectory(Path.Combine(TestArtifact.TestArtifactsPath, "nativeHosting"));
                Directory.CreateDirectory(BaseDirectory);

                string nativeHostName = RuntimeInformationExtensions.GetExeFileNameForCurrentPlatform("nativehost");

                NativeHostPath = Path.Combine(BaseDirectory, nativeHostName);

                // Copy over native host and nethost
                RepoDirectories = new RepoDirectoriesProvider();
                string nethostName = RuntimeInformationExtensions.GetSharedLibraryFileNameForCurrentPlatform("nethost");

                File.Copy(Path.Combine(RepoDirectories.CorehostPackages, nethostName), Path.Combine(BaseDirectory, nethostName));
                File.Copy(Path.Combine(RepoDirectories.Artifacts, "corehost_test", nativeHostName), NativeHostPath);

                InvalidInstallRoot = Path.Combine(BaseDirectory, "invalid");
                Directory.CreateDirectory(InvalidInstallRoot);

                ValidInstallRoot = Path.Combine(BaseDirectory, "valid");
                HostFxrPath      = CreateHostFxr(Path.Combine(ValidInstallRoot, "dotnet"));

                string appDir = Path.Combine(BaseDirectory, "app");

                Directory.CreateDirectory(appDir);
                string assemblyPath = Path.Combine(appDir, "App.dll");

                File.WriteAllText(assemblyPath, string.Empty);
                TestAssemblyPath = assemblyPath;
            }
Example #4
0
        // This helper is used in lieu of SDK support for publishing apps using the singlefilehost.
        // It replaces the apphost with singlefilehost, and along with appropriate app.dll updates in the host.
        // For now, we leave behind the hostpolicy and hostfxr DLLs in the publish directory, because
        // removing them requires deps.json update.
        void ReplaceApphostWithStaticHost(TestProjectFixture fixture)
        {
            var staticHost = Path.Combine(fixture.RepoDirProvider.HostArtifacts,
                                          RuntimeInformationExtensions.GetExeFileNameForCurrentPlatform("singlefilehost"));

            HostWriter.CreateAppHost(staticHost,
                                     BundleHelper.GetHostPath(fixture),
                                     BundleHelper.GetAppPath(fixture));
        }
Example #5
0
        public void Framework_Dependent_AppHost_Succeeds()
        {
            var fixture = sharedTestState.PortableAppFixture_Published
                          .Copy();

            // Since SDK doesn't support building framework dependent apphost yet, emulate that behavior
            // by creating the executable from apphost.exe
            var appExe     = fixture.TestProject.AppExe;
            var appDllName = Path.GetFileName(fixture.TestProject.AppDll);

            string hostExeName   = RuntimeInformationExtensions.GetExeFileNameForCurrentPlatform("apphost");
            string builtAppHost  = Path.Combine(sharedTestState.RepoDirectories.HostArtifacts, hostExeName);
            string appDir        = Path.GetDirectoryName(appExe);
            string appDirHostExe = Path.Combine(appDir, hostExeName);

            // Make a copy of apphost first, replace hash and overwrite app.exe, rather than
            // overwrite app.exe and edit in place, because the file is opened as "write" for
            // the replacement -- the test fails with ETXTBSY (exit code: 26) in Linux when
            // executing a file opened in "write" mode.
            File.Copy(builtAppHost, appDirHostExe, true);
            using (var sha256 = SHA256.Create())
            {
                // Replace the hash with the managed DLL name.
                var hash    = sha256.ComputeHash(Encoding.UTF8.GetBytes("foobar"));
                var hashStr = BitConverter.ToString(hash).Replace("-", "").ToLower();
                BinaryUtils.SearchAndReplace(appDirHostExe, Encoding.UTF8.GetBytes(hashStr), Encoding.UTF8.GetBytes(appDllName));
            }
            File.Copy(appDirHostExe, appExe, true);

            // Get the framework location that was built
            string builtDotnet = fixture.BuiltDotnet.BinPath;

            // Verify running with the default working directory
            Command.Create(appExe)
            .CaptureStdErr()
            .CaptureStdOut()
            .EnvironmentVariable("DOTNET_ROOT", builtDotnet)
            .EnvironmentVariable("DOTNET_ROOT(x86)", builtDotnet)
            .Execute()
            .Should().Pass()
            .And.HaveStdOutContaining("Hello World")
            .And.HaveStdOutContaining($"Framework Version:{sharedTestState.RepoDirectories.MicrosoftNETCoreAppVersion}");


            // Verify running from within the working directory
            Command.Create(appExe)
            .WorkingDirectory(fixture.TestProject.OutputDirectory)
            .EnvironmentVariable("DOTNET_ROOT", builtDotnet)
            .EnvironmentVariable("DOTNET_ROOT(x86)", builtDotnet)
            .CaptureStdErr()
            .CaptureStdOut()
            .Execute()
            .Should().Pass()
            .And.HaveStdOutContaining("Hello World")
            .And.HaveStdOutContaining($"Framework Version:{sharedTestState.RepoDirectories.MicrosoftNETCoreAppVersion}");
        }
Example #6
0
        // This helper is used in lieu of SDK support for publishing apps using the singlefilehost.
        // It replaces the apphost with singlefilehost, and along with appropriate app.dll updates in the host.
        // For now, we leave behind the hostpolicy and hostfxr DLLs in the publish directory, because
        // removing them requires deps.json update.
        public static string UseSingleFileSelfContainedHost(TestProjectFixture testFixture)
        {
            var singleFileHost = Path.Combine(
                testFixture.RepoDirProvider.HostArtifacts,
                RuntimeInformationExtensions.GetExeFileNameForCurrentPlatform("singlefilehost"));
            var publishedHostPath = BundleHelper.GetHostPath(testFixture);

            HostWriter.CreateAppHost(singleFileHost,
                                     publishedHostPath,
                                     BundleHelper.GetAppName(testFixture));
            return(publishedHostPath);
        }
Example #7
0
        public static string UseFrameworkDependentHost(TestProjectFixture testFixture)
        {
            var appHost = Path.Combine(
                testFixture.RepoDirProvider.HostArtifacts,
                RuntimeInformationExtensions.GetExeFileNameForCurrentPlatform("apphost"));
            var publishedHostPath = BundleHelper.GetHostPath(testFixture);

            HostWriter.CreateAppHost(appHost,
                                     publishedHostPath,
                                     BundleHelper.GetAppName(testFixture));
            return(publishedHostPath);
        }
Example #8
0
        public SharedTestStateBase()
        {
            BaseDirectory = SharedFramework.CalculateUniqueTestDirectory(Path.Combine(TestArtifact.TestArtifactsPath, "nativeHosting"));
            Directory.CreateDirectory(BaseDirectory);

            string nativeHostName = RuntimeInformationExtensions.GetExeFileNameForCurrentPlatform("nativehost");

            NativeHostPath = Path.Combine(BaseDirectory, nativeHostName);

            // Copy over native host
            RepoDirectories = new RepoDirectoriesProvider();
            File.Copy(Path.Combine(RepoDirectories.Artifacts, "corehost_test", nativeHostName), NativeHostPath);
        }
Example #9
0
            public SharedTestState()
            {
                RepoDirectories = new RepoDirectoriesProvider();
                BuiltAppHost    = Path.Combine(RepoDirectories.HostArtifacts, RuntimeInformationExtensions.GetExeFileNameForCurrentPlatform("apphost"));

                PortableAppFixture_Built = new TestProjectFixture("PortableApp", RepoDirectories)
                                           .EnsureRestored(RepoDirectories.CorehostPackages)
                                           .BuildProject();

                PortableAppFixture_Published = new TestProjectFixture("PortableApp", RepoDirectories)
                                               .EnsureRestored(RepoDirectories.CorehostPackages)
                                               .PublishProject();
            }
            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)));
            }
        public void Running_Publish_Output_Standalone_EXE_By_Renaming_apphost_exe_Succeeds()
        {
            var fixture = sharedTestState.StandaloneAppFixture_Published
                          .Copy();

            var appExe        = fixture.TestProject.AppExe;
            var renamedAppExe = fixture.TestProject.AppExe + RuntimeInformationExtensions.GetExeFileNameForCurrentPlatform("renamed");

            File.Copy(appExe, renamedAppExe, true);

            Command.Create(renamedAppExe)
            .CaptureStdErr()
            .CaptureStdOut()
            .Execute()
            .Should().Pass()
            .And.HaveStdOutContaining("Hello World")
            .And.HaveStdOutContaining(sharedTestState.RepoDirectories.MicrosoftNETCoreAppVersion);
        }
Example #12
0
            public SharedTestState()
            {
                RepoDirectories = new RepoDirectoriesProvider();
                BuiltAppHost    = Path.Combine(RepoDirectories.HostArtifacts, RuntimeInformationExtensions.GetExeFileNameForCurrentPlatform("apphost"));
                BuiltDotNet     = new DotNetCli(RepoDirectories.BuiltDotnet);

                PortableAppFixture_Built = new TestProjectFixture("PortableApp", RepoDirectories)
                                           .EnsureRestored()
                                           .BuildProject();

                PortableAppFixture_Published = new TestProjectFixture("PortableApp", RepoDirectories)
                                               .EnsureRestored()
                                               .PublishProject();

                MockApp = new TestApp(SharedFramework.CalculateUniqueTestDirectory(Path.Combine(TestArtifact.TestArtifactsPath, "portableAppActivation")), "App");
                Directory.CreateDirectory(MockApp.Location);
                File.WriteAllText(MockApp.AppDll, string.Empty);
                File.Copy(BuiltAppHost, MockApp.AppExe);
                AppHostExtensions.BindAppHost(MockApp.AppExe);
            }
Example #13
0
        public DotNetBuilder(string basePath, string builtDotnet, string name)
        {
            _path = Path.Combine(basePath, name);
            Directory.CreateDirectory(_path);

            _repoDirectories = new RepoDirectoriesProvider(builtDotnet: _path);

            // Prepare the dotnet installation mock

            // ./dotnet.exe - used as a convenient way to load and invoke hostfxr. May change in the future to use test-specific executable
            var builtDotNetCli = new DotNetCli(builtDotnet);

            File.Copy(
                builtDotNetCli.DotnetExecutablePath,
                Path.Combine(_path, RuntimeInformationExtensions.GetExeFileNameForCurrentPlatform("dotnet")),
                true);

            // ./host/fxr/<version>/hostfxr.dll - this is the component being tested
            SharedFramework.CopyDirectory(
                builtDotNetCli.GreatestVersionHostFxrPath,
                Path.Combine(_path, "host", "fxr", Path.GetFileName(builtDotNetCli.GreatestVersionHostFxrPath)));
        }
            public TestApp CreateSelfContainedAppWithMockHostPolicy()
            {
                string testAppDir = Path.Combine(_baseDir, "SelfContainedApp");

                Directory.CreateDirectory(testAppDir);
                TestApp testApp = new TestApp(testAppDir);

                string hostFxrFileName        = RuntimeInformationExtensions.GetSharedLibraryFileNameForCurrentPlatform("hostfxr");
                string hostPolicyFileName     = RuntimeInformationExtensions.GetSharedLibraryFileNameForCurrentPlatform("hostpolicy");
                string mockHostPolicyFileName = RuntimeInformationExtensions.GetSharedLibraryFileNameForCurrentPlatform("mockhostpolicy");
                string appHostFileName        = RuntimeInformationExtensions.GetExeFileNameForCurrentPlatform("apphost");

                DotNetCli builtDotNetCli = new DotNetCli(_builtDotnet);

                // ./hostfxr - the product version
                File.Copy(builtDotNetCli.GreatestVersionHostFxrFilePath, Path.Combine(testAppDir, hostFxrFileName));

                // ./hostpolicy - the mock
                File.Copy(
                    Path.Combine(_repoDirectories.Artifacts, "corehost_test", mockHostPolicyFileName),
                    Path.Combine(testAppDir, hostPolicyFileName));

                // ./SelfContainedApp.dll
                File.WriteAllText(Path.Combine(testAppDir, "SelfContainedApp.dll"), string.Empty);

                // ./SelfContainedApp.runtimeconfig.json
                File.WriteAllText(Path.Combine(testAppDir, "SelfContainedApp.runtimeconfig.json"), "{}");

                // ./SelfContainedApp.exe
                string selfContainedAppExePath = Path.Combine(testAppDir, RuntimeInformationExtensions.GetExeFileNameForCurrentPlatform("SelfContainedApp"));

                File.Copy(
                    Path.Combine(_repoDirectories.HostArtifacts, appHostFileName),
                    selfContainedAppExePath);
                AppHostExtensions.BindAppHost(selfContainedAppExePath);

                return(testApp);
            }
Example #15
0
        public void Native_Test_Fx_Ver()
        {
            RepoDirectoriesProvider repoDirectoriesProvider = new RepoDirectoriesProvider();

            string testPath = Path.Combine(repoDirectoriesProvider.Artifacts, "corehost_test", RuntimeInformationExtensions.GetExeFileNameForCurrentPlatform("test_fx_ver"));

            Command testCommand = Command.Create(testPath);

            testCommand
            .Execute()
            .Should()
            .Pass();
        }
Example #16
0
        public void Framework_Dependent_AppHost_From_Global_Registry_Location_Succeeds()
        {
            if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                return;
            }

            var fixture = sharedTestState.PortableAppFixture_Published
                          .Copy();

            // Since SDK doesn't support building framework dependent apphost yet, emulate that behavior
            // by creating the executable from apphost.exe
            var appExe     = fixture.TestProject.AppExe;
            var appDllName = Path.GetFileName(fixture.TestProject.AppDll);

            string hostExeName   = RuntimeInformationExtensions.GetExeFileNameForCurrentPlatform("apphost");
            string builtAppHost  = Path.Combine(sharedTestState.RepoDirectories.HostArtifacts, hostExeName);
            string appDir        = Path.GetDirectoryName(appExe);
            string appDirHostExe = Path.Combine(appDir, hostExeName);

            // Make a copy of apphost first, replace hash and overwrite app.exe, rather than
            // overwrite app.exe and edit in place, because the file is opened as "write" for
            // the replacement -- the test fails with ETXTBSY (exit code: 26) in Linux when
            // executing a file opened in "write" mode.
            File.Copy(builtAppHost, appDirHostExe, true);
            using (var sha256 = SHA256.Create())
            {
                // Replace the hash with the managed DLL name.
                var hash    = sha256.ComputeHash(Encoding.UTF8.GetBytes("foobar"));
                var hashStr = BitConverter.ToString(hash).Replace("-", "").ToLower();
                AppHostExtensions.SearchAndReplace(appDirHostExe, Encoding.UTF8.GetBytes(hashStr), Encoding.UTF8.GetBytes(appDllName), true);
            }
            File.Copy(appDirHostExe, appExe, true);

            // Get the framework location that was built
            string builtDotnet = fixture.BuiltDotnet.BinPath;

            RegistryKey hkcu         = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry32);
            RegistryKey interfaceKey = hkcu.CreateSubKey(@"Software\Classes\Interface");
            string      testKeyName  = "_DOTNET_Test" + System.Diagnostics.Process.GetCurrentProcess().Id.ToString();
            RegistryKey testKey      = interfaceKey.CreateSubKey(testKeyName);

            try
            {
                string      architecture      = fixture.CurrentRid.Split('-')[1];
                RegistryKey dotnetLocationKey = testKey.CreateSubKey($@"Setup\InstalledVersions\{architecture}");
                dotnetLocationKey.SetValue("InstallLocation", builtDotnet);

                // Verify running with the default working directory
                Command.Create(appExe)
                .CaptureStdErr()
                .CaptureStdOut()
                .EnvironmentVariable("_DOTNET_TEST_SDK_REGISTRY_PATH", testKey.Name)
                .Execute()
                .Should().Pass()
                .And.HaveStdOutContaining("Hello World")
                .And.HaveStdOutContaining($"Framework Version:{sharedTestState.RepoDirectories.MicrosoftNETCoreAppVersion}");

                // Verify running from within the working directory
                Command.Create(appExe)
                .WorkingDirectory(fixture.TestProject.OutputDirectory)
                .EnvironmentVariable("_DOTNET_TEST_SDK_REGISTRY_PATH", testKey.Name)
                .CaptureStdErr()
                .CaptureStdOut()
                .Execute()
                .Should().Pass()
                .And.HaveStdOutContaining("Hello World")
                .And.HaveStdOutContaining($"Framework Version:{sharedTestState.RepoDirectories.MicrosoftNETCoreAppVersion}");
            }
            finally
            {
                interfaceKey.DeleteSubKeyTree(testKeyName);
            }
        }
Example #17
0
            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)));
                }
            }
Example #18
0
        public SharedFxLookup()
        {
            // From the artifacts dir, it's possible to find where the sharedFrameworkPublish folder is. We need
            // to locate it because we'll copy its contents into other folders
            string artifactsDir = Environment.GetEnvironmentVariable("TEST_ARTIFACTS");

            _builtDotnet = Path.Combine(artifactsDir, "sharedFrameworkPublish");

            // The dotnetSharedFxLookup dir will contain some folders and files that will be
            // necessary to perform the tests
            string baseDir = Path.Combine(artifactsDir, "dotnetSharedFxLookup");

            _baseDir = SharedFramework.CalculateUniqueTestDirectory(baseDir);

            // The three tested locations will be the cwd, the user folder and the exe dir. Both cwd and exe dir
            // are easily overwritten, so they will be placed inside the multilevel folder. The actual user location will
            // be used during tests
            _currentWorkingDir = Path.Combine(_baseDir, "cwd");
            _userDir           = Path.Combine(_baseDir, "user");
            _executableDir     = Path.Combine(_baseDir, "exe");
            _globalDir         = Path.Combine(_baseDir, "global");

            RepoDirectories = new RepoDirectoriesProvider(builtDotnet: _executableDir);

            // SharedFxBaseDirs contain all available version folders
            _cwdSharedFxBaseDir    = Path.Combine(_currentWorkingDir, "shared", "Microsoft.NETCore.App");
            _userSharedFxBaseDir   = Path.Combine(_userDir, ".dotnet", RepoDirectories.BuildArchitecture, "shared", "Microsoft.NETCore.App");
            _exeSharedFxBaseDir    = Path.Combine(_executableDir, "shared", "Microsoft.NETCore.App");
            _globalSharedFxBaseDir = Path.Combine(_globalDir, "shared", "Microsoft.NETCore.App");

            _cwdSharedUberFxBaseDir    = Path.Combine(_currentWorkingDir, "shared", "Microsoft.UberFramework");
            _userSharedUberFxBaseDir   = Path.Combine(_userDir, ".dotnet", RepoDirectories.BuildArchitecture, "shared", "Microsoft.UberFramework");
            _exeSharedUberFxBaseDir    = Path.Combine(_executableDir, "shared", "Microsoft.UberFramework");
            _globalSharedUberFxBaseDir = Path.Combine(_globalDir, "shared", "Microsoft.UberFramework");

            // Create directories. It's necessary to copy the entire publish folder to the exe dir because
            // we'll need to build from it. The CopyDirectory method automatically creates the dest dir
            Directory.CreateDirectory(_cwdSharedFxBaseDir);
            Directory.CreateDirectory(_userSharedFxBaseDir);
            Directory.CreateDirectory(_globalSharedFxBaseDir);
            Directory.CreateDirectory(_cwdSharedUberFxBaseDir);
            Directory.CreateDirectory(_userSharedUberFxBaseDir);
            Directory.CreateDirectory(_globalSharedUberFxBaseDir);
            SharedFramework.CopyDirectory(_builtDotnet, _executableDir);

            //Copy dotnet to global directory
            File.Copy(
                Path.Combine(_builtDotnet, RuntimeInformationExtensions.GetExeFileNameForCurrentPlatform("dotnet")),
                Path.Combine(_globalDir, RuntimeInformationExtensions.GetExeFileNameForCurrentPlatform("dotnet")),
                true);

            // Restore and build SharedFxLookupPortableApp from exe dir
            SharedFxLookupPortableAppFixture = new TestProjectFixture("SharedFxLookupPortableApp", RepoDirectories)
                                               .EnsureRestored(RepoDirectories.CorehostPackages)
                                               .BuildProject();
            var fixture = SharedFxLookupPortableAppFixture;

            // The actual framework version can be obtained from the built fixture. We'll use it to
            // locate the builtSharedFxDir from which we can get the files contained in the version folder
            string greatestVersionSharedFxPath = fixture.BuiltDotnet.GreatestVersionSharedFxPath;

            _sharedFxVersion      = (new DirectoryInfo(greatestVersionSharedFxPath)).Name;
            _builtSharedFxDir     = Path.Combine(_builtDotnet, "shared", "Microsoft.NETCore.App", _sharedFxVersion);
            _builtSharedUberFxDir = Path.Combine(_builtDotnet, "shared", "Microsoft.UberFramework", _sharedFxVersion);
            SharedFramework.CreateUberFrameworkArtifacts(_builtSharedFxDir, _builtSharedUberFxDir, SystemCollectionsImmutableAssemblyVersion, SystemCollectionsImmutableFileVersion);

            // Trace messages used to identify from which folder the framework was picked
            _hostPolicyDllName  = Path.GetFileName(fixture.TestProject.HostPolicyDll);
            _exeSelectedMessage = $"The expected {_hostPolicyDllName} directory is [{_exeSharedFxBaseDir}";

            _exeFoundUberFxMessage = $"Chose FX version [{_exeSharedUberFxBaseDir}";
        }