基于操作系统的不同NuGet软件包 [英] Different NuGet package based on operating system

查看:53
本文介绍了基于操作系统的不同NuGet软件包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在dotnet 2.1中有一个测试项目,该项目需要跨多个平台(特别是基于Windows和Linux的系统)工作,并且需要访问DB2数据库.

I have a test project in dotnet 2.1 that needs to work across multiple platforms (specifically, windows and linux-based systems) as well as access DB2 databases.

IBM为不同的操作系统提供了单独的NuGet软件包:

IBM provides separate NuGet packages for different operating systems:

  1. IBM.Data.DB2.Core
  2. IBM.Data.DB2.Core-lnx
  3. IBM.Data.DB2.Core-osx

如何在我的 .csproj 文件中指定要基于操作系统使用不同的软件包?

How can I specify in my .csproj file that I want to use different packages based on the operating system?

可以传入 RuntimeIdentifier ( dotnet publish ... -r linux-x64 ),但是我不确定如何在中利用该信息csproj .我也不反对使用 Choose/When 构造,但是不知道如何推断哪个系统正在尝试构建项目.

Passing in the RuntimeIdentifier (dotnet publish ... -r linux-x64) is possible, but I am unsure how to leverage that information inside the csproj. I am also not opposed to using the Choose/When construct, but don't know how to infer what system is trying to build the project.

推荐答案

我最终使用了 Configuration Choose/When 范式.

一个简单的示例 .csproj

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netcoreapp2.1</TargetFramework>
    <Configurations>Debug;Release;Docker</Configurations>
    <Platforms>AnyCPU;x64</Platforms>
  </PropertyGroup>

  ... the rest of your .csproj and dependencies ...

  <Choose>
    <When Condition=" '$(Configuration)'=='Docker' ">
      <ItemGroup>
        <PackageReference Include="IBM.Data.DB2.Core-lnx" Version="1.2.2.100" />
      </ItemGroup>
    </When>
    <Otherwise>
      <ItemGroup>
        <PackageReference Include="IBM.Data.DB2.Core" Version="1.2.2.100" />
      </ItemGroup>
    </Otherwise>
  </Choose>

</Project>

在命令行上,我将运行: dotnet build/your/project.csproj -c< yourConfigurationName> .

On the command line I would run: dotnet build /your/project.csproj -c <yourConfigurationName>.

我发现此网站有助于在视觉上进行设置Studio 2017.

I found this site useful for helping set this up in visual studio 2017.

这篇关于基于操作系统的不同NuGet软件包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆