Пример #1
0
        protected async Task Build(string dotnetArgs, ITestOutputHelper output)
        {
            AssertDebuggeeSolutionDirExists(output);
            AssertDebuggeeProjectFileExists(output);
            AssertDebuggeeAssetsFileExists(output);

            output.WriteLine("Launching {0} {1}", DotNetToolPath, dotnetArgs);
            ProcessRunner runner = new ProcessRunner(DotNetToolPath, dotnetArgs).
                                   WithEnvironmentVariable("DOTNET_MULTILEVEL_LOOKUP", "0").
                                   WithEnvironmentVariable("DOTNET_ROOT", Path.GetDirectoryName(DotNetToolPath)).
                                   WithEnvironmentVariable("DOTNET_MSBUILD_SDK_RESOLVER_CLI_DIR", Path.GetDirectoryName(DotNetToolPath)).
                                   WithEnvironmentVariable("DOTNET_INSTALL_DIR", Path.GetDirectoryName(DotNetToolPath)).
                                   RemoveEnvironmentVariable("MSBuildSDKsPath").
                                   WithWorkingDirectory(DebuggeeProjectDirPath).
                                   WithLog(output).
                                   WithTimeout(TimeSpan.FromMinutes(10)). // a mac CI build of the modules debuggee is painfully slow :(
                                   WithExpectedExitCode(0);

            if (OS.Kind != OSKind.Windows && Environment.GetEnvironmentVariable("HOME") == null)
            {
                output.WriteLine("Detected HOME environment variable doesn't exist. This will trigger a bug in dotnet build.");
                output.WriteLine("See: https://github.com/NuGet/Home/issues/2960");
                output.WriteLine("Test will workaround this by manually setting a HOME value");
                output.WriteLine("");
                runner = runner.WithEnvironmentVariable("HOME", DebuggeeSolutionDirPath);
            }
            if (NuGetPackageCacheDirPath != null)
            {
                //dotnet restore helpfully documents its --packages argument in the help text, but
                //NUGET_PACKAGES was undocumented as far as I noticed. If this stops working we can also
                //auto-generate a global.json with a "packages" setting, but this was more expedient.
                runner = runner.WithEnvironmentVariable("NUGET_PACKAGES", NuGetPackageCacheDirPath);
            }

            await runner.Run();

            if (DebuggeeBinaryExePath != null)
            {
                AssertDebuggeeExeExists(output);
            }
            else
            {
                AssertDebuggeeDllExists(output);
            }
        }
Пример #2
0
        protected async Task Restore(string extraArgs, ITestOutputHelper output)
        {
            AssertDebuggeeSolutionDirExists(output);
            AssertDebuggeeProjectDirExists(output);
            AssertDebuggeeProjectFileExists(output);

            string args = "restore";

            if (NuGetConfigPath != null)
            {
                args += " --configfile " + NuGetConfigPath;
            }
            if (NuGetPackageCacheDirPath != null)
            {
                args += " --packages \"" + NuGetPackageCacheDirPath.TrimEnd('\\') + "\"";
            }
            if (extraArgs != null)
            {
                args += extraArgs;
            }
            output.WriteLine("Launching {0} {1}", DotNetToolPath, args);
            ProcessRunner runner = new ProcessRunner(DotNetToolPath, args).
                                   WithEnvironmentVariable("DOTNET_MULTILEVEL_LOOKUP", "0").
                                   WithEnvironmentVariable("DOTNET_ROOT", Path.GetDirectoryName(DotNetToolPath)).
                                   WithEnvironmentVariable("DOTNET_MSBUILD_SDK_RESOLVER_CLI_DIR", Path.GetDirectoryName(DotNetToolPath)).
                                   WithEnvironmentVariable("DOTNET_INSTALL_DIR", Path.GetDirectoryName(DotNetToolPath)).
                                   RemoveEnvironmentVariable("MSBuildSDKsPath").
                                   WithWorkingDirectory(DebuggeeSolutionDirPath).
                                   WithLog(output).
                                   WithTimeout(TimeSpan.FromMinutes(10)). // restore can be painfully slow
                                   WithExpectedExitCode(0);

            if (OS.Kind != OSKind.Windows && Environment.GetEnvironmentVariable("HOME") == null)
            {
                output.WriteLine("Detected HOME environment variable doesn't exist. This will trigger a bug in dotnet restore.");
                output.WriteLine("See: https://github.com/NuGet/Home/issues/2960");
                output.WriteLine("Test will workaround this by manually setting a HOME value");
                output.WriteLine("");
                runner = runner.WithEnvironmentVariable("HOME", DebuggeeSolutionDirPath);
            }

            //workaround for https://github.com/dotnet/cli/issues/3868
            await _dotnetRestoreLock.WaitAsync();

            try
            {
                await runner.Run();
            }
            finally
            {
                _dotnetRestoreLock.Release();
            }

            AssertDebuggeeAssetsFileExists(output);
        }
Пример #3
0
 /// <summary>
 /// Add the host environment variables to the process runner.
 /// </summary>
 /// <param name="runner">process runner instance</param>
 public void AddHostEnvVars(ProcessRunner runner)
 {
     if (HostEnvVars != null)
     {
         string[] vars = HostEnvVars.Split(';');
         foreach (string var in vars)
         {
             if (string.IsNullOrEmpty(var))
             {
                 continue;
             }
             string[] parts = var.Split('=');
             runner = runner.WithEnvironmentVariable(parts[0], parts[1]);
         }
     }
 }