@@ -182,6 +182,17 @@ export class DotnetInstallScript {
182182 return this ;
183183 }
184184
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+
185196 public useVersion ( dotnetVersion : DotnetVersion , quality ?: QualityOptions ) {
186197 if ( dotnetVersion . type ) {
187198 this . useArguments ( dotnetVersion . type , dotnetVersion . value ) ;
@@ -222,11 +233,20 @@ export abstract class DotnetInstallDir {
222233 windows : path . join ( process . env [ 'PROGRAMFILES' ] + '' , 'dotnet' )
223234 } ;
224235
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+ ) ;
230250
231251 private static convertInstallPathToAbsolute ( installDir : string ) : string {
232252 if ( path . isAbsolute ( installDir ) ) return path . normalize ( installDir ) ;
@@ -275,6 +295,8 @@ export class DotnetCoreInstaller {
275295 . useArguments ( IS_WINDOWS ? '-Runtime' : '--runtime' , 'dotnet' )
276296 // Use latest stable version
277297 . 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 )
278300 . execute ( ) ;
279301
280302 if ( runtimeInstallOutput . exitCode ) {
@@ -298,6 +320,8 @@ export class DotnetCoreInstaller {
298320 )
299321 // Use version provided by user
300322 . useVersion ( dotnetVersion , this . quality )
323+ // Explicitly set the install path (see https://github.com/actions/setup-dotnet/issues/360)
324+ . useInstallPath ( DotnetInstallDir . dirPath )
301325 . execute ( ) ;
302326
303327 if ( dotnetInstallOutput . exitCode ) {
0 commit comments