Install and use multiple runtimes/sdks (#93)
This commit is contained in:
parent
c7fabda615
commit
8cc1cdc62f
|
|
@ -31,4 +31,4 @@ project.lock.json
|
|||
global.json
|
||||
korebuild-lock.txt
|
||||
msbuild.binlog
|
||||
.test-dotnet
|
||||
.test-dotnet/
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
<Project>
|
||||
|
||||
<PropertyGroup>
|
||||
<SiteExtensionWorkingDirectory>$(RepositoryRoot).test-dotnet\</SiteExtensionWorkingDirectory>
|
||||
<TestDotNetPath>$(RepositoryRoot).test-dotnet\</TestDotNetPath>
|
||||
<SiteExtensionWorkingDirectory>$(TestDotNetPath)extension\</SiteExtensionWorkingDirectory>
|
||||
<SiteExtensionProjectDirectory>$(RepositoryRoot)src\Microsoft.AspNetCore.AzureAppServices.TestBundle\</SiteExtensionProjectDirectory>
|
||||
<SiteExtensionFeed Condition="$(SiteExtensionFeed) == ''">https://dotnet.myget.org/F/aspnetcore-ci-dev/</SiteExtensionFeed>
|
||||
<DotnetChannel>master</DotnetChannel>
|
||||
|
|
@ -9,7 +10,9 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<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>
|
||||
|
||||
<Target Name="BuildSiteExtension" DependsOnTargets="InstallDotNet">
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
<ItemGroup>
|
||||
<None Include="Templates\*.*" CopyToOutputDirectory="PreserveNewest" />
|
||||
<ContentWithTargetPath Include="NuGet.config.template" CopyToOutputDirectory="PreserveNewest" TargetPath="NuGet.config"/>
|
||||
<ContentWithTargetPath Include="global.json.template" CopyToOutputDirectory="PreserveNewest" TargetPath="global.json"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -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<string> _cliGeneratedEnvironmentVariables = new List<string> { "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<CommandResult> 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)
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
{}
|
||||
Loading…
Reference in New Issue