Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffkl committed Aug 29, 2022
1 parent fa79b74 commit df56320
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions src/NuGet.Core/NuGet.Commands/RestoreCommand/RestoreCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public async Task<RestoreResult> ExecuteAsync(CancellationToken token)
bool isPackageSourceMappingEnabled = _request?.PackageSourceMapping.IsEnabled ?? false;
telemetry.TelemetryEvent[PackageSourceMappingIsMappingEnabled] = isPackageSourceMappingEnabled;
telemetry.TelemetryEvent[SourcesCount] = _request.DependencyProviders.RemoteProviders.Count;
var httpSourcesCount = _request.DependencyProviders.RemoteProviders.Where(e => e.IsHttp).Count();
int httpSourcesCount = _request.DependencyProviders.RemoteProviders.Where(e => e.IsHttp).Count();
telemetry.TelemetryEvent[HttpSourcesCount] = httpSourcesCount;
telemetry.TelemetryEvent[LocalSourcesCount] = _request.DependencyProviders.RemoteProviders.Count - httpSourcesCount;
telemetry.TelemetryEvent[FallbackFoldersCount] = _request.DependencyProviders.FallbackPackageFolders.Count;
Expand Down Expand Up @@ -208,7 +208,7 @@ public async Task<RestoreResult> ExecuteAsync(CancellationToken token)
}
telemetry.TelemetryEvent[NoOpResult] = false; // Getting here means we did not no-op.

if (!await AreCentralVersionRequirementsSatisfiedAsync(_request))
if (!await AreCentralVersionRequirementsSatisfiedAsync(_request, httpSourcesCount))
{
// the errors will be added to the assets file
_success = false;
Expand Down Expand Up @@ -463,7 +463,7 @@ private bool HasValidPlatformVersions()
}
}

private async Task<bool> AreCentralVersionRequirementsSatisfiedAsync(RestoreRequest restoreRequest)
private async Task<bool> AreCentralVersionRequirementsSatisfiedAsync(RestoreRequest restoreRequest, int httpSourcesCount)
{
if (restoreRequest?.Project?.RestoreMetadata == null || !restoreRequest.Project.RestoreMetadata.CentralPackageVersionsEnabled)
{
Expand All @@ -483,16 +483,10 @@ private async Task<bool> AreCentralVersionRequirementsSatisfiedAsync(RestoreRequ
return false;
}

if (!restoreRequest.PackageSourceMapping.IsEnabled)
if (!restoreRequest.PackageSourceMapping.IsEnabled && httpSourcesCount > 0)
{
// Get a list of package sources that are not local folders
List<Configuration.PackageSource> nonLocalPackageSources = restoreRequest.Project.RestoreMetadata.Sources.Where(i => !i.IsLocal).ToList();

// Log a warning if there are more than one configured source and package source mapping is not enabled
if (nonLocalPackageSources.Count > 1)
{
await _logger.LogAsync(RestoreLogMessage.CreateWarning(NuGetLogCode.NU1507, string.Format(CultureInfo.CurrentCulture, Strings.Warning_CentralPackageVersions_MultipleSourcesWithoutPackageSourceMapping, nonLocalPackageSources.Count, string.Join(", ", nonLocalPackageSources.Select(i => i.Name)))));
}
await _logger.LogAsync(RestoreLogMessage.CreateWarning(NuGetLogCode.NU1507, string.Format(CultureInfo.CurrentCulture, Strings.Warning_CentralPackageVersions_MultipleSourcesWithoutPackageSourceMapping, httpSourcesCount, string.Join(", ", restoreRequest.DependencyProviders.RemoteProviders.Where(i => i.IsHttp).Select(i => i.Source.Name)))));
}

// The dependencies should not have versions explicitly defined if cpvm is enabled.
Expand Down

0 comments on commit df56320

Please sign in to comment.