Skip to content

Commit ebbdab5

Browse files
authored
Don't create tool manifests in a .config subfolder by default (#50242)
2 parents 9b98cf5 + 8ad435c commit ebbdab5

File tree

6 files changed

+51
-7
lines changed

6 files changed

+51
-7
lines changed

src/Cli/dotnet/ToolManifest/ToolManifestFinder.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,7 @@ private string WriteManifestFile(DirectoryPath folderPath)
250250
"tools": {}
251251
}
252252
""";
253-
_fileSystem.Directory.CreateDirectory(Path.Combine(folderPath.Value, Constants.DotConfigDirectoryName));
254-
string manifestFileLocation = Path.Combine(folderPath.Value, Constants.DotConfigDirectoryName, Constants.ToolManifestFileName);
253+
string manifestFileLocation = Path.Combine(folderPath.Value, Constants.ToolManifestFileName);
255254
_fileSystem.File.WriteAllText(manifestFileLocation, manifestFileContent);
256255

257256
return manifestFileLocation;
File renamed without changes.

test/dotnet-new.IntegrationTests/TemplateDiscoveryTool.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public TemplateDiscoveryTool(IMessageSink messageSink)
1515
testOutputHelper = new SharedTestOutputHelper(messageSink);
1616
string home = Utilities.CreateTemporaryFolder("home");
1717
dotnetNewTestExecutionDir = Utilities.GetTestExecutionTempFolder();
18-
string toolManifestPath = Path.Combine(dotnetNewTestExecutionDir, @".config\dotnet-tools.json");
18+
string toolManifestPath = Path.Combine(dotnetNewTestExecutionDir, "dotnet-tools.json");
1919
if (!File.Exists(toolManifestPath))
2020
{
2121
new DotnetNewCommand(

test/dotnet.Tests/CommandTests/Tool/Install/ToolInstallLocalCommandTests.cs

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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()

test/dotnet.Tests/ToolManifestTests/ToolManifestFinderTests.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,22 @@ public void GivenNoManifestInspectShouldNotThrow()
764764
a.Should().NotThrow();
765765
}
766766

767+
[Fact]
768+
public void GivenNoManifestFileWhenCreatingNewManifestItShouldCreateInDirectFolder()
769+
{
770+
var toolManifest =
771+
new ToolManifestFinder(
772+
new DirectoryPath(_testDirectoryRoot),
773+
_fileSystem,
774+
new FakeDangerousFileDetector());
775+
776+
FilePath createdManifest = toolManifest.FindFirst(createIfNotFound: true);
777+
778+
createdManifest.Value.Should().Be(Path.Combine(_testDirectoryRoot, "dotnet-tools.json"));
779+
_fileSystem.File.Exists(Path.Combine(_testDirectoryRoot, "dotnet-tools.json")).Should().BeTrue();
780+
_fileSystem.Directory.Exists(Path.Combine(_testDirectoryRoot, ".config")).Should().BeFalse("New manifests should not create .config directories");
781+
}
782+
767783
private string _jsonContent =
768784
@"{
769785
""version"":1,

0 commit comments

Comments
 (0)