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

error when TPV is missing from target frameworks #3616

Merged
merged 7 commits into from
Sep 9, 2020
Merged

Conversation

zkat
Copy link
Contributor

@zkat zkat commented Aug 28, 2020

@zivkan
Copy link
Member

zivkan commented Aug 28, 2020

  1. The PR title says it's checking dependencies, but the code seems to be checking the project TFM. It seems reasonable to me to make sure the project has a platform version. If someone creates a nupkg without a platform version, do we want to make that nupkg unusable, or just assume it's platform 0.0 and make a best guess at compatibility (compatible with all projects using the same TFM and platform identifier)?

  2. I don't see a task under the net5 epic to make sure that when a nupkg is being created (whether it's via msbuild pack or nuget.exe pack) that net5 TFMs with platforms must have a platform version. Should that work be done in this PR, or another issue/PR?

@zkat zkat changed the title error when TPV is missing from dependencies error when TPV is missing from target frameworks Aug 28, 2020
@zkat
Copy link
Contributor Author

zkat commented Aug 28, 2020

  1. yeah, that was a brain fart. Fixed!
  2. I was thinking of just doing this check during restore -- won't that block packs, too?

@zivkan
Copy link
Member

zivkan commented Aug 28, 2020

I think if the obj folder is clean, then yes, pack will fail. But if they have a valid project, restore so an assets file is created, then change the project so they don't have a TPV, I don't know what will happen if they try to pack.

I was also wondering if we need to do any checks if the customer packs with a custom nuspec, but I guess we don't validate any other lib/folder is a valid TFM, so probably no need to do anything extra.

@nkolev92
Copy link
Member

I think adding it to pack might be a reasonable suggestion.

I think if the obj folder is clean, then yes, pack will fail. But if they have a valid project, restore so an assets file is created, then change the project so they don't have a TPV, I don't know what will happen if they try to pack.

Pack shouldn't happen if a restore fails. Build shouldn't happen if a restore fails.
Worth double checking though.

@zkat zkat requested a review from a team as a code owner August 31, 2020 23:40
@zkat zkat requested a review from erdembayar September 1, 2020 16:09
if (!string.IsNullOrEmpty(targetFramework))
{
var fw = NuGetFramework.Parse(targetFramework);
if (!string.IsNullOrEmpty(fw.Platform) && fw.PlatformVersion == FrameworkConstants.EmptyVersion)
Copy link
Contributor

Choose a reason for hiding this comment

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

!string.IsNullOrEmpty(fw.Platform) && fw.PlatformVersion == FrameworkConstants.EmptyVersion [](start = 24, length = 91)

Just for my understanding, is there a case where having a PlatformVersion without a Platform is valid?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nope!

Copy link
Contributor

Choose a reason for hiding this comment

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

In that case, do we need the first check for fw.Platform?

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (!string.IsNullOrEmpty(fw.Platform) && fw.PlatformVersion == FrameworkConstants.EmptyVersion)
if (fw.PlatformVersion == FrameworkConstants.EmptyVersion)

Copy link
Contributor Author

@zkat zkat Sep 4, 2020

Choose a reason for hiding this comment

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

Oh, yes we do, because "PlatformVersion" will be EmptyVersion when Platform is empty, and we only wanna do this check when we definitely have a platform.

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 like a great start.

I think we should make sure we cover the manual edit scenarios in the test.

In particular, nuspec packing where both the targetframework is specified in the dependency group and when the file structure is created by the customer.

ie verify that someone can't just add a

lib/net50/mylib.dll

src/NuGet.Core/NuGet.Build.Tasks.Pack/PackTaskLogic.cs Outdated Show resolved Hide resolved
src/NuGet.Core/NuGet.Commands/Strings.resx Outdated Show resolved Hide resolved
@zkat zkat force-pushed the dev-zkat-missing-tpv branch from 3bddcfb to 27d89d0 Compare September 8, 2020 21:30
@zkat zkat requested review from nkolev92 and aortiz-msft September 8, 2020 21:34
if (!string.IsNullOrEmpty(targetFramework))
{
var fw = NuGetFramework.Parse(targetFramework);
if (!string.IsNullOrEmpty(fw.Platform) && fw.PlatformVersion == FrameworkConstants.EmptyVersion)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (!string.IsNullOrEmpty(fw.Platform) && fw.PlatformVersion == FrameworkConstants.EmptyVersion)
if (fw.PlatformVersion == FrameworkConstants.EmptyVersion)

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.

Can we please cover manual nuspec scenarios + advanced pack targeting scenarios where the user manually redirects to a folder using PackagePath.

In particular I think we need to handle the following scenarios:

I know these scenarios might be new, so grab some time with me if you need help crafting the tests.

{
foreach (NuGetFramework fw in badPlatforms)
{
_logger.Log(RestoreLogMessage.CreateError(NuGetLogCode.NU1012, string.Format(CultureInfo.CurrentCulture, Strings.Error_PlatformVersionNotPresent, fw.Framework, fw.Platform)));
Copy link
Member

Choose a reason for hiding this comment

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

nit: In an ideal world, I'd recommend these get merged so that a user gets only 1 instead of N errors, but I simply don't see this scenario getting hit too often (actually I'd only expect it during development), so I would not bother too much :)

@heng-liu heng-liu merged commit d1e99c9 into dev Sep 9, 2020
@heng-liu heng-liu deleted the dev-zkat-missing-tpv branch September 9, 2020 02:39
@nkolev92
Copy link
Member

nkolev92 commented Sep 9, 2020

@heng-liu I don't think this change was ready to be merged

heng-liu pushed a commit that referenced this pull request Sep 9, 2020
* error when TPV is missing from dependencies

Fixes: NuGet/Home#9441
@nkolev92
Copy link
Member

nkolev92 commented Sep 9, 2020

We should probably create a follow-up here to make sure all scenarios are covered.

We might be adding just tests, but I don't have high confidence that we don't need more product changes.

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.

net5 tfm: produce error when missing TPV
7 participants