Skip to content

Commit daa6c75

Browse files
authored
Universal Packages: Fix cred provider path (#622)
1 parent ef4b397 commit daa6c75

File tree

1 file changed

+25
-15
lines changed

1 file changed

+25
-15
lines changed

src/UniversalPackages/DownloadUniversalPackages.cs

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ public sealed class DownloadUniversalPackages : Task
3232
{
3333
private const string PackageItemName = "UniversalPackage";
3434

35-
private const string CredentialProviderRelativePath = @"plugins\netcore\CredentialProvider.Microsoft\CredentialProvider.Microsoft.exe";
36-
3735
private const string PatVarNameBase = "ArtifactToolPat_";
3836

3937
/// <summary>
@@ -567,18 +565,33 @@ private string GetArtifactToolReleaseInfoUrl(string osName, string arch)
567565

568566
private string? GetArtifactsCredentialProviderPath()
569567
{
570-
string credentialProviderDir;
568+
string exeName = RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
569+
? "CredentialProvider.Microsoft.exe"
570+
: "CredentialProvider.Microsoft";
571571
if (!string.IsNullOrWhiteSpace(ArtifactsCredentialProviderPath))
572572
{
573-
// Allow the user to specify either the exe or the root dir
573+
// Allow the user to specify either the exe, a dir with the exe, or the root dir
574574
if (File.Exists(ArtifactsCredentialProviderPath))
575575
{
576576
return ArtifactsCredentialProviderPath;
577577
}
578578

579579
if (Directory.Exists(ArtifactsCredentialProviderPath))
580580
{
581-
return GetArtifactsCredentialProviderExePath(ArtifactsCredentialProviderPath!);
581+
string possibleExePath = Path.Combine(ArtifactsCredentialProviderPath, exeName);
582+
if (File.Exists(possibleExePath))
583+
{
584+
return possibleExePath;
585+
}
586+
587+
possibleExePath = GetArtifactsCredentialProviderExePath(ArtifactsCredentialProviderPath!);
588+
if (File.Exists(possibleExePath))
589+
{
590+
return possibleExePath;
591+
}
592+
593+
Log.LogError($"Credential provider was not found under '{ArtifactsCredentialProviderPath}'.");
594+
return null;
582595
}
583596

584597
Log.LogError($"Credential provider path '{ArtifactsCredentialProviderPath}' does not exist.");
@@ -592,7 +605,7 @@ private string GetArtifactToolReleaseInfoUrl(string osName, string arch)
592605
return null;
593606
}
594607

595-
credentialProviderDir = Path.Combine(ArtifactToolBasePath, "credential-provider", releaseInfo.Value.Version, "plugins", "netcore", "CredentialProvider.Microsoft");
608+
string credentialProviderDir = Path.Combine(ArtifactToolBasePath, "credential-provider", releaseInfo.Value.Version);
596609

597610
// Download only if needed
598611
if (!Directory.Exists(credentialProviderDir))
@@ -604,20 +617,17 @@ private string GetArtifactToolReleaseInfoUrl(string osName, string arch)
604617
}
605618
}
606619

607-
return GetArtifactsCredentialProviderExePath(credentialProviderDir);
608-
}
609-
610-
string? GetArtifactsCredentialProviderExePath(string dir)
611-
{
612-
string credentialProviderExePath = Path.Combine(dir, CredentialProviderRelativePath);
613-
if (File.Exists(credentialProviderExePath))
620+
string exePath = GetArtifactsCredentialProviderExePath(credentialProviderDir);
621+
if (File.Exists(exePath))
614622
{
615-
return credentialProviderExePath;
623+
return exePath;
616624
}
617625

618-
Log.LogError($"Credential provider path '{CredentialProviderRelativePath}' was not found under '{dir}'.");
626+
Log.LogError($"Credential provider path '{exePath}' was not found.");
619627
return null;
620628
}
629+
630+
string GetArtifactsCredentialProviderExePath(string dir) => Path.Combine(dir, "plugins", "netcore", "CredentialProvider.Microsoft", exeName);
621631
}
622632

623633
private (string Version, string DownloadUri)? GetArtifactsCredentialProviderReleaseInfo()

0 commit comments

Comments
 (0)