#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously private async Task SetupSourceToCompile(string intermediateOutputDir, string runtimeDirPath, bool useExistingSetup, ITestOutputHelper output) #pragma warning restore CS1998 { const string sourceFile = "Program.cs"; const string csprojFile = "console.csproj"; string consoleProjectMainDir = GetRootDir(intermediateOutputDir); FileTasks.DeleteDirectory(consoleProjectMainDir, output); FileTasks.CreateDirectory(consoleProjectMainDir, output); File.WriteAllLines(Path.Combine(consoleProjectMainDir, sourceFile), new[] { "using System;", "public static class Program", "{", " public static int Main(string[] args) => 0;", "}" }); File.WriteAllLines(Path.Combine(consoleProjectMainDir, csprojFile), new[] { @"<Project Sdk=""Microsoft.NET.Sdk"">", @" <PropertyGroup>", @" <OutputType>Exe</OutputType>", @" <TargetFramework>netcoreapp2.1</TargetFramework>", @" </PropertyGroup>", @"</Project>", }); }
protected async Task SetupHelloWorldProject(DotNetInstallation dotNetInstall, 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(dotNetInstall.DotNetExe, "new console") .WithWorkingDirectory(helloWorldProjectDir) .WithLog(output) .Run(); RetargetProjects(dotNetInstall, helloWorldProjectDir, new string[] { "helloworld.csproj" }); } }
#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!\");", " }", "}" }); }