-
Notifications
You must be signed in to change notification settings - Fork 696
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
Warn when http sources are used in packages.config restore operations #4583
Warn when http sources are used in packages.config restore operations #4583
Conversation
Team Review: Add unit tests for the two other code paths where the warning is logged |
f72d714
to
4d9725d
Compare
@NuGet/nuget-client |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're missing packages.config restore in Visual Studio.
I assume you mean PC restore right?
Are you looking in PMC? |
Installation in packages.config is different from installation in PackageReference. We'll have a different issue for installation scenarios. |
I originally thought your branch didn't have my changes, but it seems like now does. How are you testing that the PR scenarios? I'll do some tests on my end, as that's something I expect to work. |
I just tested in VS PMUI and VS PMC with below 2 feeds.
|
My question is more about what version of VS you are testing. Are you using experimental instance etc. |
Try using a legacy package reference project. For SDK based projects, the warnings are added in by the SDK and given that the SDK doesn't know about NU1803 it can't parse it. Root cause explained: NuGet/Home#7126 |
You're right it works for legacy PR warnings are added. Does above apply for package PMUI install of packages.config projects too? |
What does above mean? |
@NuGet/nuget-client |
When you say you |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks pretty good overall.
test/NuGet.Clients.FuncTests/NuGet.CommandLine.FuncTest/Commands/InstallCommandTests.cs
Outdated
Show resolved
Hide resolved
test/NuGet.Clients.FuncTests/NuGet.CommandLine.FuncTest/Commands/RestoreCommandTests.cs
Outdated
Show resolved
Hide resolved
test/NuGet.Core.FuncTests/Msbuild.Integration.Test/MsbuildRestoreTaskTests.cs
Outdated
Show resolved
Hide resolved
test/NuGet.Clients.FuncTests/NuGet.CommandLine.FuncTest/Commands/RestoreCommandTests.cs
Show resolved
Hide resolved
test/NuGet.Clients.FuncTests/NuGet.CommandLine.FuncTest/Commands/InstallCommandTests.cs
Show resolved
Hide resolved
@@ -377,6 +378,22 @@ private NuGetPackageManager GetNuGetPackageManager(string solutionDirectory) | |||
|
|||
packageRestoreContext.Token.ThrowIfCancellationRequested(); | |||
|
|||
IEnumerable<SourceRepository> enabledSources = | |||
packageRestoreContext |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
packageRestoreContext has the SourceRepositories. Can we use those?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can use packageRestoreContext.SourceRepositories
because the collection is populated with sources that are enabled.
NuGet.Client/src/NuGet.Core/NuGet.Protocol/CachingSourceProvider.cs
Lines 33 to 36 in aca9465
_repositories = _packageSourceProvider.LoadPackageSources() | |
.Where(s => s.IsEnabled) | |
.Select(CreateRepository) | |
.ToList(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to add back this change, because some code paths sourceRepositories
is set explicitly null so we can't use packageRestoreContext.SourceRepositories
that case.
NuGet.Client/src/NuGet.Core/NuGet.PackageManagement/IDE/PackageRestoreManager.cs
Line 312 in f52a839
sourceRepositories: null, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd really love it if we can avoid adding any public methods in NuGetPackageManager.
I tried to follow RestorePackageAsync into NuGetPackageManager and it uses the ISourceRepositoryProvider to get the providers if they are not set on the context.
Maybe we can just set them?
@nkolev92 @kartheekp-ms |
cd707e8
to
25a1ec4
Compare
PackageSource source = enabledSource.PackageSource; | ||
if (source.IsHttp && !source.IsHttps) | ||
{ | ||
packageRestoreContext.Logger.Log(LogLevel.Warning, string.Format(CultureInfo.CurrentCulture, Strings.Warning_HttpServerUsage, "restore", source.Source)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to add log code to the warning. Similar to PR restore logic.
NuGet.Client/src/NuGet.Core/NuGet.Commands/RestoreCommand/RestoreCommand.cs
Lines 223 to 224 in f52a839
await _logger.LogAsync(RestoreLogMessage.CreateWarning(NuGetLogCode.NU1803, | |
string.Format(CultureInfo.CurrentCulture, Strings.Warning_HttpServerUsage, "restore", source.Source))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
log codes only work in PackageReference.
For consistency we try not to add the log codes in packages.config as none of the resolver warnings/errors have any codes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistency we try not to add the log codes in packages.config as none of the resolver warnings/errors have any codes.
I don't understand this. With a log code, the customer has something to search for (or in VS, something to click in the Error List window), and then there can be a docs page where we can provide more detailed instructions on how to resolve the error.
Why is consistency with not using log codes matter more than this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can't suppress warnings or elevate warnings in packages.config. Log codes usually suggest that you can do that.
Also warnings/errors in packages.config and PackageReference are different because pc restore rarely puts any log messages there.
I think the message itself should be actionable enough.
e86a84c
to
fe739a9
Compare
Bug
Fixes: https://github.com/NuGet/Client.Engineering/issues/1519
Regression? Last working version:
Description
Pretty straightforward. Contains the same warning as #4552, but obviously with a code since it's restore.
PR Checklist
PR has a meaningful title
PR has a linked issue.
Described changes
Tests
Documentation