Skip to content

Commit 8cc1cdc

Browse files
authored
Install and use multiple runtimes/sdks (#93)
1 parent c7fabda commit 8cc1cdc

File tree

6 files changed

+62
-65
lines changed

6 files changed

+62
-65
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ project.lock.json
3131
global.json
3232
korebuild-lock.txt
3333
msbuild.binlog
34-
.test-dotnet
34+
.test-dotnet/

build/repo.targets

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
<Project>
22

33
<PropertyGroup>
4-
<SiteExtensionWorkingDirectory>$(RepositoryRoot).test-dotnet\</SiteExtensionWorkingDirectory>
4+
<TestDotNetPath>$(RepositoryRoot).test-dotnet\</TestDotNetPath>
5+
<SiteExtensionWorkingDirectory>$(TestDotNetPath)extension\</SiteExtensionWorkingDirectory>
56
<SiteExtensionProjectDirectory>$(RepositoryRoot)src\Microsoft.AspNetCore.AzureAppServices.TestBundle\</SiteExtensionProjectDirectory>
67
<SiteExtensionFeed Condition="$(SiteExtensionFeed) == ''">https://dotnet.myget.org/F/aspnetcore-ci-dev/</SiteExtensionFeed>
78
<DotnetChannel>master</DotnetChannel>
89
<DotnetVersion>coherent</DotnetVersion>
910
</PropertyGroup>
1011

1112
<ItemGroup>
12-
<DotNetCoreSdk Include="coherent" Channel="master" InstallDir="$(SiteExtensionWorkingDirectory)" Arch="x86" />
13+
<DotNetCoreSdk Include="coherent" Channel="master" InstallDir="$(SiteExtensionWorkingDirectory)" Arch="x86" Condition="'$(AntaresSiteExtension)' != ''"/>
14+
<DotNetCoreSdk Include="coherent" Channel="master" InstallDir="$(TestDotNetPath)latest\" Condition="'$(AntaresTests)' != ''"/>
15+
<DotNetCoreSdk Include="2.0.0" InstallDir="$(TestDotNetPath)2.0\" Condition="'$(AntaresTests)' != ''"/>
1316
</ItemGroup>
1417

1518
<Target Name="BuildSiteExtension" DependsOnTargets="InstallDotNet">

test/Microsoft.AspNetCore.AzureAppServices.FunctionalTests/Microsoft.AspNetCore.AzureAppServices.FunctionalTests.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<ItemGroup>
1111
<None Include="Templates\*.*" CopyToOutputDirectory="PreserveNewest" />
1212
<ContentWithTargetPath Include="NuGet.config.template" CopyToOutputDirectory="PreserveNewest" TargetPath="NuGet.config"/>
13+
<ContentWithTargetPath Include="global.json.template" CopyToOutputDirectory="PreserveNewest" TargetPath="global.json"/>
1314
</ItemGroup>
1415

1516
<ItemGroup>

test/Microsoft.AspNetCore.AzureAppServices.FunctionalTests/TemplateFunctionalTests.cs

+51-23
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,10 @@
55
using System.Collections.Generic;
66
using System.IO;
77
using System.Linq;
8-
using System.Net.Http;
98
using System.Reflection;
109
using System.Runtime.CompilerServices;
1110
using System.Threading.Tasks;
1211
using System.Xml.Linq;
13-
using Microsoft.Azure.Management.AppService.Fluent;
14-
using Microsoft.Azure.Management.AppService.Fluent.Models;
1512
using Xunit;
1613
using Xunit.Abstractions;
1714

@@ -42,7 +39,7 @@ public async Task DotnetNewWebRunsInWebApp(string template, string expected)
4239
{
4340
var site = await _fixture.Deploy("Templates\\BasicAppServices.json", baseName: testId);
4441
var testDirectory = GetTestDirectory(testId);
45-
var dotnet = DotNet(logger, testDirectory);
42+
var dotnet = DotNet(logger, testDirectory, "2.0");
4643

4744
await dotnet.ExecuteAndAssertAsync("new " + template);
4845

@@ -79,11 +76,11 @@ public async Task DotnetNewWebRunsWebAppOnLatestRuntime(string template, string
7976
});
8077

8178
var testDirectory = GetTestDirectory(testId);
82-
var dotnet = DotNet(logger, testDirectory);
79+
var dotnet = DotNet(logger, testDirectory, "latest");
8380

8481
await dotnet.ExecuteAndAssertAsync("new " + template);
8582

86-
FixAspNetCoreVersion(testDirectory);
83+
FixAspNetCoreVersion(testDirectory, dotnet.Command);
8784

8885
await dotnet.ExecuteAndAssertAsync("restore");
8986

@@ -100,27 +97,36 @@ public async Task DotnetNewWebRunsWebAppOnLatestRuntime(string template, string
10097
}
10198
}
10299

103-
private static void FixAspNetCoreVersion(DirectoryInfo testDirectory)
100+
private static void FixAspNetCoreVersion(DirectoryInfo testDirectory, string dotnetPath)
104101
{
105102
// TODO: Temporary workaround for broken templates in latest CLI
106103

107-
var csproj = testDirectory.GetFiles("*.csproj").Single().FullName;
108-
var projectContents = XDocument.Load(csproj);
109-
var packageReference = projectContents
110-
.Descendants("PackageReference")
111-
.Single(element => (string) element.Attribute("Include") == "Microsoft.AspNetCore.All");
112-
113104
// Detect what version of aspnet core was shipped with this CLI installation
114105
var aspnetCoreVersion =
115106
new DirectoryInfo(
116-
Path.Combine(
117-
Path.GetDirectoryName(TestCommand.DotnetPath),
118-
"store", "x86", "netcoreapp2.0", "microsoft.aspnetcore"))
119-
.GetDirectories()
120-
.Single()
121-
.Name;
122-
123-
packageReference.Attribute("Version").Value = aspnetCoreVersion;
107+
Path.Combine(
108+
Path.GetDirectoryName(dotnetPath),
109+
"store", "x64", "netcoreapp2.0", "microsoft.aspnetcore"))
110+
.GetDirectories()
111+
.Single()
112+
.Name;
113+
114+
var csproj = testDirectory.GetFiles("*.csproj").Single().FullName;
115+
var projectContents = XDocument.Load(csproj);
116+
var packageReferences = projectContents
117+
.Descendants("PackageReference");
118+
119+
foreach (var packageReference in packageReferences)
120+
{
121+
var packageName = (string)packageReference.Attribute("Include");
122+
123+
if (packageName == "Microsoft.AspNetCore.All" ||
124+
packageName == "Microsoft.VisualStudio.Web.CodeGeneration.Tools")
125+
{
126+
packageReference.Attribute("Version").Value = aspnetCoreVersion;
127+
}
128+
}
129+
124130
projectContents.Save(csproj);
125131
}
126132

@@ -140,15 +146,37 @@ private TestLogger GetLogger([CallerMemberName] string callerName = null)
140146
return new TestLogger(factory, factory.CreateLogger(callerName));
141147
}
142148

143-
private TestCommand DotNet(TestLogger logger, DirectoryInfo workingDirectory)
149+
private TestCommand DotNet(TestLogger logger, DirectoryInfo workingDirectory, string sufix)
144150
{
145-
return new TestCommand("dotnet")
151+
return new TestCommand(GetDotnetPath(sufix))
146152
{
147153
Logger = logger,
148154
WorkingDirectory = workingDirectory.FullName
149155
};
150156
}
151157

158+
private static string GetDotnetPath(string sufix)
159+
{
160+
var current = new DirectoryInfo(Directory.GetCurrentDirectory());
161+
while (current != null)
162+
{
163+
var dotnetSubdir = new DirectoryInfo(Path.Combine(current.FullName, ".test-dotnet", sufix));
164+
if (dotnetSubdir.Exists)
165+
{
166+
var dotnetName = Path.Combine(dotnetSubdir.FullName, "dotnet.exe");
167+
if (!File.Exists(dotnetName))
168+
{
169+
throw new InvalidOperationException("dotnet directory was found but dotnet.exe is not in it");
170+
}
171+
return dotnetName;
172+
}
173+
current = current.Parent;
174+
}
175+
176+
throw new InvalidOperationException("dotnet executable was not found");
177+
}
178+
179+
152180
private DirectoryInfo GetTestDirectory([CallerMemberName] string callerName = null)
153181
{
154182
if (Directory.Exists(callerName))

test/Microsoft.AspNetCore.AzureAppServices.FunctionalTests/TestCommand.cs

+3-39
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,9 @@ namespace Microsoft.AspNetCore.AzureAppServices.FunctionalTests
1313
{
1414
public class TestCommand
1515
{
16-
public static string DotnetPath { get; } = GetDotnetPath();
17-
18-
private static string GetDotnetPath()
19-
{
20-
var current = new DirectoryInfo(Directory.GetCurrentDirectory());
21-
while (current != null)
22-
{
23-
var dotnetSubdir = new DirectoryInfo(Path.Combine(current.FullName, ".test-dotnet"));
24-
if (dotnetSubdir.Exists)
25-
{
26-
var dotnetName = Path.Combine(dotnetSubdir.FullName, "dotnet.exe");
27-
if (!File.Exists(dotnetName))
28-
{
29-
throw new InvalidOperationException("dotnet directory was found but dotnet.exe is not in it");
30-
}
31-
return dotnetName;
32-
}
33-
current = current.Parent;
34-
}
35-
36-
throw new InvalidOperationException("dotnet executable was not found");
37-
}
38-
3916
private List<string> _cliGeneratedEnvironmentVariables = new List<string> { "MSBuildSDKsPath" };
4017

41-
protected string _command;
18+
public string Command { get; }
4219

4320
public Process CurrentProcess { get; private set; }
4421

@@ -53,7 +30,7 @@ private static string GetDotnetPath()
5330

5431
public TestCommand(string command)
5532
{
56-
_command = command;
33+
Command = command;
5734
}
5835

5936
public void KillTree()
@@ -68,9 +45,7 @@ public void KillTree()
6845

6946
public virtual async Task<CommandResult> ExecuteAsync(string args = "")
7047
{
71-
var resolvedCommand = _command;
72-
73-
ResolveCommand(ref resolvedCommand, ref args);
48+
var resolvedCommand = Command;
7449

7550
Logger.LogInformation($"Executing - {resolvedCommand} {args} - {WorkingDirectoryInfo()}");
7651

@@ -203,17 +178,6 @@ private void RemoveNullTerminator(List<string> strings)
203178
}
204179
}
205180

206-
private void ResolveCommand(ref string executable, ref string args)
207-
{
208-
if (executable == "dotnet")
209-
{
210-
executable = DotnetPath;
211-
return;
212-
}
213-
214-
throw new ArgumentOutOfRangeException(nameof(executable));
215-
}
216-
217181
private void RemoveCliGeneratedEnvironmentVariablesFrom(ProcessStartInfo psi)
218182
{
219183
foreach (var name in _cliGeneratedEnvironmentVariables)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

0 commit comments

Comments
 (0)