aspnet / dnx

OBSOLETE - see readme
Other
963 stars 224 forks source link

Fix casing of package IDs in lockfile #1470

Closed ChengTian closed 9 years ago

ChengTian commented 9 years ago

https://github.com/aspnet/dnx/issues/581

Current dnu restore behavior is: When restoring a package with wrong id casing, for example restoring package XYZ.1.0.0 by having "xyz": "1.0.0" in project.json, it shows Unable to resolve xyz.1.0.0, do you mean XYZ.1.0.0? and doesn't install the package. It prevents users from using some NuGet packages (see cases below).

New behavior should be: Instead of exiting with error message above, we install the package to .dnx/xyz/1.0.0 and make sure the casing of package name in lockfile is correct (xyz). This should fix the cases below.

Basically, we always agree on the casing used by dependency graph.

davidfowl commented 9 years ago
{
    "version": "1.0.0-*",
    "dependencies": {
        "NuGet.Core": "2.8.3"
    },
    "frameworks": {
        "dnx451": { },
        "dnxcore50": { }
    }
}

Results in

Information: [LoaderContainer]: Load name=Microsoft.Framework.PackageManager
Information: [PathBasedAssemblyLoader]: Loaded name=Microsoft.Framework.PackageManager in 61ms
Restoring packages for C:\Users\davifowl\documents\visual studio 14\Projects\WebApplication25\src\WebApplication1\project.json
  CACHE https://nuget.org/api/v2/FindPackagesById()?Id='NuGet.Core'
  CACHE https://www.myget.org/F/aspnetvolatile/api/v2/FindPackagesById()?Id='NuGet.Core'
  CACHE https://www.nuget.org/api/v2/package/Nuget.Core/2.8.3
  CACHE https://nuget.org/api/v2/FindPackagesById()?Id='Microsoft.Web.Xdt'
  CACHE https://www.myget.org/F/aspnetvolatile/api/v2/FindPackagesById()?Id='Microsoft.Web.Xdt'
Unable to locate NuGet.Core >= 2.8.3. Do you mean Nuget.Core?
Writing lock file C:\Users\davifowl\documents\visual studio 14\Projects\WebApplication25\src\WebApplication1\project.lock.json
Restore complete, 241ms elapsed
Errors in C:\Users\davifowl\documents\visual studio 14\Projects\WebApplication25\src\WebApplication1\project.json
    Unable to locate NuGet.Core >= 2.8.3. Do you mean Nuget.Core?
Loaded Module: dnx.clr.dll
Found DLL Export: CallApplicationMain
davidfowl commented 9 years ago

Seems innocent at first, but when it happens via a transitive dependency:

{
    "version": "1.0.0-*",
    "dependencies": {
        "NuGet.Indexing": "3.0.75-r-master"
    },
    "frameworks": {
        "dnx451": { },
        "dnxcore50": { }
    }
}
Writing lock file C:\Users\davifowl\documents\visual studio 14\Projects\WebApplication25\src\WebApplication1\project.lock.json
Restore complete, 14741ms elapsed
Errors in C:\Users\davifowl\documents\visual studio 14\Projects\WebApplication25\src\WebApplication1\project.json
    Unable to locate NuGet.Core >= 2.8.3-alpha0001. Do you mean Nuget.Core?
Loaded Module: dnx.clr.dll
Found DLL Export: CallApplicationMain

This is because some nuspec way down the chain says Nuget.Core and this harder to fix:

{
    "version": "1.0.0-*",
    "dependencies": {
        "Nuget.Core": "2.8.3",
        "NuGet.Indexing": "3.0.75-r-master"
    },
    "frameworks": {
        "dnx451": { },
        "dnxcore50": { }
    }
}
Information: [LoaderContainer]: Load name=Microsoft.Framework.PackageManager
Information: [PathBasedAssemblyLoader]: Loaded name=Microsoft.Framework.PackageManager in 56ms
Restoring packages for C:\Users\davifowl\documents\visual studio 14\Projects\WebApplication25\src\WebApplication1\project.json
  CACHE https://nuget.org/api/v2/FindPackagesById()?Id='Microsoft.Web.Xdt'
  CACHE https://www.myget.org/F/aspnetvolatile/api/v2/FindPackagesById()?Id='Microsoft.Web.Xdt'
  CACHE https://nuget.org/api/v2/FindPackagesById()?Id='System.Spatial'
  CACHE https://www.myget.org/F/aspnetvolatile/api/v2/FindPackagesById()?Id='System.Spatial'
  CACHE https://www.nuget.org/api/v2/package/System.Spatial/5.2.0
  CACHE https://nuget.org/api/v2/FindPackagesById()?Id='WindowsAzure.Storage'
  CACHE https://www.myget.org/F/aspnetvolatile/api/v2/FindPackagesById()?Id='WindowsAzure.Storage'
  CACHE https://www.nuget.org/api/v2/package/WindowsAzure.Storage/2.0.5.1
  CACHE https://nuget.org/api/v2/FindPackagesById()?Id='NuGet.Core'
  CACHE https://www.myget.org/F/aspnetvolatile/api/v2/FindPackagesById()?Id='NuGet.Core'
  CACHE https://www.nuget.org/api/v2/package/Nuget.Core/2.8.3-alpha0001
Writing lock file C:\Users\davifowl\documents\visual studio 14\Projects\WebApplication25\src\WebApplication1\project.lock.json
Restore complete, 1095ms elapsed
Loaded Module: dnx.clr.dll
Found DLL Export: CallApplicationMain

Nearest wins makes it work, but if packages end up having mixed casing in the same dependency tree, it might get confusing quickly.

davidfowl commented 9 years ago

Another test case:

{
    "version": "1.0.0-*",
    "dependencies": {
        "HangFire": "1.3.0"
    },

    "frameworks" : {
        "dnx451" : { 
            "dependencies": {
            }
        }
    }
}
Information: [LoaderContainer]: Load name=Microsoft.Framework.PackageManager
Information: [PathBasedAssemblyLoader]: Loaded name=Microsoft.Framework.PackageManager in 93ms
Restoring packages for c:\users\davifowl\documents\visual studio 14\Projects\ClassLibrary58\src\ClassLibrary58\project.json
  CACHE https://nuget.org/api/v2/FindPackagesById()?Id='Hangfire.Core'
  CACHE https://www.nuget.org/api/v2/package/HangFire.Core/1.3.0
  CACHE https://nuget.org/api/v2/FindPackagesById()?Id='Hangfire.SqlServer'
  CACHE https://www.nuget.org/api/v2/package/HangFire.SqlServer/1.3.0
  CACHE https://nuget.org/api/v2/FindPackagesById()?Id='Newtonsoft.Json'
Unable to locate Hangfire.SqlServer >= 1.3.0<= 1.3.0. Do you mean HangFire.SqlServer?
Unable to locate Hangfire.Core >= 1.3.0<= 1.3.0. Do you mean HangFire.Core?
Writing lock file c:\users\davifowl\documents\visual studio 14\Projects\ClassLibrary58\src\ClassLibrary58\project.lock.json
Restore complete, 732ms elapsed
Errors in c:\users\davifowl\documents\visual studio 14\Projects\ClassLibrary58\src\ClassLibrary58\project.json
    Unable to locate Hangfire.SqlServer >= 1.3.0<= 1.3.0. Do you mean HangFire.SqlServer?
    Unable to locate Hangfire.Core >= 1.3.0<= 1.3.0. Do you mean HangFire.Core?
Loaded Module: dnx.clr.dll
Found DLL Export: CallApplicationMain
ChengTian commented 9 years ago

great, will test my fix against all of those cases