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

Move NuGet API usage to its own extension #824

Merged
merged 2 commits into from
Aug 26, 2021
Merged

Conversation

twsouthwick
Copy link
Member

NuGet API may not be stable and loading an arbitrary version with MSBuild may cause problems. This change isolates those calls so we can pin it to our own version.

This change does a couple of things:

  • Moves all NuGet usages to extension. This will now load in its own AssemblyLoadContext so we won't have any conflicts
  • Updates to the latest NuGet client API libraries
  • Adds a 'required' extension concept so that they will load in all cases even when loading is disabled.

Fixes #817

NuGet API may not be stable and loading an arbitrary version with MSBuild may cause problems. This change isolates those calls so we can pin it to our own version.

This change does a couple of things:

- Moves all NuGet usages to extension. This will now load in its own AssemblyLoadContext so we won't have any conflicts
- Updates to the latest NuGet client API libraries
- Adds a 'required' extension concept so that they will load in all cases even when loading is disabled.

Fixes #817
@twsouthwick twsouthwick marked this pull request as ready for review August 25, 2021 21:03
@twsouthwick twsouthwick requested a review from a team as a code owner August 25, 2021 21:03
@@ -15,6 +15,10 @@
"Extensions": {
"Source": "https://upgradeassistant.blob.core.windows.net/extensions/index.json",

"required": [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this naming feels a little confusing. almost feels like something that is default is required? or maybe we move the default extension under required?

Copy link
Member Author

@twsouthwick twsouthwick Aug 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is "required" because everything will need it. Default extensions are used to augment certain services but not needed everywhere. Long term, it may be good to define extensions on a "per command" usage; ie, identify commands that would only be used in analyze/upgrade/etc

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool!

Copy link
Contributor

@Sweekriti91 Sweekriti91 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apart from the naming comment, rest is good!

Copy link
Member

@mjrousos mjrousos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple questions inline, but looks good overall.

}

var list = new List<ExtensionInstance>();
// Required extensions must load, otherwise they may be turned off
if (!opts.LoadExtensions)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need a LoadExtensions option? I'm not sure it's necessary and if we removed it, this code would simplify a bit as default and required extensions wouldn't have to be distinguished anymore. The only downside I can think of to removing it is that users won't be able to disable any default extensions, but I haven't seen a use case where that would be necessary.

Copy link
Member Author

@twsouthwick twsouthwick Aug 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When managing extensions, it adds extra time that this prevents. The extension management doesn't need all the random extensions people may be adding, but it will need the NuGet one

private readonly Func<IUpgradeContext, IProject, INuGetReferences> _nugetReferenceFactory;
private readonly Func<IProjectFile, ITargetFrameworkCollection> _tfmCollectionFactory;

public Factories(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'm overlooking something here. I'm trying to figure out how this type is instantiated. I see that it's registered as a transient DI service, but I don't see where the Funcs it needs as arguments are registered. Can you help me figure out where the nugetReferenceFactory and tfmCollectionFactory implementations come from?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@twsouthwick twsouthwick merged commit ed3bdb6 into main Aug 26, 2021
@twsouthwick twsouthwick deleted the tasou/nuget-hosted branch August 26, 2021 15:22
{
if (upgradeOptions.Project?.FullName is string fullname)
{
optionss.PackageSourcePath = Path.GetDirectoryName(fullname);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the setting of PackageSourcePath got lost in this PR. It would explain why changing package sources in nuget.config doesn't work anymore.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got the same issue, 0.4.421302 will not follow my nuget.config but 0.2.241603 (a version that is before the above PR) will follow my nuget.config.

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.

NuGet API throws MethodNotFound on some versions of .NET SDK
5 participants