From 8cc1cdc62f58dba0df0b8fa2015b8402fc66457c Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Fri, 25 Aug 2017 12:51:11 -0700 Subject: [PATCH] Install and use multiple runtimes/sdks (#93) --- .gitignore | 2 +- build/repo.targets | 7 +- ...re.AzureAppServices.FunctionalTests.csproj | 1 + .../TemplateFunctionalTests.cs | 72 +++++++++++++------ .../TestCommand.cs | 42 +---------- .../global.json.template | 1 + 6 files changed, 61 insertions(+), 64 deletions(-) create mode 100644 test/Microsoft.AspNetCore.AzureAppServices.FunctionalTests/global.json.template diff --git a/.gitignore b/.gitignore index ada37ce594..7b71529a2e 100644 --- a/.gitignore +++ b/.gitignore @@ -31,4 +31,4 @@ project.lock.json global.json korebuild-lock.txt msbuild.binlog -.test-dotnet +.test-dotnet/ diff --git a/build/repo.targets b/build/repo.targets index c58b5a242d..1f5b31648a 100644 --- a/build/repo.targets +++ b/build/repo.targets @@ -1,7 +1,8 @@ - $(RepositoryRoot).test-dotnet\ + $(RepositoryRoot).test-dotnet\ + $(TestDotNetPath)extension\ $(RepositoryRoot)src\Microsoft.AspNetCore.AzureAppServices.TestBundle\ https://dotnet.myget.org/F/aspnetcore-ci-dev/ master @@ -9,7 +10,9 @@ - + + + diff --git a/test/Microsoft.AspNetCore.AzureAppServices.FunctionalTests/Microsoft.AspNetCore.AzureAppServices.FunctionalTests.csproj b/test/Microsoft.AspNetCore.AzureAppServices.FunctionalTests/Microsoft.AspNetCore.AzureAppServices.FunctionalTests.csproj index d0ad305a3a..e3c7a4a800 100644 --- a/test/Microsoft.AspNetCore.AzureAppServices.FunctionalTests/Microsoft.AspNetCore.AzureAppServices.FunctionalTests.csproj +++ b/test/Microsoft.AspNetCore.AzureAppServices.FunctionalTests/Microsoft.AspNetCore.AzureAppServices.FunctionalTests.csproj @@ -10,6 +10,7 @@ + diff --git a/test/Microsoft.AspNetCore.AzureAppServices.FunctionalTests/TemplateFunctionalTests.cs b/test/Microsoft.AspNetCore.AzureAppServices.FunctionalTests/TemplateFunctionalTests.cs index 633fd63249..bed37702d7 100644 --- a/test/Microsoft.AspNetCore.AzureAppServices.FunctionalTests/TemplateFunctionalTests.cs +++ b/test/Microsoft.AspNetCore.AzureAppServices.FunctionalTests/TemplateFunctionalTests.cs @@ -5,13 +5,10 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; -using System.Net.Http; using System.Reflection; using System.Runtime.CompilerServices; using System.Threading.Tasks; using System.Xml.Linq; -using Microsoft.Azure.Management.AppService.Fluent; -using Microsoft.Azure.Management.AppService.Fluent.Models; using Xunit; using Xunit.Abstractions; @@ -42,7 +39,7 @@ namespace Microsoft.AspNetCore.AzureAppServices.FunctionalTests { var site = await _fixture.Deploy("Templates\\BasicAppServices.json", baseName: testId); var testDirectory = GetTestDirectory(testId); - var dotnet = DotNet(logger, testDirectory); + var dotnet = DotNet(logger, testDirectory, "2.0"); await dotnet.ExecuteAndAssertAsync("new " + template); @@ -79,11 +76,11 @@ namespace Microsoft.AspNetCore.AzureAppServices.FunctionalTests }); var testDirectory = GetTestDirectory(testId); - var dotnet = DotNet(logger, testDirectory); + var dotnet = DotNet(logger, testDirectory, "latest"); await dotnet.ExecuteAndAssertAsync("new " + template); - FixAspNetCoreVersion(testDirectory); + FixAspNetCoreVersion(testDirectory, dotnet.Command); await dotnet.ExecuteAndAssertAsync("restore"); @@ -100,27 +97,36 @@ namespace Microsoft.AspNetCore.AzureAppServices.FunctionalTests } } - private static void FixAspNetCoreVersion(DirectoryInfo testDirectory) + private static void FixAspNetCoreVersion(DirectoryInfo testDirectory, string dotnetPath) { // TODO: Temporary workaround for broken templates in latest CLI - var csproj = testDirectory.GetFiles("*.csproj").Single().FullName; - var projectContents = XDocument.Load(csproj); - var packageReference = projectContents - .Descendants("PackageReference") - .Single(element => (string) element.Attribute("Include") == "Microsoft.AspNetCore.All"); - // Detect what version of aspnet core was shipped with this CLI installation var aspnetCoreVersion = new DirectoryInfo( - Path.Combine( - Path.GetDirectoryName(TestCommand.DotnetPath), - "store", "x86", "netcoreapp2.0", "microsoft.aspnetcore")) - .GetDirectories() - .Single() - .Name; + Path.Combine( + Path.GetDirectoryName(dotnetPath), + "store", "x64", "netcoreapp2.0", "microsoft.aspnetcore")) + .GetDirectories() + .Single() + .Name; + + var csproj = testDirectory.GetFiles("*.csproj").Single().FullName; + var projectContents = XDocument.Load(csproj); + var packageReferences = projectContents + .Descendants("PackageReference"); + + foreach (var packageReference in packageReferences) + { + var packageName = (string)packageReference.Attribute("Include"); + + if (packageName == "Microsoft.AspNetCore.All" || + packageName == "Microsoft.VisualStudio.Web.CodeGeneration.Tools") + { + packageReference.Attribute("Version").Value = aspnetCoreVersion; + } + } - packageReference.Attribute("Version").Value = aspnetCoreVersion; projectContents.Save(csproj); } @@ -140,15 +146,37 @@ namespace Microsoft.AspNetCore.AzureAppServices.FunctionalTests return new TestLogger(factory, factory.CreateLogger(callerName)); } - private TestCommand DotNet(TestLogger logger, DirectoryInfo workingDirectory) + private TestCommand DotNet(TestLogger logger, DirectoryInfo workingDirectory, string sufix) { - return new TestCommand("dotnet") + return new TestCommand(GetDotnetPath(sufix)) { Logger = logger, WorkingDirectory = workingDirectory.FullName }; } + private static string GetDotnetPath(string sufix) + { + var current = new DirectoryInfo(Directory.GetCurrentDirectory()); + while (current != null) + { + var dotnetSubdir = new DirectoryInfo(Path.Combine(current.FullName, ".test-dotnet", sufix)); + if (dotnetSubdir.Exists) + { + var dotnetName = Path.Combine(dotnetSubdir.FullName, "dotnet.exe"); + if (!File.Exists(dotnetName)) + { + throw new InvalidOperationException("dotnet directory was found but dotnet.exe is not in it"); + } + return dotnetName; + } + current = current.Parent; + } + + throw new InvalidOperationException("dotnet executable was not found"); + } + + private DirectoryInfo GetTestDirectory([CallerMemberName] string callerName = null) { if (Directory.Exists(callerName)) diff --git a/test/Microsoft.AspNetCore.AzureAppServices.FunctionalTests/TestCommand.cs b/test/Microsoft.AspNetCore.AzureAppServices.FunctionalTests/TestCommand.cs index 4eec47076b..29c1088c0b 100644 --- a/test/Microsoft.AspNetCore.AzureAppServices.FunctionalTests/TestCommand.cs +++ b/test/Microsoft.AspNetCore.AzureAppServices.FunctionalTests/TestCommand.cs @@ -13,32 +13,9 @@ namespace Microsoft.AspNetCore.AzureAppServices.FunctionalTests { public class TestCommand { - public static string DotnetPath { get; } = GetDotnetPath(); - - private static string GetDotnetPath() - { - var current = new DirectoryInfo(Directory.GetCurrentDirectory()); - while (current != null) - { - var dotnetSubdir = new DirectoryInfo(Path.Combine(current.FullName, ".test-dotnet")); - if (dotnetSubdir.Exists) - { - var dotnetName = Path.Combine(dotnetSubdir.FullName, "dotnet.exe"); - if (!File.Exists(dotnetName)) - { - throw new InvalidOperationException("dotnet directory was found but dotnet.exe is not in it"); - } - return dotnetName; - } - current = current.Parent; - } - - throw new InvalidOperationException("dotnet executable was not found"); - } - private List _cliGeneratedEnvironmentVariables = new List { "MSBuildSDKsPath" }; - protected string _command; + public string Command { get; } public Process CurrentProcess { get; private set; } @@ -53,7 +30,7 @@ namespace Microsoft.AspNetCore.AzureAppServices.FunctionalTests public TestCommand(string command) { - _command = command; + Command = command; } public void KillTree() @@ -68,9 +45,7 @@ namespace Microsoft.AspNetCore.AzureAppServices.FunctionalTests public virtual async Task ExecuteAsync(string args = "") { - var resolvedCommand = _command; - - ResolveCommand(ref resolvedCommand, ref args); + var resolvedCommand = Command; Logger.LogInformation($"Executing - {resolvedCommand} {args} - {WorkingDirectoryInfo()}"); @@ -203,17 +178,6 @@ namespace Microsoft.AspNetCore.AzureAppServices.FunctionalTests } } - private void ResolveCommand(ref string executable, ref string args) - { - if (executable == "dotnet") - { - executable = DotnetPath; - return; - } - - throw new ArgumentOutOfRangeException(nameof(executable)); - } - private void RemoveCliGeneratedEnvironmentVariablesFrom(ProcessStartInfo psi) { foreach (var name in _cliGeneratedEnvironmentVariables) diff --git a/test/Microsoft.AspNetCore.AzureAppServices.FunctionalTests/global.json.template b/test/Microsoft.AspNetCore.AzureAppServices.FunctionalTests/global.json.template new file mode 100644 index 0000000000..9e26dfeeb6 --- /dev/null +++ b/test/Microsoft.AspNetCore.AzureAppServices.FunctionalTests/global.json.template @@ -0,0 +1 @@ +{} \ No newline at end of file