Install and use multiple runtimes/sdks (#93)

This commit is contained in:
Pavel Krymets 2017-08-25 12:51:11 -07:00 committed by GitHub
parent c7fabda615
commit 8cc1cdc62f
6 changed files with 61 additions and 64 deletions

2
.gitignore vendored
View File

@ -31,4 +31,4 @@ project.lock.json
global.json global.json
korebuild-lock.txt korebuild-lock.txt
msbuild.binlog msbuild.binlog
.test-dotnet .test-dotnet/

View File

@ -1,7 +1,8 @@
<Project> <Project>
<PropertyGroup> <PropertyGroup>
<SiteExtensionWorkingDirectory>$(RepositoryRoot).test-dotnet\</SiteExtensionWorkingDirectory> <TestDotNetPath>$(RepositoryRoot).test-dotnet\</TestDotNetPath>
<SiteExtensionWorkingDirectory>$(TestDotNetPath)extension\</SiteExtensionWorkingDirectory>
<SiteExtensionProjectDirectory>$(RepositoryRoot)src\Microsoft.AspNetCore.AzureAppServices.TestBundle\</SiteExtensionProjectDirectory> <SiteExtensionProjectDirectory>$(RepositoryRoot)src\Microsoft.AspNetCore.AzureAppServices.TestBundle\</SiteExtensionProjectDirectory>
<SiteExtensionFeed Condition="$(SiteExtensionFeed) == ''">https://dotnet.myget.org/F/aspnetcore-ci-dev/</SiteExtensionFeed> <SiteExtensionFeed Condition="$(SiteExtensionFeed) == ''">https://dotnet.myget.org/F/aspnetcore-ci-dev/</SiteExtensionFeed>
<DotnetChannel>master</DotnetChannel> <DotnetChannel>master</DotnetChannel>
@ -9,7 +10,9 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<DotNetCoreSdk Include="coherent" Channel="master" InstallDir="$(SiteExtensionWorkingDirectory)" Arch="x86" /> <DotNetCoreSdk Include="coherent" Channel="master" InstallDir="$(SiteExtensionWorkingDirectory)" Arch="x86" Condition="'$(AntaresSiteExtension)' != ''"/>
<DotNetCoreSdk Include="coherent" Channel="master" InstallDir="$(TestDotNetPath)latest\" Condition="'$(AntaresTests)' != ''"/>
<DotNetCoreSdk Include="2.0.0" InstallDir="$(TestDotNetPath)2.0\" Condition="'$(AntaresTests)' != ''"/>
</ItemGroup> </ItemGroup>
<Target Name="BuildSiteExtension" DependsOnTargets="InstallDotNet"> <Target Name="BuildSiteExtension" DependsOnTargets="InstallDotNet">

View File

@ -10,6 +10,7 @@
<ItemGroup> <ItemGroup>
<None Include="Templates\*.*" CopyToOutputDirectory="PreserveNewest" /> <None Include="Templates\*.*" CopyToOutputDirectory="PreserveNewest" />
<ContentWithTargetPath Include="NuGet.config.template" CopyToOutputDirectory="PreserveNewest" TargetPath="NuGet.config"/> <ContentWithTargetPath Include="NuGet.config.template" CopyToOutputDirectory="PreserveNewest" TargetPath="NuGet.config"/>
<ContentWithTargetPath Include="global.json.template" CopyToOutputDirectory="PreserveNewest" TargetPath="global.json"/>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -5,13 +5,10 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Net.Http;
using System.Reflection; using System.Reflection;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Xml.Linq; using System.Xml.Linq;
using Microsoft.Azure.Management.AppService.Fluent;
using Microsoft.Azure.Management.AppService.Fluent.Models;
using Xunit; using Xunit;
using Xunit.Abstractions; using Xunit.Abstractions;
@ -42,7 +39,7 @@ namespace Microsoft.AspNetCore.AzureAppServices.FunctionalTests
{ {
var site = await _fixture.Deploy("Templates\\BasicAppServices.json", baseName: testId); var site = await _fixture.Deploy("Templates\\BasicAppServices.json", baseName: testId);
var testDirectory = GetTestDirectory(testId); var testDirectory = GetTestDirectory(testId);
var dotnet = DotNet(logger, testDirectory); var dotnet = DotNet(logger, testDirectory, "2.0");
await dotnet.ExecuteAndAssertAsync("new " + template); await dotnet.ExecuteAndAssertAsync("new " + template);
@ -79,11 +76,11 @@ namespace Microsoft.AspNetCore.AzureAppServices.FunctionalTests
}); });
var testDirectory = GetTestDirectory(testId); var testDirectory = GetTestDirectory(testId);
var dotnet = DotNet(logger, testDirectory); var dotnet = DotNet(logger, testDirectory, "latest");
await dotnet.ExecuteAndAssertAsync("new " + template); await dotnet.ExecuteAndAssertAsync("new " + template);
FixAspNetCoreVersion(testDirectory); FixAspNetCoreVersion(testDirectory, dotnet.Command);
await dotnet.ExecuteAndAssertAsync("restore"); 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 // 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 // Detect what version of aspnet core was shipped with this CLI installation
var aspnetCoreVersion = var aspnetCoreVersion =
new DirectoryInfo( new DirectoryInfo(
Path.Combine( Path.Combine(
Path.GetDirectoryName(TestCommand.DotnetPath), Path.GetDirectoryName(dotnetPath),
"store", "x86", "netcoreapp2.0", "microsoft.aspnetcore")) "store", "x64", "netcoreapp2.0", "microsoft.aspnetcore"))
.GetDirectories() .GetDirectories()
.Single() .Single()
.Name; .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); projectContents.Save(csproj);
} }
@ -140,15 +146,37 @@ namespace Microsoft.AspNetCore.AzureAppServices.FunctionalTests
return new TestLogger(factory, factory.CreateLogger(callerName)); 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, Logger = logger,
WorkingDirectory = workingDirectory.FullName 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) private DirectoryInfo GetTestDirectory([CallerMemberName] string callerName = null)
{ {
if (Directory.Exists(callerName)) if (Directory.Exists(callerName))

View File

@ -13,32 +13,9 @@ namespace Microsoft.AspNetCore.AzureAppServices.FunctionalTests
{ {
public class TestCommand 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<string> _cliGeneratedEnvironmentVariables = new List<string> { "MSBuildSDKsPath" }; private List<string> _cliGeneratedEnvironmentVariables = new List<string> { "MSBuildSDKsPath" };
protected string _command; public string Command { get; }
public Process CurrentProcess { get; private set; } public Process CurrentProcess { get; private set; }
@ -53,7 +30,7 @@ namespace Microsoft.AspNetCore.AzureAppServices.FunctionalTests
public TestCommand(string command) public TestCommand(string command)
{ {
_command = command; Command = command;
} }
public void KillTree() public void KillTree()
@ -68,9 +45,7 @@ namespace Microsoft.AspNetCore.AzureAppServices.FunctionalTests
public virtual async Task<CommandResult> ExecuteAsync(string args = "") public virtual async Task<CommandResult> ExecuteAsync(string args = "")
{ {
var resolvedCommand = _command; var resolvedCommand = Command;
ResolveCommand(ref resolvedCommand, ref args);
Logger.LogInformation($"Executing - {resolvedCommand} {args} - {WorkingDirectoryInfo()}"); 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) private void RemoveCliGeneratedEnvironmentVariablesFrom(ProcessStartInfo psi)
{ {
foreach (var name in _cliGeneratedEnvironmentVariables) foreach (var name in _cliGeneratedEnvironmentVariables)