1
- // Licensed to the .NET Foundation under one or more agreements.
1
+ // Licensed to the .NET Foundation under one or more agreements.
2
2
// The .NET Foundation licenses this file to you under the MIT license.
3
3
4
4
using System ;
@@ -16,6 +16,9 @@ namespace nanoFramework.nanoCLR.CLI
16
16
public static class ClrInstanceOperationsProcessor
17
17
{
18
18
private const string _cloudSmithApiUrl = "https://api.cloudsmith.io/v1/packages/net-nanoframework/" ;
19
+ private const string _refTargetsDevRepo = "nanoframework-images-dev" ;
20
+ private const string _refTargetsStableRepo = "nanoframework-images" ;
21
+
19
22
private static HttpClient _httpClient = new HttpClient ( ) ;
20
23
21
24
public static int ProcessVerb ( ClrInstanceOperationsOptions options )
@@ -52,6 +55,7 @@ public static int ProcessVerb(ClrInstanceOperationsOptions options)
52
55
return ( int ) UpdateNanoCLRAsync (
53
56
options . TargetVersion ,
54
57
hostBuilder . GetCLRVersion ( ) ,
58
+ options . CheckPreviewVersions ,
55
59
hostBuilder ) . Result ;
56
60
}
57
61
else if ( options . GetCLRVersion || options . GetNativeAssemblies )
@@ -110,12 +114,13 @@ orderby na.Name
110
114
private static async Task < ExitCode > UpdateNanoCLRAsync (
111
115
string targetVersion ,
112
116
string currentVersion ,
117
+ bool usePreview ,
113
118
nanoCLRHostBuilder hostBuilder )
114
119
{
115
120
try
116
121
{
117
122
// compose current version
118
- // need to get rid of git hub has , in case it has one
123
+ // need to get rid of GitHub hash , in case it has one
119
124
if ( string . IsNullOrEmpty ( currentVersion ) )
120
125
{
121
126
currentVersion = "0.0.0.0" ;
@@ -127,7 +132,7 @@ private static async Task<ExitCode> UpdateNanoCLRAsync(
127
132
currentVersion . IndexOf ( "+" ) < 0 ? currentVersion . Length : currentVersion . IndexOf ( "+" ) ) ;
128
133
}
129
134
130
- Version version = Version . Parse ( currentVersion ) ;
135
+ Version installedVersion = Version . Parse ( currentVersion ) ;
131
136
132
137
string nanoClrDllLocation = Path . Combine (
133
138
Path . GetDirectoryName ( Assembly . GetExecutingAssembly ( ) . Location ) ,
@@ -137,32 +142,37 @@ private static async Task<ExitCode> UpdateNanoCLRAsync(
137
142
_httpClient . BaseAddress = new Uri ( _cloudSmithApiUrl ) ;
138
143
_httpClient . DefaultRequestHeaders . Add ( "Accept" , "*/*" ) ;
139
144
145
+ string repoName = usePreview ? _refTargetsDevRepo : _refTargetsStableRepo ;
146
+
140
147
// get latest version available for download
141
- HttpResponseMessage response = await _httpClient . GetAsync ( $ "nanoframework-images /?query=name:^WIN_DLL_nanoCLR version:^latest$") ;
148
+ HttpResponseMessage response = await _httpClient . GetAsync ( $ "{ repoName } /?query=name:^WIN_DLL_nanoCLR version:^latest$") ;
142
149
string responseBody = await response . Content . ReadAsStringAsync ( ) ;
143
150
144
151
if ( responseBody == "[]" )
145
152
{
146
- Console . WriteLine ( $ "Error getting latest nanoCLR version .") ;
153
+ Console . WriteLine ( $ "Error getting latest available nanoCLR package .") ;
147
154
return ExitCode . E9005 ;
148
155
}
149
156
150
157
var packageInfo = JsonSerializer . Deserialize < List < CloudsmithPackageInfo > > ( responseBody ) ;
151
158
152
159
if ( packageInfo . Count != 1 )
153
160
{
154
- Console . WriteLine ( $ "Error parsing latest nanoCLR version.") ;
161
+ Console . WriteLine ( $ "Error parsing nanoCLR version from package details .") ;
155
162
return ExitCode . E9005 ;
156
163
}
157
164
else
158
165
{
159
- Version latestFwVersion = Version . Parse ( packageInfo [ 0 ] . Version ) ;
166
+ Version availableFwVersion = Version . Parse ( packageInfo [ 0 ] . Version ) ;
160
167
161
- if ( latestFwVersion < version )
168
+ // only perform version check if preview wasn't requested
169
+ if ( ! usePreview && ( availableFwVersion < installedVersion ) )
162
170
{
163
- Console . WriteLine ( $ "Current version { version } lower than available version { packageInfo [ 0 ] . Version } ") ;
171
+ Console . WriteLine ( $ "Current version { installedVersion } higher than available version { packageInfo [ 0 ] . Version } ") ;
164
172
}
165
- else if ( latestFwVersion > version
173
+
174
+ if ( usePreview
175
+ || ( availableFwVersion > installedVersion )
166
176
|| ( ! string . IsNullOrEmpty ( targetVersion )
167
177
&& ( Version . Parse ( targetVersion ) > Version . Parse ( currentVersion ) ) ) )
168
178
{
@@ -172,8 +182,8 @@ private static async Task<ExitCode> UpdateNanoCLRAsync(
172
182
// need to unload the DLL before updating it
173
183
hostBuilder . UnloadNanoClrDll ( ) ;
174
184
175
- await using var ms = await response . Content . ReadAsStreamAsync ( ) ;
176
- await using var fs = File . OpenWrite ( nanoClrDllLocation ) ;
185
+ await using Stream ms = await response . Content . ReadAsStreamAsync ( ) ;
186
+ await using FileStream fs = File . OpenWrite ( nanoClrDllLocation ) ;
177
187
178
188
ms . Seek ( 0 , SeekOrigin . Begin ) ;
179
189
await ms . CopyToAsync ( fs ) ;
0 commit comments