@@ -24,7 +24,6 @@ internal class ToolRunCommand(
2424 private readonly ToolManifestFinder _toolManifest = toolManifest ?? new ToolManifestFinder ( new DirectoryPath ( Directory . GetCurrentDirectory ( ) ) ) ;
2525 private readonly bool _fromSource = result . GetValue ( ToolRunCommandParser . FromSourceOption ) ;
2626
27- private readonly ToolInstallLocalInstaller _toolInstaller = new ( result ) ;
2827 private readonly IToolManifestEditor _toolManifestEditor = new ToolManifestEditor ( ) ;
2928 private readonly ILocalToolsResolverCache _localToolsResolverCache = new LocalToolsResolverCache ( ) ;
3029 public override int Execute ( )
@@ -39,7 +38,7 @@ public override int Execute()
3938
4039 if ( commandspec == null && _fromSource )
4140 {
42- commandspec = GetRemoteCommandSpec ( ) ;
41+ return ExecuteFromSource ( ) ;
4342 }
4443
4544 if ( commandspec == null )
@@ -51,11 +50,16 @@ public override int Execute()
5150 return result . ExitCode ;
5251 }
5352
54- public CommandSpec ? GetRemoteCommandSpec ( )
53+ public int ExecuteFromSource ( )
5554 {
55+ string tempDirectory = PathUtilities . CreateTempSubdirectory ( ) ;
5656 FilePath manifestFile = _toolManifest . FindFirst ( true ) ;
5757 PackageId packageId = new ( _toolCommandName ) ;
5858
59+ ToolInstallLocalInstaller _toolInstaller = new ( _parseResult , new ToolPackageDownloader (
60+ localToolDownloadDir : tempDirectory ,
61+ store : new ToolPackageStoreAndQuery ( new DirectoryPath ( tempDirectory ) ) ) ) ;
62+
5963 IToolPackage toolPackage = _toolInstaller . Install ( manifestFile , packageId ) ;
6064
6165 _toolManifestEditor . Add (
@@ -69,10 +73,21 @@ public override int Execute()
6973 toolPackage ,
7074 _toolInstaller . TargetFrameworkToInstall ) ;
7175
72- return _localToolsCommandResolver . ResolveStrict ( new CommandResolverArguments ( )
76+ CommandSpec commandSpec = _localToolsCommandResolver . ResolveStrict ( new CommandResolverArguments ( )
7377 {
7478 CommandName = $ "dotnet-{ toolPackage . Command . Name } ",
7579 CommandArguments = _forwardArgument ,
7680 } , _allowRollForward ) ;
81+
82+ if ( commandSpec == null )
83+ {
84+ throw new GracefulException ( [ string . Format ( CliCommandStrings . CannotFindCommandName , _toolCommandName ) ] , isUserError : false ) ;
85+ }
86+
87+ var result = CommandFactoryUsingResolver . Create ( commandSpec ) . Execute ( ) ;
88+
89+ _toolManifestEditor . Remove ( manifestFile , toolPackage . Id ) ;
90+
91+ return result . ExitCode ;
7792 }
7893}
0 commit comments