@@ -182,6 +182,14 @@ export class DotnetInstallScript {
182
182
return this ;
183
183
}
184
184
185
+ public useInstallPath ( installPath : string ) {
186
+ if ( installPath == null ) {
187
+ installPath = DotnetInstallDir . dirPath ;
188
+ }
189
+ this . useArguments ( IS_WINDOWS ? '-Install-Dir' : "--install-dir" , installPath ) ;
190
+ return this ;
191
+ }
192
+
185
193
public useVersion ( dotnetVersion : DotnetVersion , quality ?: QualityOptions ) {
186
194
if ( dotnetVersion . type ) {
187
195
this . useArguments ( dotnetVersion . type , dotnetVersion . value ) ;
@@ -222,12 +230,18 @@ export abstract class DotnetInstallDir {
222
230
windows : path . join ( process . env [ 'PROGRAMFILES' ] + '' , 'dotnet' )
223
231
} ;
224
232
225
- public static readonly dirPath = process . env [ 'DOTNET_INSTALL_DIR' ]
226
- ? DotnetInstallDir . convertInstallPathToAbsolute (
227
- process . env [ 'DOTNET_INSTALL_DIR' ]
228
- )
229
- : DotnetInstallDir . default [ PLATFORM ] ;
233
+ private static getInstallDirectory ( ) {
234
+ if ( process . env [ "DOTNET_INSTALL_DIR" ] != null ) {
235
+ return process . env [ "DOTNET_INSTALL_DIR" ] ;
236
+ }
237
+ if ( process . env [ "RUNNER_TOOL_CACHE" ] != null ) {
238
+ return path . join ( process . env [ "RUNNER_TOOL_CACHE" ] , "dotnet" ) ;
239
+ }
240
+ return DotnetInstallDir . default [ PLATFORM ] ;
241
+ }
230
242
243
+ public static readonly dirPath = DotnetInstallDir . convertInstallPathToAbsolute ( DotnetInstallDir . getInstallDirectory ( ) ) ;
244
+
231
245
private static convertInstallPathToAbsolute ( installDir : string ) : string {
232
246
if ( path . isAbsolute ( installDir ) ) return path . normalize ( installDir ) ;
233
247
@@ -257,7 +271,7 @@ export class DotnetCoreInstaller {
257
271
private version : string ,
258
272
private quality : QualityOptions
259
273
) { }
260
-
274
+
261
275
public async installDotnet ( ) : Promise < string | null > {
262
276
const versionResolver = new DotnetVersionResolver ( this . version ) ;
263
277
const dotnetVersion = await versionResolver . createDotnetVersion ( ) ;
@@ -275,6 +289,8 @@ export class DotnetCoreInstaller {
275
289
. useArguments ( IS_WINDOWS ? '-Runtime' : '--runtime' , 'dotnet' )
276
290
// Use latest stable version
277
291
. useArguments ( IS_WINDOWS ? '-Channel' : '--channel' , 'LTS' )
292
+ // Explicitly set the install path (see https://github.com/actions/setup-dotnet/issues/360)
293
+ . useInstallPath ( DotnetInstallDir . dirPath )
278
294
. execute ( ) ;
279
295
280
296
if ( runtimeInstallOutput . exitCode ) {
@@ -298,6 +314,8 @@ export class DotnetCoreInstaller {
298
314
)
299
315
// Use version provided by user
300
316
. useVersion ( dotnetVersion , this . quality )
317
+ // Explicitly set the install path (see https://github.com/actions/setup-dotnet/issues/360)
318
+ . useInstallPath ( DotnetInstallDir . dirPath )
301
319
. execute ( ) ;
302
320
303
321
if ( dotnetInstallOutput . exitCode ) {
0 commit comments