@@ -182,6 +182,17 @@ 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 (
190
+ IS_WINDOWS ? '-Install-Dir' : '--install-dir' ,
191
+ installPath
192
+ ) ;
193
+ return this ;
194
+ }
195
+
185
196
public useVersion ( dotnetVersion : DotnetVersion , quality ?: QualityOptions ) {
186
197
if ( dotnetVersion . type ) {
187
198
this . useArguments ( dotnetVersion . type , dotnetVersion . value ) ;
@@ -222,11 +233,20 @@ export abstract class DotnetInstallDir {
222
233
windows : path . join ( process . env [ 'PROGRAMFILES' ] + '' , 'dotnet' )
223
234
} ;
224
235
225
- public static readonly dirPath = process . env [ 'DOTNET_INSTALL_DIR' ]
226
- ? DotnetInstallDir . convertInstallPathToAbsolute (
227
- process . env [ 'DOTNET_INSTALL_DIR' ]
228
- )
229
- : DotnetInstallDir . default [ PLATFORM ] ;
236
+ private static getInstallDirectory ( ) {
237
+ if ( process . env [ 'DOTNET_INSTALL_DIR' ] != null ) {
238
+ return process . env [ 'DOTNET_INSTALL_DIR' ] ;
239
+ }
240
+ if ( process . env [ 'RUNNER_TOOL_CACHE' ] != null ) {
241
+ return path . join ( process . env [ 'RUNNER_TOOL_CACHE' ] , 'dotnet' ) ;
242
+ }
243
+ return DotnetInstallDir . default [ PLATFORM ] ;
244
+ }
245
+
246
+ public static readonly dirPath =
247
+ DotnetInstallDir . convertInstallPathToAbsolute (
248
+ DotnetInstallDir . getInstallDirectory ( )
249
+ ) ;
230
250
231
251
private static convertInstallPathToAbsolute ( installDir : string ) : string {
232
252
if ( path . isAbsolute ( installDir ) ) return path . normalize ( installDir ) ;
@@ -275,6 +295,8 @@ export class DotnetCoreInstaller {
275
295
. useArguments ( IS_WINDOWS ? '-Runtime' : '--runtime' , 'dotnet' )
276
296
// Use latest stable version
277
297
. useArguments ( IS_WINDOWS ? '-Channel' : '--channel' , 'LTS' )
298
+ // Explicitly set the install path (see https://github.com/actions/setup-dotnet/issues/360)
299
+ . useInstallPath ( DotnetInstallDir . dirPath )
278
300
. execute ( ) ;
279
301
280
302
if ( runtimeInstallOutput . exitCode ) {
@@ -298,6 +320,8 @@ export class DotnetCoreInstaller {
298
320
)
299
321
// Use version provided by user
300
322
. useVersion ( dotnetVersion , this . quality )
323
+ // Explicitly set the install path (see https://github.com/actions/setup-dotnet/issues/360)
324
+ . useInstallPath ( DotnetInstallDir . dirPath )
301
325
. execute ( ) ;
302
326
303
327
if ( dotnetInstallOutput . exitCode ) {
0 commit comments