@@ -36,44 +36,19 @@ internal sealed class DotNetSdkInstaller(IFeatures features, IConfiguration conf
3636 bool . TryParse ( alwaysInstallSdk , out var alwaysInstall ) &&
3737 alwaysInstall ;
3838
39- // First check if we already have the SDK installed in our private runtimes directory
40- // If we do, verify it's working properly by calling dotnet nuget config paths
41- // This is important on Windows where NuGet needs to create initial config on first use
39+ // First check if we already have the SDK installed in our private sdks directory
4240 if ( ! forceInstall )
4341 {
44- var runtimesDirectory = GetRuntimesDirectory ( ) ;
45- var sdkInstallPath = Path . Combine ( runtimesDirectory , "dotnet" , minimumVersion ) ;
42+ var sdksDirectory = GetSdksDirectory ( ) ;
43+ var sdkInstallPath = Path . Combine ( sdksDirectory , "dotnet" , minimumVersion ) ;
4644 var dotnetExecutable = RuntimeInformation . IsOSPlatform ( OSPlatform . Windows )
4745 ? Path . Combine ( sdkInstallPath , "dotnet.exe" )
4846 : Path . Combine ( sdkInstallPath , "dotnet" ) ;
4947
5048 if ( File . Exists ( dotnetExecutable ) )
5149 {
52- logger . LogDebug ( "Found private SDK installation at {Path}, verifying it works" , sdkInstallPath ) ;
53-
54- try
55- {
56- // Call GetNuGetConfigPathsAsync to ensure NuGet is properly initialized
57- var options = new DotNetCliRunnerInvocationOptions ( ) ;
58- var ( exitCode , _) = await dotNetCliRunner . GetNuGetConfigPathsAsync (
59- new DirectoryInfo ( Environment . CurrentDirectory ) ,
60- options ,
61- cancellationToken ) ;
62-
63- if ( exitCode == 0 )
64- {
65- logger . LogDebug ( "Private SDK installation verified successfully" ) ;
66- return ( true , minimumVersion , minimumVersion , false ) ;
67- }
68- else
69- {
70- logger . LogDebug ( "Private SDK installation verification failed with exit code {ExitCode}" , exitCode ) ;
71- }
72- }
73- catch ( Exception ex )
74- {
75- logger . LogDebug ( ex , "Failed to verify private SDK installation" ) ;
76- }
50+ logger . LogDebug ( "Found private SDK installation at {Path}" , sdkInstallPath ) ;
51+ return ( true , minimumVersion , minimumVersion , false ) ;
7752 }
7853 }
7954
@@ -159,8 +134,8 @@ internal sealed class DotNetSdkInstaller(IFeatures features, IConfiguration conf
159134 public async Task InstallAsync ( CancellationToken cancellationToken = default )
160135 {
161136 var sdkVersion = GetEffectiveMinimumSdkVersion ( ) ;
162- var runtimesDirectory = GetRuntimesDirectory ( ) ;
163- var sdkInstallPath = Path . Combine ( runtimesDirectory , "dotnet" , sdkVersion ) ;
137+ var sdksDirectory = GetSdksDirectory ( ) ;
138+ var sdkInstallPath = Path . Combine ( sdksDirectory , "dotnet" , sdkVersion ) ;
164139
165140 // Check if SDK is already installed in the private location
166141 if ( Directory . Exists ( sdkInstallPath ) )
@@ -169,14 +144,14 @@ public async Task InstallAsync(CancellationToken cancellationToken = default)
169144 return ;
170145 }
171146
172- // Create the runtimes directory if it doesn't exist
173- Directory . CreateDirectory ( runtimesDirectory ) ;
147+ // Create the sdks directory if it doesn't exist
148+ Directory . CreateDirectory ( sdksDirectory ) ;
174149
175150 // Determine which install script to use based on the platform
176151 var ( scriptUrl , scriptFileName , scriptRunner ) = GetInstallScriptInfo ( ) ;
177152
178153 // Download the install script
179- var scriptPath = Path . Combine ( runtimesDirectory , scriptFileName ) ;
154+ var scriptPath = Path . Combine ( sdksDirectory , scriptFileName ) ;
180155 using ( var httpClient = new HttpClient ( ) )
181156 {
182157 httpClient . Timeout = TimeSpan . FromMinutes ( 5 ) ;
@@ -271,6 +246,31 @@ public async Task InstallAsync(CancellationToken cancellationToken = default)
271246 {
272247 // Ignore cleanup errors
273248 }
249+
250+ // After installation, call dotnet nuget config paths to initialize NuGet
251+ // This is important on Windows where NuGet needs to create initial config on first use
252+ logger . LogDebug ( "Initializing NuGet configuration for private SDK installation" ) ;
253+ try
254+ {
255+ var options = new DotNetCliRunnerInvocationOptions ( ) ;
256+ var ( exitCode , _) = await dotNetCliRunner . GetNuGetConfigPathsAsync (
257+ new DirectoryInfo ( Environment . CurrentDirectory ) ,
258+ options ,
259+ cancellationToken ) ;
260+
261+ if ( exitCode == 0 )
262+ {
263+ logger . LogDebug ( "NuGet configuration initialized successfully" ) ;
264+ }
265+ else
266+ {
267+ logger . LogDebug ( "NuGet configuration initialization returned exit code {ExitCode}" , exitCode ) ;
268+ }
269+ }
270+ catch ( Exception ex )
271+ {
272+ logger . LogDebug ( ex , "Failed to initialize NuGet configuration, continuing anyway" ) ;
273+ }
274274 }
275275
276276 /// <summary>
@@ -290,12 +290,12 @@ private static string GetCurrentArchitecture()
290290 }
291291
292292 /// <summary>
293- /// Gets the directory where .NET runtimes are stored.
293+ /// Gets the directory where .NET SDKs are stored.
294294 /// </summary>
295- /// <returns>The full path to the runtimes directory.</returns>
296- private string GetRuntimesDirectory ( )
295+ /// <returns>The full path to the sdks directory.</returns>
296+ private string GetSdksDirectory ( )
297297 {
298- return executionContext . RuntimesDirectory . FullName ;
298+ return executionContext . SdksDirectory . FullName ;
299299 }
300300
301301 /// <summary>
0 commit comments