Skip to content

Use "PackageReferences" to determine applicability - #3618

Merged
nkolev92 merged 1 commit into
NuGet:devfrom
davkean:ProjectCapability
Sep 8, 2020
Merged

nkolev92 merged 1 commit into
NuGet:devfrom
davkean:ProjectCapability

Conversation

@davkean

@davkean davkean commented Aug 31, 2020 •

Copy link
Copy Markdown
Contributor

Fixes: NuGet/Home#9957

Fix

Restore uses a variety of things to opt projects into restore operations. One is a list of hardcoded project types "guids", and the other is a set of project capabilities. Across VS we're moved away from hardcoding project types to capabilities as a better way of representing the set of features a given project supports. In the past before "PackageReferences" existed, NuGet used the presence of AssemblyReferences + DeclaredSourceItems + UserSourceItem as indicator that a project supports restore. Since then we've added a new capability; PackageReferences. CPS-based package-related features have been tied behind it, including the code that nominates for restore, and watches the project assets file for changes. This code can be found here: https://github.com/dotnet/project-system/tree/master/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/PackageRestore.

This change lets a custom CPS-based project type, including C++ and MSIX projects to opt into the PackageReferences capability and have end-to-end just work.

Testing/Validation

Tests Added: No
Reason for not adding tests: There is no obvious way to test this in the code base.
Validation:

I've verified that this doesn't break existing restore for existing projects. Only two project types are currently using PackageReferences project capability and both already defined AssemblyReferences + DeclaredSourceItems + UserSourceItem, so this change by itself does not opt anymore projects into restore without corresponding project system changes.
I've verified in a custom project type (based on CPS) that this "lights" up Package Manager support including restore, and package manager. It does not, however, cause the assets file to be written whcih needs investigation. I think we should enable this anyway, as it lets us iterate with MSIX/C++ without needing custom builds of NuGet.

@davkean

davkean commented Aug 31, 2020 •

Copy link
Copy Markdown
Contributor Author

@NuGet/nuget-client What's the trick to building this locally? I've tried following https://github.com/NuGet/NuGet.Client/blob/dev/CONTRIBUTING.md#build and I get the following running Configure:

Microsoft (R) Build Engine version 16.8.0-preview-20414-02+a55ce4fbb for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

C:\nuget.client\build\bootstrap.proj : warning : Unable to load the service index for source https://api.nuget.org/v3/index.json.
C:\nuget.client\build\bootstrap.proj : error : Unable to find package Microsoft.Build.NoTargets. No packages exist with this id in source(s): dotnet-buildtools, dotnet-core, dotnet-msbuild, dotnet-roslyn, NuGet.org, NuGetVolatile, vside, vssdk
[14:06:40 +185] [DONE +00:03:04] Restoring solution packages
WARNING: [14:06:40 +0] [SKIP] Cleaning package cache
[14:06:40 +0]   [BEGIN] Validating VS 16 toolset installation
[14:06:40 +0]   [DONE +00:00:00] Validating VS 16 toolset installation
[14:06:40 +0]   Using MSBUILD version 16.8.0.42105 found at 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\MSBuild\Current\bin\msbuild.exe'
[14:06:40 +0]   Configuration data has been written to 'C:\nuget.client\artifacts\configure.json'

Have no issue hitting that URL locally.

@zivkan zivkan added the Community PRs created by someone not in the NuGet team label Aug 31, 2020
@nkolev92

Copy link
Copy Markdown
Member

@davkean

Normally I'd expect that to work.
That should be running simple msbuild.exe /t:restore. It's likely that the TLS problems are transient and machine specific.

There were some windows bugs with the TLS 1.3 implementation, @zivkan do you recall the problem?

@zivkan

zivkan commented Aug 31, 2020

Copy link
Copy Markdown
Member

dotnet/runtime#40679

I also have a HttpClient test program: https://gist.github.com/zivkan/5291f507c8c5724d41a18357b7afcd30. You'll need to change the csproj to test net5.0 if that's the SDK you have installed and are using for restore.

NuGet just uses HttpClient. We don't change the SslProtocol defaults, so we're dependent on the operating system working (well, NuGet's dependant on the .NET runtime working, but the System.Net.Http team say they just use the OS defaults). It's frustrating that so many people on WIndows have been having TLS connection problems, but I don't remember any problems from customers on Linux or Mac. Anyway, if my test program says that "none" failed, then your operating system defaults need to be changed.

return hierarchy.IsCapabilityMatch("AssemblyReferences + DeclaredSourceItems + UserSourceItems");
// NOTE: (AssemblyReferences + DeclaredSourceItems + UserSourceItems) exists solely for compatibility reasons
// with existing custom CPS-based projects that existed before "PackageReferences" capability was introduced.
return hierarchy.IsCapabilityMatch("(AssemblyReferences + DeclaredSourceItems + UserSourceItems) | PackageReferences");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We have another capability check, see here.

That one probably needs to be a PackageReferences check but I think it can break some custom project-systems if any.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this is good enough for now though.
Happy to have a discussion if necessary @davkean

@nkolev92

Copy link
Copy Markdown
Member

@zivkan fwiw, seems like this is a Framework instead of Core problem: NuGet/Home#9961

At least afaik, the configure.ps1 script calls MSBuild,

@davkean

davkean commented Sep 1, 2020

Copy link
Copy Markdown
Contributor Author

@zivkan I tried turning on TLS 1.3 via some regkeys I fond on the interweb, but to no avail - what should I be setting it?

@davkean

davkean commented Sep 1, 2020

Copy link
Copy Markdown
Contributor Author

@rrelyea It looks like some tests with your photo next to it, timed out, should I be looking at those?

@zivkan

zivkan commented Sep 1, 2020

Copy link
Copy Markdown
Member

I tried turning on TLS 1.3 via some regkeys I fond on the interweb, but to no avail - what should I be setting it?

Windows TLS 1.3 should be disabled, not enabled.

My understanding is that the TLS 1.3 implementation that Windows had months ago was from an early TLS1.3 spec that got changed before the rest of the industry took up TLS1.3, so Windows TLS APIs were never really compatible with TLS1.3. But it had always been turned off by default, possibly until recently. The dotnet/runtime issue I linked suggests that recent Windows Insider builds have changed something, in case you're running preview versions of Windows. Check that thread out for more info, but again people reported that disabling TLS 1.3 allows .NET's HttpClient to use TLS1.2. The strangest thing is that nuget.org told their CDN provider to turn off TLS 1.3 on api.nuget.org, which suggests that Windows TLS implementation isn't even "falling back" to TLS 1.2 when both 1.3 and 1.2 are enabled on the client, but the server only supports 1.2

More than this, I'm not really sure. NuGet uses .NET's HttpClient in a fairly standard way, so we're reliant on the .NET System.Net team, and the Windows SCHANNEL team (they implement TLS). All I can suggest is contacting those teams. My gist that I linked is a very simple demo app to ensure that it's not NuGet doing something weird.

It looks like some tests with your photo next to it, timed out, should I be looking at those?

We've been experiencing a lot of xunit flakiness, but only on Linux. Each time Linux tests hang, there's exactly 8 tests that started and never finished, but the tests seem to be different each time, so we haven't been able to determine it's the way that a test was implemented, and if it was one specific test, it doesn't explain why it kills 7 other tests in the run.

Anyway, I'll rerun the failed linux job. Most of the time the tests don't hang, but a non-trivial percentage do hang. We'll see how lucky we are today.

@aortiz-msft

Copy link
Copy Markdown
Contributor

Thank you for the fix. Could you please fill out the PR template?

@aortiz-msft aortiz-msft left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please fill out the PR template.

@donnie-msft donnie-msft left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please link to any docs/specs that describe the PackageReferences capability.

@nkolev92

nkolev92 commented Sep 4, 2020

Copy link
Copy Markdown
Member

@davkean

It does not, however, cause the assets file to be written whcih needs investigation.

It's possible that we are not bucketing the project in the right NuGet type.
At project load we call https://github.com/NuGet/NuGet.Client/blob/dev/src/NuGet.Clients/NuGet.PackageManagement.VisualStudio/Projects/NetCorePackageReferenceProjectProvider.cs

Specifically here:

await _threadingService.JoinableTaskFactory.SwitchToMainThreadAsync();
.

If you are motivated, you can debug and see in which bucket it ends up.

We have 2 types of PR projects, LegacyPackageReference and NetCorePackageReferenceProject.
The NetCorePackageReferenceProject is the one that works with nominations.

@zivkan

zivkan commented Sep 4, 2020

Copy link
Copy Markdown
Member

This change lets a custom CPS-based project type, including C++ and MSIX projects to opt into the PackageReferences capability and have end-to-end just work.

I think only restore might "just work". Installing, upgrading and uninstalling packages, NuGet has a hard dependency on the project system currently, so I don't think it will work for projects that are neither csproj.dll or CPS (although it's not clear to me if it would even work for non-.NET CPS projects, maybe our updates are specific to managed CPS project types).

@nkolev92

nkolev92 commented Sep 4, 2020

Copy link
Copy Markdown
Member

I think only restore might "just work". Installing, upgrading and uninstalling packages, NuGet has a hard dependency on the project system currently, so I don't think it will work for projects that are neither csproj.dll or CPS

The checks for "can I read PRs" & "can I write PRs" are rolled into one (the whole ProjectProvider concept) so I think we just don't interpret them as PR at the end of the day.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Community PRs created by someone not in the NuGet team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NuGet features should light up for projects that have the capability; "PackageReferences"

5 participants