Skip to content
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

Merged
merged 7 commits into from
May 11, 2022

Conversation

erdembayar
Copy link
Contributor

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

    • Automated tests added
    • OR
    • Test exception
    • OR
    • N/A
  • Documentation

    • Documentation PR or issue filled
    • OR
    • N/A

@erdembayar erdembayar requested a review from a team as a code owner April 19, 2022 01:21
@jeffkl
Copy link
Contributor

jeffkl commented Apr 19, 2022

Team Review: Add unit tests for the two other code paths where the warning is logged

@erdembayar erdembayar force-pushed the dev-eryondon-warn-httpconnection-packagesconfigprojects branch from f72d714 to 4d9725d Compare April 21, 2022 00:25
@erdembayar
Copy link
Contributor Author

Team Review: Add unit tests for the two other code paths where the warning is logged

@NuGet/nuget-client
I added tests for 2 other code paths.

Copy link
Member

@nkolev92 nkolev92 left a 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.

@erdembayar
Copy link
Contributor Author

erdembayar commented Apr 23, 2022

You're missing packages.config restore in Visual Studio.

I just tested PR restore in Visual Studio and I don't see any warning in "Package Manager console".
It seems restore logging in Visual Studio has a bug.
When I'm debugging packages.config restore in VS, I can see it's logging something but nothing in "Package Manager console".
image
I can file separate bug for this. Does it sound fair?

@nkolev92
Copy link
Member

I just tested PR restore in Visual Studio and I don't see any warning in "Package Manager console".

I assume you mean PC restore right?

When I'm debugging packages.config restore in VS, I can see it's logging something but nothing in "Package Manager console".

Are you looking in PMC?
We have an output window titled Package Manager, check there.

@erdembayar
Copy link
Contributor Author

erdembayar commented Apr 25, 2022

I just tested PR restore in Visual Studio and I don't see any warning in "Package Manager console".

I assume you mean PC restore right?

When I'm debugging packages.config restore in VS, I can see it's logging something but nothing in "Package Manager console".

Are you looking in PMC? We have an output window titled Package Manager, check there.

Sorry for naming confusion let me clear it for you.

1. PMUI scenario
I tested both PC and PR with PMUI install scenario, both cases I don't see any warning in Output >> PackageManager, I suspect there is a logging bug here. Would you like me file bug for it?
PR:
image

PC:
image

2. PMC scenario
Then I tested both PC and PR in PMC window

PR: I can see asset file include text2xml entry, that means restore did happen.
image

PC:
image

By the way I did clean up cache between repro cycles and I used below 2 sources for tests:
image

@nkolev92
Copy link
Member

nkolev92 commented Apr 25, 2022

Installation in packages.config is different from installation in PackageReference.
We discussed shortly in one of the teams channels, it's all restore in PackageReference. In packages.config, they are different gestures.

We'll have a different issue for installation scenarios.

@nkolev92
Copy link
Member

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.

@erdembayar
Copy link
Contributor Author

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.

    <add key="nuget" value="http://api.nuget.org/v3/index.json" />
    <add key="myinsecure" value="http://nuget.org/api/v2" />

@nkolev92
Copy link
Member

My question is more about what version of VS you are testing. Are you using experimental instance etc.

@erdembayar
Copy link
Contributor Author

My question is more about what version of VS you are testing. Are you using experimental instance etc.

Yes, it's experimental instance for VS 17.2 Preview 4.
image

@nkolev92
Copy link
Member

@erdembayar

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

@erdembayar
Copy link
Contributor Author

erdembayar commented Apr 26, 2022

@erdembayar

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.
image
image

Does above apply for package PMUI install of packages.config projects too?

@nkolev92
Copy link
Member

Does above apply for package PMUI install of packages.config projects too

What does above mean?

@erdembayar
Copy link
Contributor Author

Does above apply for package PMUI install of packages.config projects too

What does above mean?

Install package to PC project via PMUI, I don't see any warning, but it's not sdk based so just wandering why:
image

@erdembayar
Copy link
Contributor Author

erdembayar commented Apr 26, 2022

Does above apply for package PMUI install of packages.config projects too

What does above mean?

Install package to PC project via PMUI, I don't see any warning, but it's not sdk based so just wandering why: ![image]

Never mind, I was using wrong logger, I changed it. Now both PMC and PMUI warnings are working.
image

image

It's ready to review.

@erdembayar
Copy link
Contributor Author

@NuGet/nuget-client
It's ready to review.

@nkolev92
Copy link
Member

When you say you PMC and PMUI warnings work, can you clarify what commands you are running there?

Copy link
Member

@nkolev92 nkolev92 left a 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.

@@ -377,6 +378,22 @@ private NuGetPackageManager GetNuGetPackageManager(string solutionDirectory)

packageRestoreContext.Token.ThrowIfCancellationRequested();

IEnumerable<SourceRepository> enabledSources =
packageRestoreContext
Copy link
Member

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?

Copy link
Contributor

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.

_repositories = _packageSourceProvider.LoadPackageSources()
.Where(s => s.IsEnabled)
.Select(CreateRepository)
.ToList();

Copy link
Contributor Author

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.

Copy link
Member

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?

@erdembayar
Copy link
Contributor Author

@nkolev92 @kartheekp-ms
I addressed PR comments.

nkolev92
nkolev92 previously approved these changes May 2, 2022
@erdembayar erdembayar force-pushed the dev-eryondon-warn-httpconnection-packagesconfigprojects branch 2 times, most recently from cd707e8 to 25a1ec4 Compare May 4, 2022 21:08
jeffkl
jeffkl previously approved these changes May 5, 2022
PackageSource source = enabledSource.PackageSource;
if (source.IsHttp && !source.IsHttps)
{
packageRestoreContext.Logger.Log(LogLevel.Warning, string.Format(CultureInfo.CurrentCulture, Strings.Warning_HttpServerUsage, "restore", source.Source));
Copy link
Contributor

@kartheekp-ms kartheekp-ms May 6, 2022

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.

await _logger.LogAsync(RestoreLogMessage.CreateWarning(NuGetLogCode.NU1803,
string.Format(CultureInfo.CurrentCulture, Strings.Warning_HttpServerUsage, "restore", source.Source)));

Copy link
Member

@nkolev92 nkolev92 May 6, 2022

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.

Copy link
Member

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?

Copy link
Member

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.

nkolev92
nkolev92 previously approved these changes May 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants