Skip to content

Commit 7bbde71

Browse files
TrymBeastgep13
authored andcommitted
(#2028) Add support for NuGet Credentials Providers
1 parent f20ad25 commit 7bbde71

File tree

5 files changed

+26
-10
lines changed

5 files changed

+26
-10
lines changed

src/Cake.NuGet/Cake.NuGet.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
</ItemGroup>
1919
<!-- Global packages -->
2020
<ItemGroup>
21+
<PackageReference Include="NuGet.Credentials"/>
2122
<PackageReference Include="NuGet.Frameworks"/>
2223
<PackageReference Include="NuGet.Versioning" />
2324
<PackageReference Include="NuGet.Protocol" />

src/Cake.NuGet/Client/NuGetLogger.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,23 +50,23 @@ public NuGetLogger(ICakeLog log)
5050
_log = log ?? throw new ArgumentNullException(nameof(log));
5151
}
5252

53-
public void LogDebug(string data) => _log.Debug(data);
53+
public void LogDebug(string data) => _log.Debug("{0}", data);
5454

55-
public void LogVerbose(string data) => _log.Debug(data);
55+
public void LogVerbose(string data) => _log.Debug("{0}", data);
5656

57-
public void LogInformation(string data) => _log.Debug(data);
57+
public void LogInformation(string data) => _log.Debug("{0}", data);
5858

59-
public void LogMinimal(string data) => _log.Information(data);
59+
public void LogMinimal(string data) => _log.Information("{0}", data);
6060

61-
public void LogWarning(string data) => _log.Warning(data);
61+
public void LogWarning(string data) => _log.Warning("{0}", data);
6262

63-
public void LogError(string data) => _log.Error(data);
63+
public void LogError(string data) => _log.Error("{0}", data);
6464

65-
public void LogInformationSummary(string data) => _log.Information(data);
65+
public void LogInformationSummary(string data) => _log.Information("{0}", data);
6666

67-
public void LogErrorSummary(string data) => _log.Error(data);
67+
public void LogErrorSummary(string data) => _log.Error("{0}", data);
6868

69-
public void Log(LogLevel level, string data) => _log.Write(GetVerbosity(level), GetLogLevel(level), data);
69+
public void Log(LogLevel level, string data) => _log.Write(GetVerbosity(level), GetLogLevel(level), "{0}", data);
7070

7171
public Task LogAsync(LogLevel level, string data)
7272
{

src/Cake.NuGet/Constants.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ public static class NuGet
2727
/// The config key name for overriding the default NuGet config file.
2828
/// </summary>
2929
public const string ConfigFile = "NuGet_ConfigFile";
30+
31+
/// <summary>
32+
/// The config key name for non-interactive mode.
33+
/// </summary>
34+
public const string NonInteractive = "NuGet_NonInteractive";
3035
}
3136

3237
public static class Paths

src/Cake.NuGet/Installers/InProcessInstaller.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using Cake.Core.IO;
1313
using NuGet.Common;
1414
using NuGet.Configuration;
15+
using NuGet.Credentials;
1516
using NuGet.Frameworks;
1617
using NuGet.Packaging;
1718
using NuGet.Packaging.Core;
@@ -114,6 +115,14 @@ public IReadOnlyCollection<IFile> Install(PackageReference package, PackageType
114115
allRepositories.AddRange(localAndPrimaryRepositories);
115116
allRepositories.AddRange(sourceRepositoryProvider.Repositories);
116117

118+
var nonInteractiveString = _config.GetValue(Constants.NuGet.NonInteractive) ?? bool.TrueString;
119+
if (!bool.TryParse(nonInteractiveString, out bool nonInteractive))
120+
{
121+
// If there is no explicit preference, use non interactive.
122+
nonInteractive = true;
123+
}
124+
DefaultCredentialServiceUtility.SetupDefaultCredentialService(_nugetLogger, nonInteractive);
125+
117126
var packageIdentity = GetPackageId(package, localAndPrimaryRepositories, targetFramework, _sourceCacheContext, _nugetLogger);
118127
if (packageIdentity == null)
119128
{

src/Directory.Packages.props

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<PackageVersion Include="NSubstitute" Version="5.3.0" />
2222
<PackageVersion Include="NuGet.Common" Version="6.14.0" />
2323
<PackageVersion Include="NuGet.Frameworks" Version="6.14.0" />
24+
<PackageVersion Include="NuGet.Credentials" Version="6.14.0" />
2425
<PackageVersion Include="NuGet.Packaging" Version="6.14.0" />
2526
<PackageVersion Include="NuGet.Protocol" Version="6.14.0" />
2627
<PackageVersion Include="NuGet.Resolver" Version="6.14.0" />
@@ -56,4 +57,4 @@
5657
<PackageVersion Include="System.Security.Cryptography.Pkcs" Version="8.0.1" />
5758
</ItemGroup>
5859

59-
</Project>
60+
</Project>

0 commit comments

Comments
 (0)