public RegisteredInstallLocationOverride(string productBinaryPath) { _testOnlyProductBehavior = TestOnlyProductBehavior.Enable(productBinaryPath); if (OperatingSystem.IsWindows()) { // To test registered installs, we need a registry key which is: // - writable without admin access - so that the tests don't require admin to run // - redirected in WOW64 - so that there are both 32-bit and 64-bit versions of the key // This is because the product stores the info in the 32-bit hive only and even 64-bit // product must look into the 32-bit hive. // Without the redirection we would not be able to test that the product always looks // into 32-bit only. // Per this page https://docs.microsoft.com/en-us/windows/desktop/WinProg64/shared-registry-keys // a user writable redirected key is for example HKCU\Software\Classes\Interface // so we're going to use that one - it's not super clean as the key stores COM interfaces, // but we should not corrupt anything by adding a special subkey even if it's left behind. // // Note: If you want to inspect the values written by the test and/or modify them manually // you have to navigate to HKCU\Software\Classes\Wow6432Node\Interface on a 64-bit OS. using (RegistryKey hkcu = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry32)) { parentKey = hkcu.CreateSubKey(@"Software\Classes\Interface"); keyName = "_DOTNET_Test" + Process.GetCurrentProcess().Id.ToString(); key = parentKey.CreateSubKey(keyName); PathValueOverride = key.Name; } } else { // On Linux/macOS the install location is registered in a file which is normally // located in /etc/dotnet/install_location // So we need to redirect it to a different place here. string directory = Path.Combine(TestArtifact.TestArtifactsPath, "installLocationOverride" + Process.GetCurrentProcess().Id.ToString()); if (Directory.Exists(directory)) { Directory.Delete(directory, true); } Directory.CreateDirectory(directory); PathValueOverride = directory; } }
public MultilevelSDKLookup() { // The dotnetMultilevelSDKLookup dir will contain some folders and files that will be // necessary to perform the tests string baseMultilevelDir = Path.Combine(TestArtifact.TestArtifactsPath, "dotnetMultilevelSDKLookup"); _multilevelDir = SharedFramework.CalculateUniqueTestDirectory(baseMultilevelDir); // The tested locations will be the cwd, user folder, exe dir, and registered directory. cwd and user are no longer supported. // All dirs will be placed inside the multilevel folder _currentWorkingDir = Path.Combine(_multilevelDir, "cwd"); _userDir = Path.Combine(_multilevelDir, "user"); _exeDir = Path.Combine(_multilevelDir, "exe"); _regDir = Path.Combine(_multilevelDir, "reg"); DotNet = new DotNetBuilder(_multilevelDir, Path.Combine(TestArtifact.TestArtifactsPath, "sharedFrameworkPublish"), "exe") .AddMicrosoftNETCoreAppFrameworkMockHostPolicy("9999.0.0") .Build(); RepoDirectories = new RepoDirectoriesProvider(builtDotnet: DotNet.BinPath); // SdkBaseDirs contain all available version folders _cwdSdkBaseDir = Path.Combine(_currentWorkingDir, "sdk"); _userSdkBaseDir = Path.Combine(_userDir, ".dotnet", RepoDirectories.BuildArchitecture, "sdk"); _exeSdkBaseDir = Path.Combine(_exeDir, "sdk"); _regSdkBaseDir = Path.Combine(_regDir, "sdk"); // Create directories Directory.CreateDirectory(_cwdSdkBaseDir); Directory.CreateDirectory(_userSdkBaseDir); Directory.CreateDirectory(_exeSdkBaseDir); Directory.CreateDirectory(_regSdkBaseDir); // Trace messages used to identify from which folder the SDK was picked _exeSelectedMessage = $"Using .NET SDK dll=[{_exeSdkBaseDir}"; _regSelectedMessage = $"Using .NET SDK dll=[{_regSdkBaseDir}"; _testOnlyProductBehaviorMarker = TestOnlyProductBehavior.Enable(DotNet.GreatestVersionHostFxrFilePath); }
public void Hostfxr_get_available_sdks_with_multilevel_lookup() { if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { // multilevel lookup is not supported on non-Windows return; } var f = new SdkResolutionFixture(sharedTestState); // With multi-level lookup (windows only): get local and global sdks sorted by ascending version, // with global sdk coming before local sdk when versions are equal string expectedList = string.Join(';', new[] { Path.Combine(f.LocalSdkDir, "0.1.2"), Path.Combine(f.ProgramFilesGlobalSdkDir, "1.2.3"), Path.Combine(f.LocalSdkDir, "1.2.3"), Path.Combine(f.ProgramFilesGlobalSdkDir, "2.3.4-preview"), Path.Combine(f.SelfRegisteredGlobalSdkDir, "3.0.0"), Path.Combine(f.ProgramFilesGlobalSdkDir, "4.5.6"), Path.Combine(f.LocalSdkDir, "5.6.7-preview"), Path.Combine(f.SelfRegisteredGlobalSdkDir, "5.6.7"), Path.Combine(f.SelfRegisteredGlobalSdkDir, "15.1.4-preview"), }); using (TestOnlyProductBehavior.Enable(f.Dotnet.GreatestVersionHostFxrFilePath)) { f.Dotnet.Exec(f.AppDll, new[] { "hostfxr_get_available_sdks", f.ExeDir }) .EnvironmentVariable("TEST_MULTILEVEL_LOOKUP_PROGRAM_FILES", f.ProgramFiles) .EnvironmentVariable("TEST_MULTILEVEL_LOOKUP_SELF_REGISTERED", f.SelfRegistered) .CaptureStdOut() .CaptureStdErr() .Execute() .Should().Pass() .And.HaveStdOutContaining("hostfxr_get_available_sdks:Success") .And.HaveStdOutContaining($"hostfxr_get_available_sdks sdks:[{expectedList}]"); } }
public MultilevelSharedFxLookup() { // 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 = new RepoDirectoriesProvider().GetTestContextVariable("TEST_ARTIFACTS"); _builtDotnet = Path.Combine(artifactsDir, "sharedFrameworkPublish"); // The dotnetMultilevelSharedFxLookup dir will contain some folders and files that will be // necessary to perform the tests string baseMultilevelDir = Path.Combine(artifactsDir, "dotnetMultilevelSharedFxLookup"); _multilevelDir = SharedFramework.CalculateUniqueTestDirectory(baseMultilevelDir); // 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(_multilevelDir, "cwd"); _userDir = Path.Combine(_multilevelDir, "user"); _exeDir = Path.Combine(_multilevelDir, "exe"); _regDir = Path.Combine(_multilevelDir, "reg"); RepoDirectories = new RepoDirectoriesProvider(builtDotnet: _exeDir); // 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(_exeDir, "shared", "Microsoft.NETCore.App"); _regSharedFxBaseDir = Path.Combine(_regDir, "shared", "Microsoft.NETCore.App"); _cwdSharedUberFxBaseDir = Path.Combine(_currentWorkingDir, "shared", "Microsoft.UberFramework"); _userSharedUberFxBaseDir = Path.Combine(_userDir, ".dotnet", RepoDirectories.BuildArchitecture, "shared", "Microsoft.UberFramework"); _exeSharedUberFxBaseDir = Path.Combine(_exeDir, "shared", "Microsoft.UberFramework"); _regSharedUberFxBaseDir = Path.Combine(_regDir, "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(_regSharedFxBaseDir); Directory.CreateDirectory(_cwdSharedUberFxBaseDir); Directory.CreateDirectory(_userSharedUberFxBaseDir); Directory.CreateDirectory(_regSharedUberFxBaseDir); SharedFramework.CopyDirectory(_builtDotnet, _exeDir); //Copy dotnet to self-registered directory File.Copy( Path.Combine(_builtDotnet, RuntimeInformationExtensions.GetExeFileNameForCurrentPlatform("dotnet")), Path.Combine(_regDir, RuntimeInformationExtensions.GetExeFileNameForCurrentPlatform("dotnet")), true); // Restore and build SharedFxLookupPortableApp from exe dir SharedFxLookupPortableAppFixture = new TestProjectFixture("SharedFxLookupPortableApp", RepoDirectories) .EnsureRestored() .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}"; _regSelectedMessage = $"The expected {_hostPolicyDllName} directory is [{_regSharedFxBaseDir}"; _exeFoundUberFxMessage = $"Chose FX version [{_exeSharedUberFxBaseDir}"; _testOnlyProductBehaviorMarker = TestOnlyProductBehavior.Enable(fixture.BuiltDotnet.GreatestVersionHostFxrFilePath); }