66using System . Collections . Generic ;
77using Cake . Common . Tools . DotNet . Tool ;
88using Cake . Core ;
9+ using Cake . Core . Configuration ;
910using Cake . Core . IO ;
1011
1112namespace Cake . Common . Tools . DotNet
@@ -123,11 +124,9 @@ private static void AppendToolExecuteSettings(ProcessArgumentBuilder builder, Do
123124 AppendRestoreSettings ( builder , settings . DisableParallel , settings . IgnoreFailedSources , settings . NoHttpCache , settings . Interactive ) ;
124125 }
125126
126- private static void AppendToolInstallSettings ( ProcessArgumentBuilder builder , DotNetToolInstallSettings settings , ICakeEnvironment environment )
127+ private static void AppendToolInstallSettings ( ProcessArgumentBuilder builder , DotNetToolInstallSettings settings , ICakeConfiguration configuration , ICakeEnvironment environment )
127128 {
128- AppendSwitch ( builder , "--global" , settings . Global ) ;
129- AppendSwitch ( builder , "--local" , settings . Local ) ;
130- AppendDirectoryPath ( builder , "--tool-path" , settings . ToolInstallationPath , environment ) ;
129+ AppendInstallationScope ( builder , settings . InstallationScope , settings . ToolInstallationPath , settings . WorkingDirectory , configuration , environment ) ;
131130 AppendPackageResolutionSettings ( builder , settings . Version , settings . ConfigFile , settings . Source , settings . AddSource , settings . Prerelease , environment ) ;
132131 AppendFilePath ( builder , "--tool-manifest" , settings . ToolManifest , environment ) ;
133132 AppendString ( builder , "--framework" , settings . Framework ) ;
@@ -138,11 +137,11 @@ private static void AppendToolInstallSettings(ProcessArgumentBuilder builder, Do
138137 AppendSwitch ( builder , "--allow-roll-forward" , settings . AllowRollForward ) ;
139138 }
140139
141- private static void AppendToolListSettings ( ProcessArgumentBuilder builder , DotNetToolListSettings settings , ICakeEnvironment environment )
140+ private static void AppendToolListSettings ( ProcessArgumentBuilder builder , DotNetToolListSettings settings , ICakeConfiguration configuration , ICakeEnvironment environment )
142141 {
143- AppendSwitch ( builder , "--global" , settings . Global ) ;
144- AppendSwitch ( builder , "--local" , settings . Local ) ;
145- AppendDirectoryPath ( builder , "--tool-path " , settings . ToolInstallationPath , environment ) ;
142+ AppendInstallationScope ( builder , settings . InstallationScope , settings . ToolInstallationPath , settings . WorkingDirectory , configuration , environment ) ;
143+
144+ AppendFilePath ( builder , "--tool-manifest " , settings . ToolManifest , environment ) ;
146145
147146 if ( settings . Format . HasValue )
148147 {
@@ -180,19 +179,15 @@ private static void AppendToolSearchSettings(ProcessArgumentBuilder builder, Dot
180179 AppendSwitch ( builder , "--prerelease" , settings . Prerelease ) ;
181180 }
182181
183- private static void AppendToolUninstallSettings ( ProcessArgumentBuilder builder , DotNetToolUninstallSettings settings , ICakeEnvironment environment )
182+ private static void AppendToolUninstallSettings ( ProcessArgumentBuilder builder , DotNetToolUninstallSettings settings , ICakeConfiguration configuration , ICakeEnvironment environment )
184183 {
185- AppendSwitch ( builder , "--global" , settings . Global ) ;
186- AppendSwitch ( builder , "--local" , settings . Local ) ;
187- AppendDirectoryPath ( builder , "--tool-path" , settings . ToolInstallationPath , environment ) ;
184+ AppendInstallationScope ( builder , settings . InstallationScope , settings . ToolInstallationPath , settings . WorkingDirectory , configuration , environment ) ;
188185 AppendFilePath ( builder , "--tool-manifest" , settings . ToolManifest , environment ) ;
189186 }
190187
191- private static void AppendToolUpdateSettings ( ProcessArgumentBuilder builder , DotNetToolUpdateSettings settings , ICakeEnvironment environment )
188+ private static void AppendToolUpdateSettings ( ProcessArgumentBuilder builder , DotNetToolUpdateSettings settings , ICakeConfiguration configuration , ICakeEnvironment environment )
192189 {
193- AppendSwitch ( builder , "--global" , settings . Global ) ;
194- AppendSwitch ( builder , "--local" , settings . Local ) ;
195- AppendDirectoryPath ( builder , "--tool-path" , settings . ToolInstallationPath , environment ) ;
190+ AppendInstallationScope ( builder , settings . InstallationScope , settings . ToolInstallationPath , settings . WorkingDirectory , configuration , environment ) ;
196191 AppendPackageResolutionSettings ( builder , settings . Version , settings . ConfigFile , settings . Source , settings . AddSource , settings . Prerelease , environment ) ;
197192 AppendFilePath ( builder , "--tool-manifest" , settings . ToolManifest , environment ) ;
198193 AppendString ( builder , "--framework" , settings . Framework ) ;
@@ -201,6 +196,30 @@ private static void AppendToolUpdateSettings(ProcessArgumentBuilder builder, Dot
201196 AppendSwitch ( builder , "--all" , settings . All ) ;
202197 }
203198
199+ private static void AppendInstallationScope (
200+ ProcessArgumentBuilder builder ,
201+ DotNetToolInstallationScope scope ,
202+ DirectoryPath toolInstallationPath ,
203+ DirectoryPath settingsWorkingDirectory ,
204+ ICakeConfiguration configuration ,
205+ ICakeEnvironment environment )
206+ {
207+ switch ( scope )
208+ {
209+ case DotNetToolInstallationScope . Global :
210+ builder . Append ( "--global" ) ;
211+ break ;
212+ case DotNetToolInstallationScope . Local :
213+ builder . Append ( "--local" ) ;
214+ break ;
215+ case DotNetToolInstallationScope . ToolPath :
216+ var root = settingsWorkingDirectory ?? environment . WorkingDirectory ;
217+ var path = toolInstallationPath ?? configuration . GetToolPath ( root , environment ) ;
218+ AppendDirectoryPath ( builder , "--tool-path" , path , environment ) ;
219+ break ;
220+ }
221+ }
222+
204223 private static void AppendPackageResolutionSettings (
205224 ProcessArgumentBuilder builder ,
206225 string version ,
0 commit comments