@@ -315,6 +315,35 @@ out ToolCommand restoredCommand
315315 "But restore do not need to 'revert' since it just set in nuget global directory" ) ;
316316 }
317317
318+ [ Fact ]
319+ public void WhenRunWithExistingManifestInConfigDirectoryItShouldAddToExistingManifest ( )
320+ {
321+ // Test backward compatibility: ensure tools can be added to existing manifests in .config directories
322+ _fileSystem . File . Delete ( _manifestFilePath ) ;
323+ var configDirectory = Path . Combine ( _temporaryDirectory , ".config" ) ;
324+ _fileSystem . Directory . CreateDirectory ( configDirectory ) ;
325+ var configManifestPath = Path . Combine ( configDirectory , "dotnet-tools.json" ) ;
326+ _fileSystem . File . WriteAllText ( configManifestPath , _jsonContent ) ;
327+
328+ var toolInstallLocalCommand = GetDefaultTestToolInstallLocalCommand ( ) ;
329+
330+ toolInstallLocalCommand . Execute ( ) . Should ( ) . Be ( 0 ) ;
331+
332+ // Verify the tool was added to the existing .config manifest
333+ var manifestPackages = _toolManifestFinder . Find ( ) ;
334+ manifestPackages . Should ( ) . HaveCount ( 1 ) ;
335+ manifestPackages . First ( ) . PackageId . Should ( ) . Be ( _packageIdA ) ;
336+
337+ // Verify that the manifest under the .config folder has been updated
338+ _fileSystem . File . Exists ( configManifestPath ) . Should ( ) . BeTrue ( "The .config manifest file should exist" ) ;
339+ var configManifestContent = _fileSystem . File . ReadAllText ( configManifestPath ) ;
340+ configManifestContent . Should ( ) . Contain ( _packageIdA . ToString ( ) , "The .config manifest should contain the installed tool" ) ;
341+ configManifestContent . Should ( ) . NotBe ( _jsonContent , "The .config manifest should have been updated with the new tool" ) ;
342+
343+ // Verify that no manifest exists in the root folder after the install command is run
344+ _fileSystem . File . Exists ( _manifestFilePath ) . Should ( ) . BeFalse ( "No manifest should exist in the root folder" ) ;
345+ }
346+
318347 private ToolInstallLocalCommand GetDefaultTestToolInstallLocalCommand ( )
319348 {
320349 return new ToolInstallLocalCommand (
@@ -418,7 +447,7 @@ public void GivenNoManifestFileAndCreateManifestIfNeededFlagItShouldCreateManife
418447 _reporter ) ;
419448
420449 installLocalCommand . Execute ( ) . Should ( ) . Be ( 0 ) ;
421- _fileSystem . File . Exists ( Path . Combine ( _temporaryDirectory , ".config" , " dotnet-tools.json") ) . Should ( ) . BeTrue ( ) ;
450+ _fileSystem . File . Exists ( Path . Combine ( _temporaryDirectory , "dotnet-tools.json" ) ) . Should ( ) . BeTrue ( ) ;
422451 }
423452
424453 [ Fact ]
@@ -440,7 +469,7 @@ public void GivenNoManifestFileItUsesCreateManifestIfNeededByDefault()
440469 _reporter ) ;
441470
442471 installLocalCommand . Execute ( ) . Should ( ) . Be ( 0 ) ;
443- _fileSystem . File . Exists ( Path . Combine ( _temporaryDirectory , ".config" , " dotnet-tools.json") ) . Should ( ) . BeTrue ( ) ;
472+ _fileSystem . File . Exists ( Path . Combine ( _temporaryDirectory , "dotnet-tools.json" ) ) . Should ( ) . BeTrue ( ) ;
444473 }
445474
446475 [ Fact ]
@@ -465,7 +494,7 @@ public void GivenNoManifestFileAndCreateManifestIfNeededFlagItShouldCreateManife
465494 _reporter ) ;
466495
467496 installLocalCommand . Execute ( ) . Should ( ) . Be ( 0 ) ;
468- _fileSystem . File . Exists ( Path . Combine ( _temporaryDirectory , ".config" , " dotnet-tools.json") ) . Should ( ) . BeTrue ( ) ;
497+ _fileSystem . File . Exists ( Path . Combine ( _temporaryDirectory , "dotnet-tools.json" ) ) . Should ( ) . BeTrue ( ) ;
469498 }
470499
471500 [ Fact ]
@@ -487,7 +516,7 @@ public void GivenNoManifestFileAndCreateManifestIfNeededFlagItShouldCreateManife
487516 _reporter ) ;
488517
489518 installLocalCommand . Execute ( ) . Should ( ) . Be ( 0 ) ;
490- _fileSystem . File . Exists ( Path . Combine ( _temporaryDirectory , ".config" , " dotnet-tools.json") ) . Should ( ) . BeTrue ( ) ;
519+ _fileSystem . File . Exists ( Path . Combine ( _temporaryDirectory , "dotnet-tools.json" ) ) . Should ( ) . BeTrue ( ) ;
491520 }
492521
493522 private IToolPackageDownloader GetToolToolPackageInstallerWithPreviewInFeed ( )
0 commit comments