5
5
using System . Collections . Generic ;
6
6
using System . IO ;
7
7
using System . Linq ;
8
- using System . Net . Http ;
9
8
using System . Reflection ;
10
9
using System . Runtime . CompilerServices ;
11
10
using System . Threading . Tasks ;
12
11
using System . Xml . Linq ;
13
- using Microsoft . Azure . Management . AppService . Fluent ;
14
- using Microsoft . Azure . Management . AppService . Fluent . Models ;
15
12
using Xunit ;
16
13
using Xunit . Abstractions ;
17
14
@@ -42,7 +39,7 @@ public async Task DotnetNewWebRunsInWebApp(string template, string expected)
42
39
{
43
40
var site = await _fixture . Deploy ( "Templates\\ BasicAppServices.json" , baseName : testId ) ;
44
41
var testDirectory = GetTestDirectory ( testId ) ;
45
- var dotnet = DotNet ( logger , testDirectory ) ;
42
+ var dotnet = DotNet ( logger , testDirectory , "2.0" ) ;
46
43
47
44
await dotnet . ExecuteAndAssertAsync ( "new " + template ) ;
48
45
@@ -79,11 +76,11 @@ public async Task DotnetNewWebRunsWebAppOnLatestRuntime(string template, string
79
76
} ) ;
80
77
81
78
var testDirectory = GetTestDirectory ( testId ) ;
82
- var dotnet = DotNet ( logger , testDirectory ) ;
79
+ var dotnet = DotNet ( logger , testDirectory , "latest" ) ;
83
80
84
81
await dotnet . ExecuteAndAssertAsync ( "new " + template ) ;
85
82
86
- FixAspNetCoreVersion ( testDirectory ) ;
83
+ FixAspNetCoreVersion ( testDirectory , dotnet . Command ) ;
87
84
88
85
await dotnet . ExecuteAndAssertAsync ( "restore" ) ;
89
86
@@ -100,27 +97,36 @@ public async Task DotnetNewWebRunsWebAppOnLatestRuntime(string template, string
100
97
}
101
98
}
102
99
103
- private static void FixAspNetCoreVersion ( DirectoryInfo testDirectory )
100
+ private static void FixAspNetCoreVersion ( DirectoryInfo testDirectory , string dotnetPath )
104
101
{
105
102
// TODO: Temporary workaround for broken templates in latest CLI
106
103
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
-
113
104
// Detect what version of aspnet core was shipped with this CLI installation
114
105
var aspnetCoreVersion =
115
106
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
+
124
130
projectContents . Save ( csproj ) ;
125
131
}
126
132
@@ -140,15 +146,37 @@ private TestLogger GetLogger([CallerMemberName] string callerName = null)
140
146
return new TestLogger ( factory , factory . CreateLogger ( callerName ) ) ;
141
147
}
142
148
143
- private TestCommand DotNet ( TestLogger logger , DirectoryInfo workingDirectory )
149
+ private TestCommand DotNet ( TestLogger logger , DirectoryInfo workingDirectory , string sufix )
144
150
{
145
- return new TestCommand ( "dotnet" )
151
+ return new TestCommand ( GetDotnetPath ( sufix ) )
146
152
{
147
153
Logger = logger ,
148
154
WorkingDirectory = workingDirectory . FullName
149
155
} ;
150
156
}
151
157
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
+
152
180
private DirectoryInfo GetTestDirectory ( [ CallerMemberName ] string callerName = null )
153
181
{
154
182
if ( Directory . Exists ( callerName ) )
0 commit comments