@@ -29,11 +29,11 @@ internal interface IDotNetCliRunner
29
29
Task < int > RunAsync ( FileInfo projectFile , bool watch , bool noBuild , string [ ] args , IDictionary < string , string > ? env , TaskCompletionSource < IAppHostBackchannel > ? backchannelCompletionSource , DotNetCliRunnerInvocationOptions options , CancellationToken cancellationToken ) ;
30
30
Task < int > CheckHttpCertificateAsync ( DotNetCliRunnerInvocationOptions options , CancellationToken cancellationToken ) ;
31
31
Task < int > TrustHttpCertificateAsync ( DotNetCliRunnerInvocationOptions options , CancellationToken cancellationToken ) ;
32
- Task < ( int ExitCode , string ? TemplateVersion ) > InstallTemplateAsync ( string packageName , string version , string ? nugetSource , bool force , DotNetCliRunnerInvocationOptions options , CancellationToken cancellationToken ) ;
32
+ Task < ( int ExitCode , string ? TemplateVersion ) > InstallTemplateAsync ( string packageName , string version , FileInfo ? nugetConfigFile , string ? nugetSource , bool force , DotNetCliRunnerInvocationOptions options , CancellationToken cancellationToken ) ;
33
33
Task < int > NewProjectAsync ( string templateName , string name , string outputPath , string [ ] extraArgs , DotNetCliRunnerInvocationOptions options , CancellationToken cancellationToken ) ;
34
34
Task < int > BuildAsync ( FileInfo projectFilePath , DotNetCliRunnerInvocationOptions options , CancellationToken cancellationToken ) ;
35
35
Task < int > AddPackageAsync ( FileInfo projectFilePath , string packageName , string packageVersion , string ? nugetSource , DotNetCliRunnerInvocationOptions options , CancellationToken cancellationToken ) ;
36
- Task < ( int ExitCode , NuGetPackage [ ] ? Packages ) > SearchPackagesAsync ( DirectoryInfo workingDirectory , string query , bool prerelease , int take , int skip , string ? nugetSource , DotNetCliRunnerInvocationOptions options , CancellationToken cancellationToken ) ;
36
+ Task < ( int ExitCode , NuGetPackage [ ] ? Packages ) > SearchPackagesAsync ( DirectoryInfo workingDirectory , string query , bool prerelease , int take , int skip , FileInfo ? nugetConfigFile , DotNetCliRunnerInvocationOptions options , CancellationToken cancellationToken ) ;
37
37
}
38
38
39
39
internal sealed class DotNetCliRunnerInvocationOptions
@@ -45,7 +45,7 @@ internal sealed class DotNetCliRunnerInvocationOptions
45
45
public bool StartDebugSession { get ; set ; }
46
46
}
47
47
48
- internal class DotNetCliRunner ( ILogger < DotNetCliRunner > logger , IServiceProvider serviceProvider , AspireCliTelemetry telemetry , IConfiguration configuration , IFeatures features , IInteractionService interactionService ) : IDotNetCliRunner
48
+ internal class DotNetCliRunner ( ILogger < DotNetCliRunner > logger , IServiceProvider serviceProvider , AspireCliTelemetry telemetry , IConfiguration configuration , IFeatures features , IInteractionService interactionService , CliExecutionContext executionContext ) : IDotNetCliRunner
49
49
{
50
50
51
51
internal Func < int > GetCurrentProcessId { get ; set ; } = ( ) => Environment . ProcessId ;
@@ -267,11 +267,12 @@ public async Task<int> TrustHttpCertificateAsync(DotNetCliRunnerInvocationOption
267
267
cancellationToken : cancellationToken ) ;
268
268
}
269
269
270
- public async Task < ( int ExitCode , string ? TemplateVersion ) > InstallTemplateAsync ( string packageName , string version , string ? nugetSource , bool force , DotNetCliRunnerInvocationOptions options , CancellationToken cancellationToken )
270
+ public async Task < ( int ExitCode , string ? TemplateVersion ) > InstallTemplateAsync ( string packageName , string version , FileInfo ? nugetConfigFile , string ? nugetSource , bool force , DotNetCliRunnerInvocationOptions options , CancellationToken cancellationToken )
271
271
{
272
272
using var activity = telemetry . ActivitySource . StartActivity ( nameof ( InstallTemplateAsync ) , ActivityKind . Client ) ;
273
273
274
- List < string > cliArgs = [ "new" , "install" , $ "{ packageName } ::{ version } "] ;
274
+ // NOTE: The change to @ over :: for template version separator (now enforced in .NET 10.0 SDK).
275
+ List < string > cliArgs = [ "new" , "install" , $ "{ packageName } @{ version } "] ;
275
276
276
277
if ( force )
277
278
{
@@ -298,6 +299,14 @@ public async Task<int> TrustHttpCertificateAsync(DotNetCliRunnerInvocationOption
298
299
existingStandardErrorCallback ? . Invoke ( line ) ;
299
300
} ;
300
301
302
+ // The dotnet new install command does not support the --configfile option so if we
303
+ // are installing packages based on a channel config we'll be passing in a nuget config
304
+ // file which is dynamically generated in a temporary folder. We'll use that temporary
305
+ // folder as the working directory for the command. If we are using an implicit channel
306
+ // then we just use the current execution context for the CLI and inherit whatever
307
+ // NuGet.configs that may or may not be laying around.
308
+ var workingDirectory = nugetConfigFile ? . Directory ?? executionContext . WorkingDirectory ;
309
+
301
310
var exitCode = await ExecuteAsync (
302
311
args : [ .. cliArgs ] ,
303
312
env : new Dictionary < string , string >
@@ -307,7 +316,7 @@ public async Task<int> TrustHttpCertificateAsync(DotNetCliRunnerInvocationOption
307
316
[ KnownConfigNames . DotnetCliUiLanguage ] = "en-US"
308
317
} ,
309
318
projectFile : null ,
310
- workingDirectory : new DirectoryInfo ( Environment . CurrentDirectory ) ,
319
+ workingDirectory : workingDirectory ,
311
320
backchannelCompletionSource : null ,
312
321
options : options ,
313
322
cancellationToken : cancellationToken ) ;
@@ -705,7 +714,7 @@ public async Task<int> AddPackageAsync(FileInfo projectFilePath, string packageN
705
714
return result ;
706
715
}
707
716
708
- public async Task < ( int ExitCode , NuGetPackage [ ] ? Packages ) > SearchPackagesAsync ( DirectoryInfo workingDirectory , string query , bool prerelease , int take , int skip , string ? nugetSource , DotNetCliRunnerInvocationOptions options , CancellationToken cancellationToken )
717
+ public async Task < ( int ExitCode , NuGetPackage [ ] ? Packages ) > SearchPackagesAsync ( DirectoryInfo workingDirectory , string query , bool prerelease , int take , int skip , FileInfo ? nugetConfigFile , DotNetCliRunnerInvocationOptions options , CancellationToken cancellationToken )
709
718
{
710
719
using var activity = telemetry . ActivitySource . StartActivity ( ) ;
711
720
List < string > cliArgs = [
@@ -720,10 +729,10 @@ public async Task<int> AddPackageAsync(FileInfo projectFilePath, string packageN
720
729
"json"
721
730
] ;
722
731
723
- if ( nugetSource is not null )
732
+ if ( nugetConfigFile is not null )
724
733
{
725
- cliArgs . Add ( "--source " ) ;
726
- cliArgs . Add ( nugetSource ) ;
734
+ cliArgs . Add ( "--configfile " ) ;
735
+ cliArgs . Add ( nugetConfigFile . FullName ) ;
727
736
}
728
737
729
738
if ( prerelease )
0 commit comments