Skip to content

Commit

Permalink
Paket convert-from-nuget doesn't crash on NuGet v2 syntax - fixes #3151
Browse files Browse the repository at this point in the history
  • Loading branch information
forki committed Apr 13, 2018
1 parent eaf56e7 commit 833b36c
Show file tree
Hide file tree
Showing 15 changed files with 95 additions and 74 deletions.
3 changes: 3 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#### 5.156.1 - 2018-04-13
* BUGFIX: Paket convert-from-nuget doesn't crash on NuGet v2 syntax - https://github.com/fsprojects/Paket/issues/3151

#### 5.156.0 - 2018-04-12
* Support monoandroid version 8.1 - https://github.com/fsprojects/Paket/pull/3146

Expand Down
12 changes: 6 additions & 6 deletions src/Paket.Bootstrapper/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
[assembly: AssemblyTitleAttribute("Paket.Bootstrapper")]
[assembly: AssemblyProductAttribute("Paket")]
[assembly: AssemblyDescriptionAttribute("A dependency manager for .NET with support for NuGet packages and git repositories.")]
[assembly: AssemblyVersionAttribute("5.156.0")]
[assembly: AssemblyFileVersionAttribute("5.156.0")]
[assembly: AssemblyInformationalVersionAttribute("5.156.0")]
[assembly: AssemblyVersionAttribute("5.156.1")]
[assembly: AssemblyFileVersionAttribute("5.156.1")]
[assembly: AssemblyInformationalVersionAttribute("5.156.1")]
namespace System {
internal static class AssemblyVersionInformation {
internal const System.String AssemblyTitle = "Paket.Bootstrapper";
internal const System.String AssemblyProduct = "Paket";
internal const System.String AssemblyDescription = "A dependency manager for .NET with support for NuGet packages and git repositories.";
internal const System.String AssemblyVersion = "5.156.0";
internal const System.String AssemblyFileVersion = "5.156.0";
internal const System.String AssemblyInformationalVersion = "5.156.0";
internal const System.String AssemblyVersion = "5.156.1";
internal const System.String AssemblyFileVersion = "5.156.1";
internal const System.String AssemblyInformationalVersion = "5.156.1";
}
}
12 changes: 6 additions & 6 deletions src/Paket.Core/AssemblyInfo.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ open System.Reflection
[<assembly: AssemblyProductAttribute("Paket")>]
[<assembly: AssemblyCompanyAttribute("Paket team")>]
[<assembly: AssemblyDescriptionAttribute("A dependency manager for .NET with support for NuGet packages and git repositories.")>]
[<assembly: AssemblyVersionAttribute("5.156.0")>]
[<assembly: AssemblyFileVersionAttribute("5.156.0")>]
[<assembly: AssemblyInformationalVersionAttribute("5.156.0")>]
[<assembly: AssemblyVersionAttribute("5.156.1")>]
[<assembly: AssemblyFileVersionAttribute("5.156.1")>]
[<assembly: AssemblyInformationalVersionAttribute("5.156.1")>]
do ()

module internal AssemblyVersionInformation =
let [<Literal>] AssemblyTitle = "Paket.Core"
let [<Literal>] AssemblyProduct = "Paket"
let [<Literal>] AssemblyCompany = "Paket team"
let [<Literal>] AssemblyDescription = "A dependency manager for .NET with support for NuGet packages and git repositories."
let [<Literal>] AssemblyVersion = "5.156.0"
let [<Literal>] AssemblyFileVersion = "5.156.0"
let [<Literal>] AssemblyInformationalVersion = "5.156.0"
let [<Literal>] AssemblyVersion = "5.156.1"
let [<Literal>] AssemblyFileVersion = "5.156.1"
let [<Literal>] AssemblyInformationalVersion = "5.156.1"
4 changes: 2 additions & 2 deletions src/Paket.Core/Dependencies/PackageResolver.fs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ module ResolutionRaw =

errorReport.AddLine (sprintf " Conflict detected:")

let getConflictMessage req =
let getConflictMessage (req:PackageRequirement) =
let vr = formatVR req.VersionRequirement
let pr = formatPR req.VersionRequirement
let tp = if req.TransitivePrereleases then "*" else ""
Expand Down Expand Up @@ -555,7 +555,7 @@ let private getCompatibleVersions
| true, p ->
allRequirementsOfCurrentPackage
|> Set.forall (fun r ->
let mapped = mapF r
let mapped : PackageRequirement = mapF r
mapped.VersionRequirement.IsInRange cache.Version ||
mapped.IncludingPrereleases(p.VersionRequirement.PreReleases).VersionRequirement.IsInRange cache.Version)
| _ ->
Expand Down
7 changes: 2 additions & 5 deletions src/Paket.Core/Installation/InstallProcess.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,10 @@ open Chessie.ErrorHandling
open Paket.Domain
open Paket.Logging
open Paket.BindingRedirects
open Paket.ModuleResolver
open Paket.PackageResolver
open System.IO
open Paket.PackageSources
open Paket.PackagesConfigFile
open Paket.Requirements
open System.Collections.Generic
open Paket.ProjectFile
open System

let updatePackagesConfigFile (model: Map<GroupName*PackageName,SemVerInfo*InstallSettings>) packagesConfigFileName =
Expand All @@ -23,8 +19,9 @@ let updatePackagesConfigFile (model: Map<GroupName*PackageName,SemVerInfo*Instal
model
|> Seq.filter (fun kv -> defaultArg (snd kv.Value).IncludeVersionInPath false)
|> Seq.map (fun kv ->
let v = fst kv.Value
{ NugetPackage.Id = (snd kv.Key).ToString()
VersionRange = VersionRange.Specific (fst kv.Value)
VersionRequirement = VersionRequirement(VersionRange.Specific v,PreReleaseStatus.No)
Kind = NugetPackageKind.Package
TargetFramework = None })
|> Seq.toList
Expand Down
30 changes: 15 additions & 15 deletions src/Paket.Core/PackageManagement/NugetConvert.fs
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,9 @@ module ConvertResultR =
PaketEnv = paketEnv
SolutionFiles = solutionFiles }

let createPackageRequirement sources (packageName, versionRange, restrictions) dependenciesFileName =
let createPackageRequirement sources (packageName, versionRequirement, restrictions) dependenciesFileName =
{ Name = PackageName packageName
VersionRequirement = VersionRequirement(versionRange, PreReleaseStatus.No)
VersionRequirement = versionRequirement
ResolverStrategyForDirectDependencies = None
ResolverStrategyForTransitives = None
Settings = { InstallSettings.Default with FrameworkRestrictions = restrictions }
Expand All @@ -240,7 +240,7 @@ let private addFSharpCoreToDependenciesIfRequired nugetEnv packages =
packages
|> Seq.exists (fun (n,_,_,_) -> "fsharp.core".Equals(n, StringComparison.OrdinalIgnoreCase))
if hasFSharpProject && not hasFSharpCorePackage then
let fsCore = ("FSharp.Core", VersionRange.AtLeast "0",FrameworkRestriction.NoRestriction, NugetPackageKind.Package)
let fsCore = ("FSharp.Core", VersionRequirement.AllReleases,FrameworkRestriction.NoRestriction, NugetPackageKind.Package)
fsCore :: packages
else
packages
Expand All @@ -252,12 +252,12 @@ let createDependenciesFileR (rootDirectory : DirectoryInfo) nugetEnv mode =
let allVersionsGroupped =
nugetEnv.NuGetProjectFiles
|> List.collect (fun (pf,c) ->
c
|> Option.map (fun x -> x.Packages)
|> Option.toList
|> List.concat
|> List.append (ProjectFile.dotNetCorePackages pf)
|> List.append (ProjectFile.cliTools pf))
c
|> Option.map (fun x -> x.Packages)
|> Option.toList
|> List.concat
|> List.append (ProjectFile.dotNetCorePackages pf)
|> List.append (ProjectFile.cliTools pf))
|> List.groupBy (fun p -> p.Id)

let findDistinctPackages selector =
Expand All @@ -270,13 +270,13 @@ let createDependenciesFileR (rootDirectory : DirectoryInfo) nugetEnv mode =
if List.length versions > 1 then
traceWarnfn message name versions

findWarnings (List.choose (fun p -> match p.VersionRange with Specific v -> Some v | _ -> None) >> List.distinct >> List.map string)
findWarnings (List.choose (fun p -> match p.VersionRequirement.Range with Specific v -> Some v | _ -> None) >> List.distinct >> List.map string)
"Package %s is referenced multiple times in different versions: %A. Paket will choose the latest one."
findWarnings (List.map (fun p -> p.TargetFramework) >> List.distinct >> List.choose id >> List.map string)
"Package %s is referenced multiple times with different target frameworks : %A. Paket may disregard target framework."

let latestVersions =
findDistinctPackages (List.map (fun p -> p.VersionRange, p.TargetFramework, p.Kind) >> List.distinct)
findDistinctPackages (List.map (fun p -> p.VersionRequirement, p.TargetFramework, p.Kind) >> List.distinct)
|> List.map (fun (name, versions) ->
let latestVersion, _, _ = versions |> List.maxBy (fun (x,_,_) -> x)
let kind =
Expand All @@ -303,7 +303,7 @@ let createDependenciesFileR (rootDirectory : DirectoryInfo) nugetEnv mode =

let packages =
match nugetEnv.NuGetExe with
| Some _ -> ("NuGet.CommandLine",VersionRange.AtLeast "0",FrameworkRestriction.NoRestriction, NugetPackageKind.Package) :: latestVersions
| Some _ -> ("NuGet.CommandLine",VersionRequirement.AllReleases,FrameworkRestriction.NoRestriction, NugetPackageKind.Package) :: latestVersions
| _ -> latestVersions
|> addFSharpCoreToDependenciesIfRequired nugetEnv

Expand All @@ -312,12 +312,12 @@ let createDependenciesFileR (rootDirectory : DirectoryInfo) nugetEnv mode =
packages
|> List.map (fun (name, vr, restrictions, kind) ->
Constants.MainDependencyGroup, PackageName name, vr, { InstallSettings.Default with FrameworkRestrictions = ExplicitRestriction restrictions}, kind)
|> List.fold (fun (dependenciesFile:DependenciesFile) (groupName, packageName,versionRange,installSettings,kind) ->
|> List.fold (fun (dependenciesFile:DependenciesFile) (groupName, packageName,versionRequirement,installSettings,kind) ->
let reqKind =
match kind with
| NugetPackageKind.Package -> PackageRequirementKind.Package
| NugetPackageKind.DotnetCliTool -> PackageRequirementKind.DotnetCliTool
dependenciesFile.Add(groupName, packageName,versionRange,installSettings, reqKind)) dependenciesFile
dependenciesFile.Add(groupName, packageName,versionRequirement.Range,installSettings, reqKind)) dependenciesFile
try
DependenciesFile.ReadFromFile dependenciesFileName
|> ok
Expand Down Expand Up @@ -397,7 +397,7 @@ let convertProjects nugetEnv =
|> Option.toList
|> List.concat
|> List.choose (fun p ->
match p.VersionRange with
match p.VersionRequirement.Range with
| VersionRange.Specific v -> Some(p.Id, v)
| _ -> None )

Expand Down
12 changes: 10 additions & 2 deletions src/Paket.Core/PaketConfigFiles/PackagesConfigFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ let Read fileName =
doc.Load f)

[for node in doc.SelectNodes("//package") ->
let v = node.Attributes.["version"].Value
{ NugetPackage.Id = node.Attributes.["id"].Value
VersionRange = VersionRange.Specific (SemVer.Parse node.Attributes.["version"].Value)
VersionRequirement = VersionRequirement.Parse v

This comment has been minimized.

Copy link
@matthid

matthid Jul 28, 2018

Member

I think this has changed behavior because packages.config will never contain [] and in particular it has changed convert-from-nuget (and some tests).

This comment has been minimized.

Copy link
@matthid

matthid Jul 28, 2018

Member

Will revert this in #3307 in an attempt to get the CI green again ...

Kind = NugetPackageKind.Package
TargetFramework =
node
Expand All @@ -28,13 +29,20 @@ let Serialize (packages: NugetPackage seq) =
let packages =
packages
|> Seq.choose (fun p ->
match p.VersionRange with
match p.VersionRequirement.Range with
| VersionRange.Specific v ->
let framework =
match p.TargetFramework with
| Some tf -> sprintf "targetFramework=\"%s\" " (tf.Replace(">= ",""))
| _ -> ""

Some (sprintf """ <package id="%s" version="[%O]" %s/>""" p.Id v framework)

This comment has been minimized.

Copy link
@M0ns1gn0r

M0ns1gn0r May 21, 2018

This change breaks Package Management Console in Visual Studio.

An error occurred while reading file 'D:\Work\PaketVersionTest\packages.config': Invalid package version for package id 'EntityFramework': '[6.2.0]'

Look like the brackets syntax is not supported. Should I create a separate issue?

| VersionRange.Minimum v ->
let framework =
match p.TargetFramework with
| Some tf -> sprintf "targetFramework=\"%s\" " (tf.Replace(">= ",""))
| _ -> ""

Some (sprintf """ <package id="%s" version="%O" %s/>""" p.Id v framework)
| _ -> None)

Expand Down
49 changes: 20 additions & 29 deletions src/Paket.Core/PaketConfigFiles/ProjectFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1628,46 +1628,37 @@ module ProjectFile =

tryNextPlat platforms []

let versionRequirement node =
let v =
match node |> getAttribute "Version" with
| Some version -> version
| None ->
match node |> getNode "Version" with
| Some n -> n.InnerText
| None -> "*"

if v.Contains "[" || v.Contains "(" then
VersionRequirement.Parse v
else
let prerelease = if v.Contains "-" then PreReleaseStatus.All else PreReleaseStatus.No
if v.Contains "*" then
VersionRequirement.VersionRequirement(VersionRange.AtLeast (v.Replace("*","0")),prerelease)
else
VersionRequirement.VersionRequirement(VersionRange.Exactly v,prerelease)

let dotNetCorePackages (projectFile: ProjectFile) =
packageReferencesNoPrivateAssets projectFile
|> List.map (fun node ->
let versionRange =
let v =
match node |> getAttribute "Version" with
| Some version -> version
| None ->
match node |> getNode "Version" with
| Some n -> n.InnerText
| None -> "*"

if v.Contains "*" then
VersionRange.AtLeast (v.Replace("*","0"))
else
VersionRange.Exactly v
{ NugetPackage.Id = getPackageIdAttribute projectFile node
VersionRange = versionRange
VersionRequirement = versionRequirement node
Kind = NugetPackageKind.Package
TargetFramework = None })

let cliTools (projectFile: ProjectFile) =
cliToolsNoPrivateAssets projectFile
|> List.map (fun node ->
let versionRange =
let v =
match node |> getAttribute "Version" with
| Some version -> version
| None ->
match node |> getNode "Version" with
| Some n -> n.InnerText
| None -> "*"

if v.Contains "*" then
VersionRange.AtLeast (v.Replace("*","0"))
else
VersionRange.Exactly v

{ NugetPackage.Id = node |> getAttribute "Include" |> Option.get
VersionRange = versionRange
VersionRequirement = versionRequirement node
Kind = NugetPackageKind.DotnetCliTool
TargetFramework = None })

Expand Down
2 changes: 1 addition & 1 deletion src/Paket.Core/Versioning/PackageSources.fs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ let DefaultNuGetSource = PackageSource.NuGetV2Source Constants.DefaultNuGetStrea

type NugetPackage = {
Id : string
VersionRange : VersionRange
VersionRequirement : VersionRequirement
Kind : NugetPackageKind
TargetFramework : string option
}
Expand Down
12 changes: 6 additions & 6 deletions src/Paket/AssemblyInfo.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ open System.Reflection
[<assembly: AssemblyProductAttribute("Paket")>]
[<assembly: AssemblyCompanyAttribute("Paket team")>]
[<assembly: AssemblyDescriptionAttribute("A dependency manager for .NET with support for NuGet packages and git repositories.")>]
[<assembly: AssemblyVersionAttribute("5.156.0")>]
[<assembly: AssemblyFileVersionAttribute("5.156.0")>]
[<assembly: AssemblyInformationalVersionAttribute("5.156.0")>]
[<assembly: AssemblyVersionAttribute("5.156.1")>]
[<assembly: AssemblyFileVersionAttribute("5.156.1")>]
[<assembly: AssemblyInformationalVersionAttribute("5.156.1")>]
do ()

module internal AssemblyVersionInformation =
let [<Literal>] AssemblyTitle = "Paket"
let [<Literal>] AssemblyProduct = "Paket"
let [<Literal>] AssemblyCompany = "Paket team"
let [<Literal>] AssemblyDescription = "A dependency manager for .NET with support for NuGet packages and git repositories."
let [<Literal>] AssemblyVersion = "5.156.0"
let [<Literal>] AssemblyFileVersion = "5.156.0"
let [<Literal>] AssemblyInformationalVersion = "5.156.0"
let [<Literal>] AssemblyVersion = "5.156.1"
let [<Literal>] AssemblyFileVersion = "5.156.1"
let [<Literal>] AssemblyInformationalVersion = "5.156.1"
1 change: 1 addition & 0 deletions tests/Paket.Tests.preview3/Paket.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
<TestAsset Include="NuGetLocal\case2\package.name.1.2.0.0.nupkg" />
<TestAsset Include="NuGetLocal\case3\netstedFolder\package.in.nested.folder.1.0.0.nupkg" />
<TestAsset Include="PackagesConfig\xunit.visualstudio.packages.config" />
<TestAsset Include="PackagesConfig\xunit.visualstudio.packages2.config" />
<TestAsset Include="PackagesConfig\asp.net.packages.config" />
<Compile Include="$(PaketTestsSourcesDir)\PackagesConfig\ReadConfig.fs" />
<Compile Include="$(PaketTestsSourcesDir)\PackagesConfig\WriteConfig.fs" />
Expand Down
11 changes: 9 additions & 2 deletions tests/Paket.Tests/PackagesConfig/ReadConfig.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,19 @@ open Paket
open Paket.PackagesConfigFile
open NUnit.Framework
open FsUnit
open Domain

[<Test>]
let ``can read xunit.visualstudio.packages.config``() =
let config = Read("PackagesConfig/xunit.visualstudio.packages.config") |> List.head

config.Id |> shouldEqual "xunit.runner.visualstudio"
config.TargetFramework |> shouldEqual None
config.VersionRange |> shouldEqual (VersionRange.Specific (SemVer.Parse "2.0.1"))
config.VersionRequirement.Range |> shouldEqual (VersionRange.Minimum (SemVer.Parse "2.0.1"))

[<Test>]
let ``can read xunit.visualstudio.packages2.config``() =
let config = Read("PackagesConfig/xunit.visualstudio.packages2.config") |> List.head

config.Id |> shouldEqual "xunit.runner.visualstudio"
config.TargetFramework |> shouldEqual None
config.VersionRequirement.Range |> shouldEqual (VersionRange.Specific (SemVer.Parse "2.0.1"))
7 changes: 7 additions & 0 deletions tests/Paket.Tests/PackagesConfig/WriteConfig.fs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ let ``can write xunit.visualstudio.packages.config``() =
let expected = File.ReadAllText fileName |> normalizeLineEndings
Serialize config |> normalizeLineEndings |> shouldEqual expected

[<Test>]
let ``can write xunit.visualstudio.package2s.config``() =
let fileName = "PackagesConfig/xunit.visualstudio.packages2.config"
let config = Read fileName
let expected = File.ReadAllText fileName |> normalizeLineEndings
Serialize config |> normalizeLineEndings |> shouldEqual expected

[<Test>]
let ``can write asp.net.packages.config``() =
let fileName = "PackagesConfig/asp.net.packages.config"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="xunit.runner.visualstudio" version="[2.0.1]" />
</packages>
3 changes: 3 additions & 0 deletions tests/Paket.Tests/Paket.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@
<Content Include="PackagesConfig\xunit.visualstudio.packages.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="PackagesConfig\xunit.visualstudio.packages2.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="PackagesConfig\asp.net.packages.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
Expand Down

0 comments on commit 833b36c

Please sign in to comment.