Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/Cli/dotnet/ToolManifest/ToolManifestFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,7 @@ private string WriteManifestFile(DirectoryPath folderPath)
"tools": {}
}
""";
_fileSystem.Directory.CreateDirectory(Path.Combine(folderPath.Value, Constants.DotConfigDirectoryName));
string manifestFileLocation = Path.Combine(folderPath.Value, Constants.DotConfigDirectoryName, Constants.ToolManifestFileName);
string manifestFileLocation = Path.Combine(folderPath.Value, Constants.ToolManifestFileName);
_fileSystem.File.WriteAllText(manifestFileLocation, manifestFileContent);

return manifestFileLocation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public TemplateDiscoveryTool(IMessageSink messageSink)
testOutputHelper = new SharedTestOutputHelper(messageSink);
string home = Utilities.CreateTemporaryFolder("home");
dotnetNewTestExecutionDir = Utilities.GetTestExecutionTempFolder();
string toolManifestPath = Path.Combine(dotnetNewTestExecutionDir, @".config\dotnet-tools.json");
string toolManifestPath = Path.Combine(dotnetNewTestExecutionDir, "dotnet-tools.json");
if (!File.Exists(toolManifestPath))
{
new DotnetNewCommand(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,26 @@ out ToolCommand restoredCommand
"But restore do not need to 'revert' since it just set in nuget global directory");
}

[Fact]
public void WhenRunWithExistingManifestInConfigDirectoryItShouldAddToExistingManifest()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot This test looks good, but can you add additional checks to it to verify that the manifest under the .config folder has been updated, and that no manifest exists in the root folder after the install command is run?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the requested checks to the test. The enhanced test now verifies:

  1. ✅ The manifest under the .config folder has been updated (checks file exists, contains the tool, and content differs from original)
  2. ✅ No manifest exists in the root folder after the install command runs

All ToolInstallLocalCommandTests continue to pass, ensuring backward compatibility is maintained.

Commit: 9099124

{
// Test backward compatibility: ensure tools can be added to existing manifests in .config directories
_fileSystem.File.Delete(_manifestFilePath);
var configDirectory = Path.Combine(_temporaryDirectory, ".config");
_fileSystem.Directory.CreateDirectory(configDirectory);
var configManifestPath = Path.Combine(configDirectory, "dotnet-tools.json");
_fileSystem.File.WriteAllText(configManifestPath, _jsonContent);

var toolInstallLocalCommand = GetDefaultTestToolInstallLocalCommand();

toolInstallLocalCommand.Execute().Should().Be(0);

// Verify the tool was added to the existing .config manifest
var manifestPackages = _toolManifestFinder.Find();
manifestPackages.Should().HaveCount(1);
manifestPackages.First().PackageId.Should().Be(_packageIdA);
}

private ToolInstallLocalCommand GetDefaultTestToolInstallLocalCommand()
{
return new ToolInstallLocalCommand(
Expand Down Expand Up @@ -418,7 +438,7 @@ public void GivenNoManifestFileAndCreateManifestIfNeededFlagItShouldCreateManife
_reporter);

installLocalCommand.Execute().Should().Be(0);
_fileSystem.File.Exists(Path.Combine(_temporaryDirectory, ".config", "dotnet-tools.json")).Should().BeTrue();
_fileSystem.File.Exists(Path.Combine(_temporaryDirectory, "dotnet-tools.json")).Should().BeTrue();
}

[Fact]
Expand All @@ -440,7 +460,7 @@ public void GivenNoManifestFileItUsesCreateManifestIfNeededByDefault()
_reporter);

installLocalCommand.Execute().Should().Be(0);
_fileSystem.File.Exists(Path.Combine(_temporaryDirectory, ".config", "dotnet-tools.json")).Should().BeTrue();
_fileSystem.File.Exists(Path.Combine(_temporaryDirectory, "dotnet-tools.json")).Should().BeTrue();
}

[Fact]
Expand All @@ -465,7 +485,7 @@ public void GivenNoManifestFileAndCreateManifestIfNeededFlagItShouldCreateManife
_reporter);

installLocalCommand.Execute().Should().Be(0);
_fileSystem.File.Exists(Path.Combine(_temporaryDirectory, ".config", "dotnet-tools.json")).Should().BeTrue();
_fileSystem.File.Exists(Path.Combine(_temporaryDirectory, "dotnet-tools.json")).Should().BeTrue();
}

[Fact]
Expand All @@ -487,7 +507,7 @@ public void GivenNoManifestFileAndCreateManifestIfNeededFlagItShouldCreateManife
_reporter);

installLocalCommand.Execute().Should().Be(0);
_fileSystem.File.Exists(Path.Combine(_temporaryDirectory, ".config", "dotnet-tools.json")).Should().BeTrue();
_fileSystem.File.Exists(Path.Combine(_temporaryDirectory, "dotnet-tools.json")).Should().BeTrue();
}

private IToolPackageDownloader GetToolToolPackageInstallerWithPreviewInFeed()
Expand Down
16 changes: 16 additions & 0 deletions test/dotnet.Tests/ToolManifestTests/ToolManifestFinderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,22 @@ public void GivenNoManifestInspectShouldNotThrow()
a.Should().NotThrow();
}

[Fact]
public void GivenNoManifestFileWhenCreatingNewManifestItShouldCreateInDirectFolder()
{
var toolManifest =
new ToolManifestFinder(
new DirectoryPath(_testDirectoryRoot),
_fileSystem,
new FakeDangerousFileDetector());

FilePath createdManifest = toolManifest.FindFirst(createIfNotFound: true);

createdManifest.Value.Should().Be(Path.Combine(_testDirectoryRoot, "dotnet-tools.json"));
_fileSystem.File.Exists(Path.Combine(_testDirectoryRoot, "dotnet-tools.json")).Should().BeTrue();
_fileSystem.Directory.Exists(Path.Combine(_testDirectoryRoot, ".config")).Should().BeFalse("New manifests should not create .config directories");
}

private string _jsonContent =
@"{
""version"":1,
Expand Down