@@ -34,6 +34,7 @@ internal class ToolInstallGlobalOrToolPathCommand : CommandBase
3434 private readonly IReporter _errorReporter ;
3535 private CreateShellShimRepository _createShellShimRepository ;
3636 private CreateToolPackageStoresAndInstaller _createToolPackageStoresAndInstaller ;
37+ private readonly ShellShimTemplateFinder _shellShimTemplateFinder ;
3738
3839 private readonly PackageId _packageId ;
3940 private readonly string _packageVersion ;
@@ -45,8 +46,6 @@ internal class ToolInstallGlobalOrToolPathCommand : CommandBase
4546 private readonly string _toolPath ;
4647 private readonly string _architectureOption ;
4748 private IEnumerable < string > _forwardRestoreArguments ;
48- private readonly DirectoryPath _tempDir ;
49- private readonly INuGetPackageDownloader _nugetPackageDownloader ;
5049
5150 public ToolInstallGlobalOrToolPathCommand (
5251 ParseResult parseResult ,
@@ -73,8 +72,16 @@ public ToolInstallGlobalOrToolPathCommand(
7372 _environmentPathInstruction = environmentPathInstruction
7473 ?? EnvironmentPathFactory . CreateEnvironmentPathInstruction ( ) ;
7574 _createShellShimRepository = createShellShimRepository ?? ShellShimRepositoryFactory . CreateShellShimRepository ;
76- _tempDir = new DirectoryPath ( Path . Combine ( Path . GetTempPath ( ) , "dotnet-tool-install" ) ) ;
77- _nugetPackageDownloader = nugetPackageDownloader ?? new NuGetPackageDownloader ( _tempDir , verboseLogger : new NullLogger ( ) ) ;
75+ var tempDir = new DirectoryPath ( Path . Combine ( Path . GetTempPath ( ) , "dotnet-tool-install" ) ) ;
76+ var configOption = parseResult . ValueForOption ( ToolInstallCommandParser . ConfigOption ) ;
77+ var sourceOption = parseResult . ValueForOption ( ToolInstallCommandParser . AddSourceOption ) ;
78+ var packageSourceLocation = new PackageSourceLocation ( string . IsNullOrEmpty ( configOption ) ? null : new FilePath ( configOption ) , additionalSourceFeeds : sourceOption ) ;
79+ var restoreAction = new RestoreActionConfig ( DisableParallel : parseResult . ValueForOption ( ToolCommandRestorePassThroughOptions . DisableParallelOption ) ,
80+ NoCache : parseResult . ValueForOption ( ToolCommandRestorePassThroughOptions . NoCacheOption ) ,
81+ IgnoreFailedSources : parseResult . ValueForOption ( ToolCommandRestorePassThroughOptions . IgnoreFailedSourcesOption ) ,
82+ Interactive : parseResult . ValueForOption ( ToolCommandRestorePassThroughOptions . InteractiveRestoreOption ) ) ;
83+ nugetPackageDownloader ??= new NuGetPackageDownloader ( tempDir , verboseLogger : new NullLogger ( ) , restoreActionConfig : restoreAction ) ;
84+ _shellShimTemplateFinder = new ShellShimTemplateFinder ( nugetPackageDownloader , tempDir , packageSourceLocation ) ;
7885
7986 _reporter = ( reporter ?? Reporter . Output ) ;
8087 _errorReporter = ( reporter ?? Reporter . Error ) ;
@@ -105,7 +112,7 @@ public override int Execute()
105112 toolPath = new DirectoryPath ( _toolPath ) ;
106113 }
107114
108- string appHostSourceDirectory = ResolveAppHostSourceDirectoryAsync ( _architectureOption , _framework ) . Result ;
115+ string appHostSourceDirectory = _shellShimTemplateFinder . ResolveAppHostSourceDirectoryAsync ( _architectureOption , _framework ) . Result ;
109116
110117 ( IToolPackageStore toolPackageStore , IToolPackageStoreQuery toolPackageStoreQuery , IToolPackageInstaller toolPackageInstaller ) =
111118 _createToolPackageStoresAndInstaller ( toolPath , _forwardRestoreArguments ) ;
@@ -171,39 +178,5 @@ public override int Execute()
171178 isUserError : false ) ;
172179 }
173180 }
174-
175- private async Task < string > ResolveAppHostSourceDirectoryAsync ( string archOption , string targetFramework )
176- {
177- string rid ;
178- var validRids = new string [ ] { "win-x64" , "win-arm64" , "osx-x64" , "osx-arm64" } ;
179- if ( string . IsNullOrEmpty ( archOption ) )
180- {
181- if ( ! string . IsNullOrEmpty ( targetFramework ) && new NuGetFramework ( targetFramework ) . Version < new Version ( "6.0" )
182- && ( OperatingSystem . IsWindows ( ) || OperatingSystem . IsMacOS ( ) ) && ! RuntimeInformation . ProcessArchitecture . Equals ( Architecture . X64 ) )
183- {
184- rid = OperatingSystem . IsWindows ( ) ? "win-x64" : "osx-x64" ;
185- }
186- else
187- {
188- // Use the default app host
189- return null ;
190- }
191- }
192- else
193- {
194- rid = CommonOptions . ResolveRidShorthandOptionsToRuntimeIdentifier ( null , archOption ) ;
195- }
196-
197- if ( ! validRids . Contains ( rid ) )
198- {
199- throw new GracefulException ( string . Format ( LocalizableStrings . InvalidRuntimeIdentifier , rid , string . Join ( " " , validRids ) ) ) ;
200- }
201-
202- var packageId = new PackageId ( $ "microsoft.netcore.app.host.{ rid } ") ;
203- var packagePath = await _nugetPackageDownloader . DownloadPackageAsync ( packageId ) ;
204- var content = await _nugetPackageDownloader . ExtractPackageAsync ( packagePath , _tempDir ) ;
205-
206- return Path . Combine ( _tempDir . Value , "runtimes" , rid , "native" ) ;
207- }
208181 }
209182}
0 commit comments