@@ -19,8 +19,8 @@ let checkTargetFrameworkCondition msbuildCondition (itemGroup: XElement) =
19
19
let checkTargetFrameworkNoRestriction itemGroup =
20
20
checkTargetFrameworkCondition " " itemGroup
21
21
22
- let checkTargetFrameworkRestriction r itemGroup =
23
- let msbuildCond = r |> Paket.Requirements.getExplicitRestriction |> fun c -> c.ToMSBuildCondition ()
22
+ let checkTargetFrameworkRestriction rc r itemGroup =
23
+ let msbuildCond = r |> Paket.Requirements.getExplicitRestriction |> fun c -> PlatformMatching.getCondition rc c.RepresentedFrameworks
24
24
checkTargetFrameworkCondition ( sprintf " AND (%s )" msbuildCond) itemGroup
25
25
26
26
let checkContainsPackageRefs pkgRefs ( group : XElement ) =
@@ -186,11 +186,127 @@ group Other1
186
186
match itemGroups with
187
187
| [ groupMain; otherGroup] ->
188
188
groupMain
189
- |> checkTargetFrameworkRestriction lockFile.Groups.[ Constants.MainDependencyGroup]. Options.Settings.FrameworkRestrictions
189
+ |> checkTargetFrameworkRestriction lockFile.Groups.[ Constants.MainDependencyGroup]. Options.Settings.ReferenceCondition lockFile.Groups .[ Constants.MainDependencyGroup ]. Options.Settings. FrameworkRestrictions
190
190
groupMain
191
191
|> checkContainsPackageRefs [ " FSharp.Core" , " 3.1.2.5" ; " Argu" , " 4.2.1" ]
192
192
otherGroup
193
- |> checkTargetFrameworkRestriction lockFile.Groups.[ Domain.GroupName " Other1" ]. Options.Settings.FrameworkRestrictions
193
+ |> checkTargetFrameworkRestriction lockFile.Groups.[ Domain.GroupName " Other1" ]. Options.Settings.ReferenceCondition lockFile.Groups.[ Domain.GroupName " Other1" ]. Options.Settings.FrameworkRestrictions
194
+ otherGroup
195
+ |> checkContainsPackageRefs [ " FSharp.Core" , " 4.3.4" ; " FsCheck" , " 2.8.2" ]
196
+ | l ->
197
+ Assert.Fail( sprintf " expected two ItemGroup but was '%A '" l)
198
+
199
+ [<Test>]
200
+ let ``should create props file for design mode with group conditions`` () =
201
+
202
+ let lockFile = """ CONDITION: COND_MAIN
203
+ NUGET
204
+ remote: https://api.nuget.org/v3/index.json
205
+ Argu (4.2.1)
206
+ FSharp.Core (>= 3.1.2)
207
+ FSharp.Core (3.1.2.5)
208
+
209
+ GROUP Other1
210
+ CONDITION: COND_OTHER1
211
+ NUGET
212
+ remote: https://api.nuget.org/v3/index.json
213
+ FsCheck (2.8.2)
214
+ FSharp.Core (>= 3.1.2.5)
215
+ FSharp.Core (4.3.4)
216
+ """
217
+
218
+ let refFileContent = """
219
+ FSharp.Core
220
+ Argu
221
+
222
+ group Other1
223
+ FSharp.Core
224
+ FsCheck
225
+ """
226
+
227
+ let lockFile = LockFile.Parse( " " , toLines lockFile)
228
+
229
+ let refFile = ReferencesFile.FromLines( toLines refFileContent)
230
+
231
+ let packages =
232
+ [ for kv in refFile.Groups do
233
+ let packagesInGroup , _ = lockFile.GetOrderedPackageHull( kv.Key, refFile)
234
+ yield ! packagesInGroup ]
235
+
236
+ let outPath = System.IO.Path.GetTempFileName()
237
+ Paket.RestoreProcess.createPaketPropsFile lockFile Seq.empty packages ( FileInfo outPath)
238
+
239
+ let doc = XDocument.Load( outPath, LoadOptions.PreserveWhitespace)
240
+
241
+ let itemGroups = doc.Root.Elements ( xname " ItemGroup" ) |> Seq.toList
242
+
243
+ match itemGroups with
244
+ | [ groupMain; otherGroup] ->
245
+ groupMain
246
+ |> checkTargetFrameworkRestriction lockFile.Groups.[ Constants.MainDependencyGroup]. Options.Settings.ReferenceCondition lockFile.Groups.[ Constants.MainDependencyGroup]. Options.Settings.FrameworkRestrictions
247
+ groupMain
248
+ |> checkContainsPackageRefs [ " FSharp.Core" , " 3.1.2.5" ; " Argu" , " 4.2.1" ]
249
+ otherGroup
250
+ |> checkTargetFrameworkRestriction lockFile.Groups.[ Domain.GroupName " Other1" ]. Options.Settings.ReferenceCondition lockFile.Groups.[ Domain.GroupName " Other1" ]. Options.Settings.FrameworkRestrictions
251
+ otherGroup
252
+ |> checkContainsPackageRefs [ " FSharp.Core" , " 4.3.4" ; " FsCheck" , " 2.8.2" ]
253
+ | l ->
254
+ Assert.Fail( sprintf " expected two ItemGroup but was '%A '" l)
255
+
256
+ [<Test>]
257
+ let ``should create props file for design mode with group restrictions and conditions`` () =
258
+
259
+ let lockFile = """ CONDITION: COND_MAIN
260
+ RESTRICTION: && (>= net461) (< net47)
261
+ NUGET
262
+ remote: https://api.nuget.org/v3/index.json
263
+ Argu (4.2.1)
264
+ FSharp.Core (>= 3.1.2)
265
+ FSharp.Core (3.1.2.5)
266
+
267
+ GROUP Other1
268
+ CONDITION: COND_OTHER1
269
+ RESTRICTION: == netstandard2.0
270
+ NUGET
271
+ remote: https://api.nuget.org/v3/index.json
272
+ FsCheck (2.8.2)
273
+ FSharp.Core (>= 3.1.2.5)
274
+ FSharp.Core (4.3.4)
275
+ """
276
+
277
+ let refFileContent = """
278
+ FSharp.Core
279
+ Argu
280
+
281
+ group Other1
282
+ FSharp.Core
283
+ FsCheck
284
+ """
285
+
286
+ let lockFile = LockFile.Parse( " " , toLines lockFile)
287
+
288
+ let refFile = ReferencesFile.FromLines( toLines refFileContent)
289
+
290
+ let packages =
291
+ [ for kv in refFile.Groups do
292
+ let packagesInGroup , _ = lockFile.GetOrderedPackageHull( kv.Key, refFile)
293
+ yield ! packagesInGroup ]
294
+
295
+ let outPath = System.IO.Path.GetTempFileName()
296
+ Paket.RestoreProcess.createPaketPropsFile lockFile Seq.empty packages ( FileInfo outPath)
297
+
298
+ let doc = XDocument.Load( outPath, LoadOptions.PreserveWhitespace)
299
+
300
+ let itemGroups = doc.Root.Elements ( xname " ItemGroup" ) |> Seq.toList
301
+
302
+ match itemGroups with
303
+ | [ groupMain; otherGroup] ->
304
+ groupMain
305
+ |> checkTargetFrameworkRestriction lockFile.Groups.[ Constants.MainDependencyGroup]. Options.Settings.ReferenceCondition lockFile.Groups.[ Constants.MainDependencyGroup]. Options.Settings.FrameworkRestrictions
306
+ groupMain
307
+ |> checkContainsPackageRefs [ " FSharp.Core" , " 3.1.2.5" ; " Argu" , " 4.2.1" ]
308
+ otherGroup
309
+ |> checkTargetFrameworkRestriction lockFile.Groups.[ Domain.GroupName " Other1" ]. Options.Settings.ReferenceCondition lockFile.Groups.[ Domain.GroupName " Other1" ]. Options.Settings.FrameworkRestrictions
194
310
otherGroup
195
311
|> checkContainsPackageRefs [ " FSharp.Core" , " 4.3.4" ; " FsCheck" , " 2.8.2" ]
196
312
| l ->
@@ -243,17 +359,17 @@ group Other2
243
359
match itemGroups with
244
360
| [ groupMain; otherGroup20And21; otherGroupOnly21] ->
245
361
groupMain
246
- |> checkTargetFrameworkRestriction lockFile.Groups.[ Constants.MainDependencyGroup]. Options.Settings.FrameworkRestrictions
362
+ |> checkTargetFrameworkRestriction lockFile.Groups.[ Constants.MainDependencyGroup]. Options.Settings.ReferenceCondition lockFile.Groups .[ Constants.MainDependencyGroup ]. Options.Settings. FrameworkRestrictions
247
363
groupMain
248
364
|> checkContainsPackageRefs [ " FSharp.Core" , " 3.1.2.5" ; " Argu" , " 4.2.1" ]
249
365
250
366
otherGroup20And21
251
- |> checkTargetFrameworkRestriction lockFile.Groups.[ Domain.GroupName " Other2" ]. Options.Settings.FrameworkRestrictions
367
+ |> checkTargetFrameworkRestriction lockFile.Groups.[ Domain.GroupName " Other2" ]. Options.Settings.ReferenceCondition lockFile.Groups .[ Domain.GroupName " Other2 " ]. Options.Settings. FrameworkRestrictions
252
368
otherGroup20And21
253
369
|> checkContainsPackageRefs [ " FSharp.Core" , " 4.3.4" ]
254
370
255
371
otherGroupOnly21
256
- |> checkTargetFrameworkRestriction lockFile.Groups.[ Domain.GroupName " Other2" ]. Resolution.[ Domain.PackageName " FsCheck" ]. Settings.FrameworkRestrictions
372
+ |> checkTargetFrameworkRestriction lockFile.Groups.[ Domain.GroupName " Other2" ]. Options.Settings.ReferenceCondition lockFile.Groups .[ Domain.GroupName " Other2 " ]. Resolution.[ Domain.PackageName " FsCheck" ]. Settings.FrameworkRestrictions
257
373
otherGroupOnly21
258
374
|> checkContainsPackageRefs [ " FsCheck" , " 2.8.2" ]
259
375
| l ->
@@ -286,11 +402,11 @@ Newtonsoft.Json
286
402
let doc = XDocument.Load( outPath, LoadOptions.PreserveWhitespace)
287
403
288
404
let itemGroups = doc.Root.Elements ( xname " ItemGroup" ) |> Seq.toList
289
-
405
+
290
406
match itemGroups with
291
407
| [ groupMain] ->
292
408
groupMain
293
- |> checkTargetFrameworkRestriction lockFile.Groups.[ Constants.MainDependencyGroup]. Resolution.[ Domain.PackageName " Newtonsoft.Json" ]. Settings.FrameworkRestrictions
409
+ |> checkTargetFrameworkRestriction lockFile.Groups.[ Constants.MainDependencyGroup]. Options.Settings.ReferenceCondition lockFile.Groups .[ Constants.MainDependencyGroup ]. Resolution.[ Domain.PackageName " Newtonsoft.Json" ]. Settings.FrameworkRestrictions
294
410
groupMain
295
411
|> checkContainsPackageRefs [ " Newtonsoft.Json" , " 11.0.2" ]
296
412
| l ->
0 commit comments