.NET Core SDKというかnew fsprojになってから、以下のような依存関係を書く機会によく遭遇する。
<ItemGroup Condition="'$(TargetFramework)'=='net45'"> <PackageReference Include="FSharp.Core" Version="3.1.2.5" /> </ItemGroup> <ItemGroup Condition="'$(TargetFramework)'=='netstandard1.6'"> <PackageReference Include="FSharp.Core" Version="4.1.18" /> </ItemGroup>
古い環境ではなるべく最低ラインのバージョンを指定しつつ、netstandardでは比較的新しめのバージョンを指定するというもの。 ただこの書き方は現時点のVS2017だとちゃんと認識されないので困った。
というわけでこれと同等の書き方をPaketで再現させる。
まずはpaket.dependenciesを用意。
framework: netstandard1.6 source https://api.nuget.org/v3/index.json nuget FSharp.Core >= 4.1.18 lowest_matching:true group Legacy framework: net45 source https://api.nuget.org/v3/index.json nuget FSharp.Core >= 3.1.2.5 lowest_matching:true
framework targetごとにグループをわけておく。 これで異なるバージョンの、最も小さいバージョンが指定できる。
paket.reference側では次のように記述する。
FSharp.Core group Legacy FSharp.Core
二つのグループについて依存関係を追加している。 これで、frameworkごとに異なるバージョンを指定できる。 この方法だとVS2017も正しく依存関係を認識する。
ちなみにpaket.templateでは、以下のようにLOCKEDVERSION-グループ名で記述する。
dependencies
framework: net45
FSharp.Core >= LOCKEDVERSION-Legacy
framework: netstandard1.6
FSharp.Core >= LOCKEDVERSION