From c07c4f977391f7b5cc905f2f3f34e5a51ffe516e Mon Sep 17 00:00:00 2001 From: Steffen Forkmann Date: Fri, 29 Jan 2016 18:01:10 +0100 Subject: [PATCH] Show message if a dependency is installed for wrong target framework - closes #1442 --- .../Paket.IntegrationTests/InstallSpecs.fs | 4 ++ .../before/MyClassLibrary/MyClassLibrary.sln | 27 ++++++++ .../MyClassLibrary/MyClassLibrary/Class1.cs | 12 ++++ .../MyClassLibrary.csprojtemplate | 65 +++++++++++++++++++ .../MyClassLibrary/Properties/AssemblyInfo.cs | 36 ++++++++++ .../MyClassLibrary/paket.references | 1 + .../before/paket.dependencies | 3 + src/Paket.Core/InstallModel.fs | 8 ++- src/Paket.Core/InstallProcess.fs | 1 - src/Paket.Core/ProjectFile.fs | 31 +++++---- src/Paket/Paket.fsproj | 4 +- 11 files changed, 176 insertions(+), 16 deletions(-) create mode 100644 integrationtests/scenarios/i001442-warn-if-empty/before/MyClassLibrary/MyClassLibrary.sln create mode 100644 integrationtests/scenarios/i001442-warn-if-empty/before/MyClassLibrary/MyClassLibrary/Class1.cs create mode 100644 integrationtests/scenarios/i001442-warn-if-empty/before/MyClassLibrary/MyClassLibrary/MyClassLibrary.csprojtemplate create mode 100644 integrationtests/scenarios/i001442-warn-if-empty/before/MyClassLibrary/MyClassLibrary/Properties/AssemblyInfo.cs create mode 100644 integrationtests/scenarios/i001442-warn-if-empty/before/MyClassLibrary/MyClassLibrary/paket.references create mode 100644 integrationtests/scenarios/i001442-warn-if-empty/before/paket.dependencies diff --git a/integrationtests/Paket.IntegrationTests/InstallSpecs.fs b/integrationtests/Paket.IntegrationTests/InstallSpecs.fs index c91e239405..13c0f5f1d9 100644 --- a/integrationtests/Paket.IntegrationTests/InstallSpecs.fs +++ b/integrationtests/Paket.IntegrationTests/InstallSpecs.fs @@ -127,6 +127,10 @@ let ``#1427 won't install content when content:none``() = let s2 = File.ReadAllText newWeavers |> normalizeLineEndings s1 |> shouldEqual s2 // we don not touch it +[] +let ``#1442 warn if install finds no libs``() = + let result = paket "install" "i001442-warn-if-empty" + result |> shouldContainText "contains libraries, but not for the selected TargetFramework" [] let ``#1334 without download fail``() = diff --git a/integrationtests/scenarios/i001442-warn-if-empty/before/MyClassLibrary/MyClassLibrary.sln b/integrationtests/scenarios/i001442-warn-if-empty/before/MyClassLibrary/MyClassLibrary.sln new file mode 100644 index 0000000000..d319700402 --- /dev/null +++ b/integrationtests/scenarios/i001442-warn-if-empty/before/MyClassLibrary/MyClassLibrary.sln @@ -0,0 +1,27 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.23107.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".paket", ".paket", "{673951A0-5216-4FBD-BA08-7FA057D5CC0D}" + ProjectSection(SolutionItems) = preProject + ..\paket.dependencies = ..\paket.dependencies + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MyClassLibrary", "MyClassLibrary\MyClassLibrary.csproj", "{CD678800-8DFC-4BB1-911A-7234F492EA29}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {CD678800-8DFC-4BB1-911A-7234F492EA29}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CD678800-8DFC-4BB1-911A-7234F492EA29}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CD678800-8DFC-4BB1-911A-7234F492EA29}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CD678800-8DFC-4BB1-911A-7234F492EA29}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/integrationtests/scenarios/i001442-warn-if-empty/before/MyClassLibrary/MyClassLibrary/Class1.cs b/integrationtests/scenarios/i001442-warn-if-empty/before/MyClassLibrary/MyClassLibrary/Class1.cs new file mode 100644 index 0000000000..2580be441d --- /dev/null +++ b/integrationtests/scenarios/i001442-warn-if-empty/before/MyClassLibrary/MyClassLibrary/Class1.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MyClassLibrary +{ + public class Class1 + { + } +} diff --git a/integrationtests/scenarios/i001442-warn-if-empty/before/MyClassLibrary/MyClassLibrary/MyClassLibrary.csprojtemplate b/integrationtests/scenarios/i001442-warn-if-empty/before/MyClassLibrary/MyClassLibrary/MyClassLibrary.csprojtemplate new file mode 100644 index 0000000000..01fe857954 --- /dev/null +++ b/integrationtests/scenarios/i001442-warn-if-empty/before/MyClassLibrary/MyClassLibrary/MyClassLibrary.csprojtemplate @@ -0,0 +1,65 @@ + + + + + Debug + AnyCPU + {CD678800-8DFC-4BB1-911A-7234F492EA29} + Library + Properties + MyClassLibrary + MyClassLibrary + v4.5 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + + ..\..\packages\Newtonsoft.Json\lib\net45\Newtonsoft.Json.dll + True + True + + + + + \ No newline at end of file diff --git a/integrationtests/scenarios/i001442-warn-if-empty/before/MyClassLibrary/MyClassLibrary/Properties/AssemblyInfo.cs b/integrationtests/scenarios/i001442-warn-if-empty/before/MyClassLibrary/MyClassLibrary/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..7920bce104 --- /dev/null +++ b/integrationtests/scenarios/i001442-warn-if-empty/before/MyClassLibrary/MyClassLibrary/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("MyClassLibrary")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("MyClassLibrary")] +[assembly: AssemblyCopyright("Copyright © 2015")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("cd678800-8dfc-4bb1-911a-7234f492ea29")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/integrationtests/scenarios/i001442-warn-if-empty/before/MyClassLibrary/MyClassLibrary/paket.references b/integrationtests/scenarios/i001442-warn-if-empty/before/MyClassLibrary/MyClassLibrary/paket.references new file mode 100644 index 0000000000..17d7ab6bfc --- /dev/null +++ b/integrationtests/scenarios/i001442-warn-if-empty/before/MyClassLibrary/MyClassLibrary/paket.references @@ -0,0 +1 @@ +Newtonsoft.Json framework: net451 \ No newline at end of file diff --git a/integrationtests/scenarios/i001442-warn-if-empty/before/paket.dependencies b/integrationtests/scenarios/i001442-warn-if-empty/before/paket.dependencies new file mode 100644 index 0000000000..bdd652ff0c --- /dev/null +++ b/integrationtests/scenarios/i001442-warn-if-empty/before/paket.dependencies @@ -0,0 +1,3 @@ +source https://www.nuget.org/api/v2/ + +nuget Newtonsoft.Json \ No newline at end of file diff --git a/src/Paket.Core/InstallModel.fs b/src/Paket.Core/InstallModel.fs index 098d7c7838..3035fe2a1b 100644 --- a/src/Paket.Core/InstallModel.fs +++ b/src/Paket.Core/InstallModel.fs @@ -156,6 +156,8 @@ module InstallModel = getFileFolders target installModel.TargetsFileFolders (function Reference.TargetsFile targetsFile -> Some targetsFile | _ -> None) + let hasReferences (installModel:InstallModel) = List.isEmpty installModel.ReferenceFileFolders |> not + let getPlatformReferences frameworkIdentifier installModel = getLibReferences (SinglePlatform frameworkIdentifier) installModel @@ -358,7 +360,7 @@ type InstallModel with member this.MapFolders mapfn = InstallModel.mapFolders mapfn this - member this.MapFiles mapfn = InstallModel.mapFiles mapfn this + member this.MapFiles mapfn = InstallModel.mapFiles mapfn this member this.GetLibReferences target = InstallModel.getLibReferences target this @@ -376,6 +378,8 @@ type InstallModel with member this.AddLibReferences (libs, references) = InstallModel.addLibReferences libs references this + member this.HasLibReferences () = InstallModel.hasReferences this + member this.AddReferences libs = InstallModel.addLibReferences libs NuspecReferences.All this member this.AddAnalyzerFiles analyzerFiles = InstallModel.addAnalyzerFiles analyzerFiles this @@ -384,7 +388,7 @@ type InstallModel with member this.AddTargetsFiles targetsFiles = InstallModel.addTargetsFiles targetsFiles this - member this.AddPackageFile (path, file, references) = InstallModel.addPackageFile path file references this + member this.AddPackageFile (path, file, references) = InstallModel.addPackageFile path file references this member this.AddFrameworkAssemblyReference reference = InstallModel.addFrameworkAssemblyReference this reference diff --git a/src/Paket.Core/InstallProcess.fs b/src/Paket.Core/InstallProcess.fs index f353120bc9..74069d5242 100644 --- a/src/Paket.Core/InstallProcess.fs +++ b/src/Paket.Core/InstallProcess.fs @@ -282,7 +282,6 @@ let InstallIntoProjects(options : InstallerOptions, dependenciesFile, lockFile : for project, referenceFile in projectsAndReferences do verbosefn "Installing to %s" project.FileName - let usedPackages = referenceFile.Groups |> Seq.map (fun kv -> diff --git a/src/Paket.Core/ProjectFile.fs b/src/Paket.Core/ProjectFile.fs index a4c696442d..1a77358eb3 100644 --- a/src/Paket.Core/ProjectFile.fs +++ b/src/Paket.Core/ProjectFile.fs @@ -226,11 +226,6 @@ module ProjectFile = node.InnerText <- text node - - -// let createChildNode name text project = -// project |> addChild (createNodeSet name text project) - open System.Text let getPropertyWithDefaults propertyName defaultProperties (projectFile:ProjectFile) = @@ -845,11 +840,21 @@ module ProjectFile = while List.exists (fun x -> deleteIfEmpty x project) ["ItemGroup";"When";"Otherwise";"Choose"] do () + + let getTargetFrameworkIdentifier (project:ProjectFile) = getProperty "TargetFrameworkIdentifier" project + + let getTargetFrameworkProfile (project:ProjectFile) = getProperty "TargetFrameworkProfile" project + let updateReferences (completeModel: Map) (usedPackages : Map) hard (project:ProjectFile) = removePaketNodes project - + + let targetFramework = + match getProperty "TargetFrameworkVersion" project with + | None -> None + | Some v -> FrameworkDetection.Extract(v.Replace("v","net")) + completeModel |> Seq.filter (fun kv -> usedPackages.ContainsKey kv.Key) |> Seq.map (fun kv -> @@ -860,6 +865,14 @@ module ProjectFile = (snd kv.Value) .ApplyFrameworkRestrictions(installSettings.FrameworkRestrictions) .RemoveIfCompletelyEmpty() + + match targetFramework with + | Some targetFramework -> + if projectModel.GetLibReferences targetFramework |> Seq.isEmpty then + if projectModel.HasLibReferences() then + traceWarnfn "Package %O contains libraries, but not for the selected TargetFramework %O in project %s." + (snd kv.Key) targetFramework project.FileName + | None -> () let copyLocal = defaultArg installSettings.CopyLocal true let importTargets = defaultArg installSettings.ImportTargets true @@ -1036,11 +1049,7 @@ module ProjectFile = | _ -> ProjectOutputType.Library } |> Seq.head - let getTargetFrameworkIdentifier (project:ProjectFile) = getProperty "TargetFrameworkIdentifier" project - - let getTargetFrameworkProfile (project:ProjectFile) = getProperty "TargetFrameworkProfile" project - - let getTargetProfile (project:ProjectFile) = + let getTargetProfile (project:ProjectFile) = match getTargetFrameworkProfile project with | Some profile when profile = "Client" -> SinglePlatform (DotNetFramework FrameworkVersion.V4_Client) diff --git a/src/Paket/Paket.fsproj b/src/Paket/Paket.fsproj index 8c0b243bb2..6f3e5e2adc 100644 --- a/src/Paket/Paket.fsproj +++ b/src/Paket/Paket.fsproj @@ -38,7 +38,7 @@ pack output D:\code\paketbug\output install restore - pack output "out/nuget" version 0.9.3 releaseNotes "[LanguageExtensions][New] New Ensure methods with exception parameter." include-referenced-projects + update Project paket.exe c:\code\Paketkopie @@ -48,7 +48,7 @@ d:\code\paketrepro D:\code\Paket\integrationtests\scenarios\i001270-net461\temp C:\code\restore - D:\code\Journalist + D:\code\Paket\integrationtests\scenarios\i001442-warn-if-empty\temp pdbonly