@@ -246,7 +246,7 @@ type DependenciesFile(fileName,groups:Map<GroupName,DependenciesGroup>, textRepr
246246 let packageString = DependenciesFileSerializer.packageString packageName versionRequirement resolverStrategy settings
247247
248248 // Try to find alphabetical matching position to insert the package
249- let isPackageInLastSource ( p : PackageRequirement ) =
249+ let isPackageInLastSource =
250250 match groups |> Map.tryFind groupName with
251251 | None -> true
252252 | Some group ->
@@ -256,12 +256,21 @@ type DependenciesFile(fileName,groups:Map<GroupName,DependenciesGroup>, textRepr
256256 let lastSource = Seq.last sources
257257 group.Sources |> Seq.exists ( fun s -> s = lastSource)
258258
259+ let sourceCount =
260+ match groups |> Map.tryFind groupName with
261+ | None -> 0
262+ | Some group ->
263+ match group.Sources with
264+ | [] -> 0
265+ | sources -> group.Sources |> Seq.length
266+
267+
259268 let smaller =
260269 match groups |> Map.tryFind groupName with
261270 | None -> []
262271 | Some group ->
263272 group.Packages
264- |> Seq.takeWhile ( fun ( p : PackageRequirement ) -> p.Name <= packageName || not ( isPackageInLastSource p ) )
273+ |> Seq.takeWhile ( fun ( p : PackageRequirement ) -> p.Name <= packageName || not isPackageInLastSource)
265274 |> List.ofSeq
266275
267276 let list = new System.Collections.Generic.List<_>()
@@ -287,7 +296,7 @@ type DependenciesFile(fileName,groups:Map<GroupName,DependenciesGroup>, textRepr
287296 list.Insert( pos + 1 , packageString)
288297 | None ->
289298 let firstGroupLine , lastGroupLine = findGroupBorders groupName
290- if pinDown then
299+ if pinDown || sourceCount > 1 then
291300 if newGroupInserted then
292301 list.Add( packageString)
293302 else
0 commit comments