Skip to content

Commit

Permalink
Use dotnet tool list to check package installation status
Browse files Browse the repository at this point in the history
  • Loading branch information
Noggog committed Dec 27, 2024
1 parent 7c707af commit 6637d42
Showing 1 changed file with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,43 @@ public ConstructDotNetToolEndpoint(
_tempSourcesProvider = tempSourcesProvider;
}

private async Task<bool> IsToolInstalled(
PackageIdentity ident,
DirectoryPath toolsPath,
CancellationToken cancellationToken)
{
var args = $"tool list {ident.Id} --tool-path \"{toolsPath}\"";
var ret = _processFactory.Create(
new ProcessStartInfo("dotnet")
{
Arguments = args,
},
cancel: cancellationToken,
killWithParent: false);
bool found = false;
using var outputSub = ret.Output
.Subscribe(x =>
{
if (found) return;
var split = x.Split(" ");
if (split.Length != 3) return;
if (split[0].Equals(ident.Id, StringComparison.OrdinalIgnoreCase) && split[1] == ident.Version.ToString())
{
found = true;
}
});
await ret.Run();
return found;
}

public async Task<DotNetToolEntryPoint?> ConstructFor(
DirectoryPath tempPath,
PackageIdentity ident,
CancellationToken cancellationToken)
{
DirectoryPath toolsPath = _pathProvider.Path(tempPath, ident);

if (!toolsPath.CheckExists())
if (!await IsToolInstalled(ident, toolsPath, cancellationToken))
{
try
{
Expand Down

0 comments on commit 6637d42

Please sign in to comment.