NuGet / Home

Repo for NuGet Client issues
Other
1.5k stars 252 forks source link

packages.config to PackageReference migrator fails when a package with an invalid folder structure is in the project graph. #8923

Open a-einstein opened 4 years ago

a-einstein commented 4 years ago

Details about Problem

NuGet product used: VS UI. 'Migrate packages.config to PackageReference' on a packages.config of a Test project.

NuGet version: 5.4.0

dotnet.exe --version: 4.8

VS version: 16.4.1.

OS version: Windows 10 version 1909 build 18363.476

Worked before? If so, with which NuGet version: Yes, on other projects.

Detailed repro steps so we can see the same problem

  1. I have this package file.

    <?xml version="1.0" encoding="utf-8"?>
    <packages>
    <package id="Appium.WebDriver" version="4.1.1" targetFramework="net48" />
    <package id="Castle.Core" version="4.4.0" targetFramework="net472" />
    <package id="DotNetSeleniumExtras.PageObjects" version="3.11.0" targetFramework="net472" />
    <package id="Microsoft.CodeAnalysis.FxCopAnalyzers" version="2.9.8" targetFramework="net48" developmentDependency="true" />
    <package id="Microsoft.CodeAnalysis.VersionCheckAnalyzer" version="2.9.8" targetFramework="net48" developmentDependency="true" />
    <package id="Microsoft.CodeQuality.Analyzers" version="2.9.8" targetFramework="net48" developmentDependency="true" />
    <package id="Microsoft.NetCore.Analyzers" version="2.9.8" targetFramework="net48" developmentDependency="true" />
    <package id="Microsoft.NetFramework.Analyzers" version="2.9.8" targetFramework="net48" developmentDependency="true" />
    <package id="Newtonsoft.Json" version="12.0.3" targetFramework="net48" />
    <package id="Selenium.Support" version="3.141.0" targetFramework="net472" />
    <package id="Selenium.WebDriver" version="3.141.0" targetFramework="net472" />
    <package id="VS.QualityTools.UnitTestFramework" version="15.0.27323.2" targetFramework="net472" />
    </packages>

    Also see the analysis screen shot. analysis

  2. Call the migrator. I get a good analysis as it seems.

  3. Apply.

    • I do not get a report.
    • The package files disappears.
    • The difference on the project file shows only removals.
    • Project does not build.
  4. Used the NuGet package manager to manually install the top level dependencies.

    • Fails on UnitTestFramework. DotNet 4.8 not supported.
  5. Added UnitTestFramework as a simple reference. Found in Visual Studio 2019.

    • Builds.

Sample Project

Did not succeed in Firefox. Done in bare Pale Moon. RCS.WpfShop.TestGui.zip

Conclusion

So, it seems a matter of handling such a case by the migrator.

donnie-msft commented 4 years ago

Just to confirm, are you actually using the UnitTestFramework in your code? I expect if a Restore would fail due to incompatible TFMs, we may not know that at the time of the PackageReference migration.

//cc: @rrelyea

nkolev92 commented 4 years ago

PackageReference has better restrictions for invalid packages compared to packages.config.

And the package vs.qualitytools.unittestframework is such an invalid package. Peaking at the packages content I see:

vs.qualitytools.unittestframework\15.0.27323.2\lib\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll

Notice how the folder name is the name of the dll. Related https://docs.microsoft.com/en-us/nuget/reference/errors-and-warnings/nu5101

The correct way to author this package would be:

lib\\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll

For example:

lib\net472\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll

At migration time, NuGet was unable to install the package in question and it was supposed to fail.

As you correctly observed, there was no report/no indication that something went wrong and that's a bug in the migrator.

Given your repro, if I remove the faulty package then everything works (as you've already observed), so if possible, you can consider not depending on that package. If you really need the functionality of the package, you can:

  1. contact the package author to publish a new version
  2. consider repacking locally with the correct folder structure.

You've already indicated that you are unblocked though, just wanted to clarify your options :)

Given all this, we'll keep this issue open as a migrator bug.

jjmanton commented 4 years ago

I believe this could be a regression in a recent release of the migrator/Visual Studio. In previous versions, I would get a warning for packages that contained only a lib folder (which would require lib/Net45 for example), but in the most recent versions I am no longer seeing those packages show as compatibility issues. When migrating in the latest visual studio version, I get behavior similar to @a-einstein. No packageReferences are created in the project file.

nkolev92 commented 4 years ago

@v-luzh

Can you please try to validate this report with the latest stable NuGet (VS 2019.6)

v-luzh commented 4 years ago

Hi @nkolev92, this issue still repro (didn't have the report, all packages disappeared in PM UI, and the "Packages.config" file disappeared) on VS Master\30126.103 + NuGet Client Dev\5.7.0.6623. But we got error NU1202 in the Error List window to show the incompatible TFM as below screenshot. image

nkolev92 commented 4 years ago

Thanks @v-luzh

@jjmanton are you seeing something different from what @v-luzh's repro does? I think the lack of a report is the obvious bug. I am just trying to understand if there's any other bugs that we might be missing.

jjmanton commented 4 years ago

@nkolev92 I think 16.6 partially fixed the issue. Here is what I observed -

Screen Shot 2020-05-28 at 9 33 50 AM Screen Shot 2020-05-28 at 8 30 54 AM

Note that the package compatibility box is still empty, which is a bug. I am not getting warnings about install.ps1, and missing TFM folder under lib. The web report comes up fine, and package references are correctly added to the csproj. Strangely though, my packages with lib only folder hierarchy are working fine. Was this a change recently? This used to fail.

nkolev92 commented 4 years ago

Note that the package compatibility box is still empty, which is a bug.

Yep, that's the main issue we've observed here :)

I am not getting warnings about install.ps1, and missing TFM folder under lib. The web report comes up fine, and package references are correctly added to the csproj. Strangely though, my packages with lib only folder hierarchy are working fine. Was this a change recently? This used to fail.

No change with install.ps1 and missing tfm folder warnigns. The warnings should've been displayed and no compatibility changes have been made.

Nikita-T86 commented 1 year ago

I still have that problem is VS 2022. To reproduce

  1. Add NuGet package reference to VS.QualityTools.UnitTestFramework (some private package with wrong folder structure)
  2. Try to use converter to convert to PackageReference, you will get an error that package is not supported in net472 (because it has wrong folder structure).

The workaround is to reference MSTest.TestAdapter and MSTest.TestFramework packages instead.