I just had to do the same thing with IBM.EntityFrameworkCore
libraries (which use IBM.Data.DB2.Core
), here's how I got it to work.
Add RuntimeIdentifiers, otherwise the RuntimeIdentifier
variable will be empty for dependent projects:
<RuntimeIdentifiers>win-x64;osx-x64;linux-x64</RuntimeIdentifiers>
If RuntimeIdentifier
is set, use that to determine which package to install, otherwise just go based on the operating system. This way we can use dotnet build --runtime linux-x64
or Visual Studio to build.
<Choose>
<When Condition="$(RuntimeIdentifier) != ''">
<ItemGroup>
<PackageReference Condition="$(RuntimeIdentifier.StartsWith('win'))" Include="IBM.EntityFrameworkCore" Version="3.1.0.300" />
<PackageReference Condition="$(RuntimeIdentifier.StartsWith('osx'))" Include="IBM.EntityFrameworkCore-osx" Version="3.1.0.300" />
<PackageReference Condition="$(RuntimeIdentifier.StartsWith('linux'))" Include="IBM.EntityFrameworkCore-lnx" Version="3.1.0.300" />
</ItemGroup>
</When>
<Otherwise>
<ItemGroup>
<PackageReference Condition="$([MSBuild]::IsOSPlatform('Windows'))" Include="IBM.EntityFrameworkCore" Version="3.1.0.300" />
<PackageReference Condition="$([MSBuild]::IsOSPlatform('OSX'))" Include="IBM.EntityFrameworkCore-osx" Version="3.1.0.300" />
<PackageReference Condition="$([MSBuild]::IsOSPlatform('Linux'))" Include="IBM.EntityFrameworkCore-lnx" Version="3.1.0.300" />
</ItemGroup>
</Otherwise>
</Choose>
I also wanted to copy the license file from the project to the nuget directory:
<Target Condition="$([MSBuild]::IsOSPlatform('Windows'))" Name="PreBuildWin" BeforeTargets="BeforeBuild">
<Copy Condition="$(RuntimeIdentifier) == ''" SourceFiles="db2consv_is.lic" DestinationFolder="$(USERPROFILE)\.nuget\packages\ibm.data.db2.core\3.1.0.300\buildTransitive\clidriver\license" SkipUnchangedFiles="true" />
<Copy Condition="$(RuntimeIdentifier.StartsWith('win'))" SourceFiles="db2consv_is.lic" DestinationFolder="$(USERPROFILE)\.nuget\packages\ibm.data.db2.core\3.1.0.300\buildTransitive\clidriver\license" SkipUnchangedFiles="true" />
<Copy Condition="$(RuntimeIdentifier.StartsWith('osx'))" SourceFiles="db2consv_is.lic" DestinationFolder="$(USERPROFILE)\.nuget\packages\ibm.data.db2.core-osx\3.1.0.300\buildTransitive\clidriver\license" SkipUnchangedFiles="true" />
<Copy Condition="$(RuntimeIdentifier.StartsWith('linux'))" SourceFiles="db2consv_is.lic" DestinationFolder="$(USERPROFILE)\.nuget\packages\ibm.data.db2.core-lnx\3.1.0.300\buildTransitive\clidriver\license" SkipUnchangedFiles="true" />
</Target>
<Target Condition="$([MSBuild]::IsOSPlatform('OSX')) Or $([MSBuild]::IsOSPlatform('Linux'))" Name="PreBuildUnix" BeforeTargets="BeforeBuild">
<Copy Condition="$(RuntimeIdentifier) == '' And $([MSBuild]::IsOSPlatform('OSX'))" SourceFiles="db2consv_is.lic" DestinationFolder="$(HOME)\.nuget\packages\ibm.data.db2.core-osx\3.1.0.300\buildTransitive\clidriver\license" SkipUnchangedFiles="true" />
<Copy Condition="$(RuntimeIdentifier) == '' And $([MSBuild]::IsOSPlatform('Linux'))" SourceFiles="db2consv_is.lic" DestinationFolder="$(HOME)\.nuget\packages\ibm.data.db2.core-lnx\3.1.0.300\buildTransitive\clidriver\license" SkipUnchangedFiles="true" />
<Copy Condition="$(RuntimeIdentifier.StartsWith('win'))" SourceFiles="db2consv_is.lic" DestinationFolder="$(HOME)\.nuget\packages\ibm.data.db2.core\3.1.0.300\buildTransitive\clidriver\license" SkipUnchangedFiles="true" />
<Copy Condition="$(RuntimeIdentifier.StartsWith('osx'))" SourceFiles="db2consv_is.lic" DestinationFolder="$(HOME)\.nuget\packages\ibm.data.db2.core-osx\3.1.0.300\buildTransitive\clidriver\license" SkipUnchangedFiles="true" />
<Copy Condition="$(RuntimeIdentifier.StartsWith('linux'))" SourceFiles="db2consv_is.lic" DestinationFolder="$(HOME)\.nuget\packages\ibm.data.db2.core-lnx\3.1.0.300\buildTransitive\clidriver\license" SkipUnchangedFiles="true" />
</Target>
dotnet SDK used: 3.1.402