@@ -182,6 +182,14 @@ 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 ( IS_WINDOWS ? '-Install-Dir' : "--install-dir" , installPath ) ;
190+ return this ;
191+ }
192+
185193 public useVersion ( dotnetVersion : DotnetVersion , quality ?: QualityOptions ) {
186194 if ( dotnetVersion . type ) {
187195 this . useArguments ( dotnetVersion . type , dotnetVersion . value ) ;
@@ -222,12 +230,18 @@ export abstract class DotnetInstallDir {
222230 windows : path . join ( process . env [ 'PROGRAMFILES' ] + '' , 'dotnet' )
223231 } ;
224232
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+ }
230242
243+ public static readonly dirPath = DotnetInstallDir . convertInstallPathToAbsolute ( DotnetInstallDir . getInstallDirectory ( ) ) ;
244+
231245 private static convertInstallPathToAbsolute ( installDir : string ) : string {
232246 if ( path . isAbsolute ( installDir ) ) return path . normalize ( installDir ) ;
233247
@@ -257,7 +271,7 @@ export class DotnetCoreInstaller {
257271 private version : string ,
258272 private quality : QualityOptions
259273 ) { }
260-
274+
261275 public async installDotnet ( ) : Promise < string | null > {
262276 const versionResolver = new DotnetVersionResolver ( this . version ) ;
263277 const dotnetVersion = await versionResolver . createDotnetVersion ( ) ;
@@ -275,6 +289,8 @@ export class DotnetCoreInstaller {
275289 . useArguments ( IS_WINDOWS ? '-Runtime' : '--runtime' , 'dotnet' )
276290 // Use latest stable version
277291 . 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 )
278294 . execute ( ) ;
279295
280296 if ( runtimeInstallOutput . exitCode ) {
@@ -298,6 +314,8 @@ export class DotnetCoreInstaller {
298314 )
299315 // Use version provided by user
300316 . useVersion ( dotnetVersion , this . quality )
317+ // Explicitly set the install path (see https://github.com/actions/setup-dotnet/issues/360)
318+ . useInstallPath ( DotnetInstallDir . dirPath )
301319 . execute ( ) ;
302320
303321 if ( dotnetInstallOutput . exitCode ) {
0 commit comments