Skip to content

dotnet tool install --local works by default, by creating a manifest by default, utilizing --create-manifest-if-needed #48906

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ internal static class ToolInstallCommandParser
public static readonly Option<bool> CreateManifestIfNeededOption = new("--create-manifest-if-needed")
{
Description = CliCommandStrings.CreateManifestIfNeededOptionDescription,
Arity = ArgumentArity.Zero
Arity = ArgumentArity.ZeroOrOne,
DefaultValueFactory = _ => true,
};

public static readonly Option<bool> AllowPackageDowngradeOption = new("--allow-downgrade")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,22 +128,41 @@ public void WhenRunWithPackageIdItShouldSaveToCacheAndAddToManifestFile()
}

[Fact]
public void GivenNoManifestFileItShouldThrow()
public void GivenCreateManifestIfNeededWithoutArgumentTheDefaultIsTrueForLegacyBehavior()
{
_fileSystem.File.Delete(_manifestFilePath);
var toolInstallLocalCommand = GetDefaultTestToolInstallLocalCommand();
ParseResult parseResult =
Parser.Instance.Parse(
$"dotnet tool install {_packageIdA.ToString()} --create-manifest-if-needed");

Action a = () => toolInstallLocalCommand.Execute();
a.Should().Throw<GracefulException>()
.And.Message.Should()
.Contain(CliStrings.CannotFindAManifestFile);
var toolInstallLocalCommand = new ToolInstallLocalCommand(
parseResult,
_packageIdA,
_toolPackageDownloaderMock,
_toolManifestFinder,
_toolManifestEditor,
_localToolsResolverCache,
_reporter);

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

[Fact]
public void GivenNoManifestFileItShouldThrowAndContainNoManifestGuide()
{
_fileSystem.File.Delete(_manifestFilePath);
var toolInstallLocalCommand = GetDefaultTestToolInstallLocalCommand();
ParseResult parseResult =
Parser.Instance.Parse(
$"dotnet tool install {_packageIdA.ToString()} --create-manifest-if-needed false");

var toolInstallLocalCommand = new ToolInstallLocalCommand(
parseResult,
_packageIdA,
_toolPackageDownloaderMock,
_toolManifestFinder,
_toolManifestEditor,
_localToolsResolverCache,
_reporter);

Action a = () => toolInstallLocalCommand.Execute();
a.Should().Throw<GracefulException>()
Expand Down Expand Up @@ -408,6 +427,28 @@ public void GivenNoManifestFileAndCreateManifestIfNeededFlagItShouldCreateManife
_fileSystem.File.Exists(Path.Combine(_temporaryDirectory, ".config", "dotnet-tools.json")).Should().BeTrue();
}

[Fact]
public void GivenNoManifestFileItUsesCreateManifestIfNeededByDefault()
{
_fileSystem.File.Delete(_manifestFilePath);

ParseResult parseResult =
Parser.Instance.Parse(
$"dotnet tool install {_packageIdA.ToString()}");

var installLocalCommand = new ToolInstallLocalCommand(
parseResult,
_packageIdA,
_toolPackageDownloaderMock,
_toolManifestFinder,
_toolManifestEditor,
_localToolsResolverCache,
_reporter);

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

[Fact]
public void GivenNoManifestFileAndCreateManifestIfNeededFlagItShouldCreateManifestInSln()
{
Expand Down
Loading