Exemplo n.º 1
0
        protected async Task SetupHelloWorldProject(string dotNetExePath, string intermediateOutputDir, bool useExistingSetup, ITestOutputHelper output)
        {
            string helloWorldProjectDir = Path.Combine(intermediateOutputDir, "helloworld");

            //the 'exePath' gets passed as an argument to dotnet.exe
            //in this case it isn't an executable at all, its a CLI command
            //a little cheap, but it works
            ExePath        = "build";
            WorkingDirPath = helloWorldProjectDir;

            // This disables using the shared build server. I was told using it interferes with the ability to delete folders after the
            // test is complete though I haven't encountered that particular issue myself. I imagine this meaningfully changes the
            // performance of this benchmark, so if we ever want to do real perf testing on the shared scenario we have to resolve this
            // issue another way.
            EnvironmentVariables["UseSharedCompilation"] = "false";

            if (!useExistingSetup)
            {
                FileTasks.DeleteDirectory(helloWorldProjectDir, output);
                FileTasks.CreateDirectory(helloWorldProjectDir, output);
                await new ProcessRunner(dotNetExePath, "new console")
                .WithWorkingDirectory(helloWorldProjectDir)
                .WithLog(output)
                .Run();
            }
        }
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
        protected override async Task SetupSourceToCompile(string intermediateOutputDir, string runtimeDirPath, bool useExistingSetup, ITestOutputHelper output)
#pragma warning restore CS1998
        {
            string helloWorldDir            = Path.Combine(intermediateOutputDir, "helloWorldSource");
            string helloWorldPath           = Path.Combine(helloWorldDir, "hello.cs");
            string systemPrivateCoreLibPath = Path.Combine(runtimeDirPath, "System.Private.CoreLib.dll");
            string systemRuntimePath        = Path.Combine(runtimeDirPath, "System.Runtime.dll");
            string systemConsolePath        = Path.Combine(runtimeDirPath, "System.Console.dll");

            CommandLineArguments = "hello.cs /nostdlib /r:" + systemPrivateCoreLibPath + " /r:" + systemRuntimePath + " /r:" + systemConsolePath;
            WorkingDirPath       = helloWorldDir;
            if (useExistingSetup)
            {
                return;
            }

            FileTasks.DeleteDirectory(helloWorldDir, output);
            FileTasks.CreateDirectory(helloWorldDir, output);
            File.WriteAllLines(helloWorldPath, new string[]
            {
                "using System;",
                "public static class Program",
                "{",
                "    public static void Main(string[] args)",
                "    {",
                "        Console.WriteLine(\"Hello World!\");",
                "    }",
                "}"
            });
        }