gpt4 book ai didi

c# - 如何为一个库定位多个框架

转载 作者:行者123 更新时间:2023-11-30 21:26:31 25 4
gpt4 key购买 nike

我正在根据下载的框架使这个标准库成为目标。例如,对于 .NET Core,它将下载适用于 .NET Core 的包

 <!--Trageting .NET CORE (2.1, 3.0) && .NET STANDARD (2.0,2.1) -->
<ItemGroup Condition="$(TargetFramework.StartsWith('netcore')) OR $(TargetFramework.StartsWith('netstandard')) ">
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.7" />
<!--<PackageReference Include="Microsoft.AspNet.WebApi.Core" Version="5.2.7" />-->
<PackageReference Include="NLog.Extensions.Logging" Version="1.6.1" />
<PackageReference Include="NLog.WindowsEventLog" Version="4.6.7" />
<PackageReference Include="System.Diagnostics.EventLog" Version="4.6.0" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.6.0" />
<PackageReference Include="System.Data.SqlClient" Version="4.7.0" />
<PackageReference Include="System.Linq" Version="4.3.0" />
<PackageReference Include="Microsoft.Win32.Registry" Version="4.6.0" />
</ItemGroup>

<!--Targeting .NET FRAMEWORK (4.6.1 4.6.2) -->
<ItemGroup Condition="'$(TargetFramework)' == 'net461' OR '$(TargetFramework)' == 'net462'">
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
<PackageReference Include="Microsoft.AspNet.WebApi.Client" version="5.2.3" />
<PackageReference Include="Microsoft.AspNet.WebApi.Core" version="5.2.3" />
<PackageReference Include="NLog.Extensions.Logging" Version="1.5.4" />
<PackageReference Include="NLog.WindowsEventLog" Version="4.6.7" />
<PackageReference Include="System.Diagnostics.EventLog" Version="4.5.0" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.5.0" />
<PackageReference Include="System.Data.SqlClient" Version="4.6.1" />
<PackageReference Include="System.Linq" Version="4.3.0" />
<PackageReference Include="Microsoft.Win32.Registry" Version="4.5.0" />
</ItemGroup>

<!--Targeting .NET FRAMEWORK (4.7, 4.7.1, 4.7.2)-->
<ItemGroup Condition="'$(TargetFramework)' == 'net47' &#xD;&#xA; OR '$(TargetFramework)' == 'net471'&#xD;&#xA; OR '$(TargetFramework)' == 'net472'">
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
<PackageReference Include="Microsoft.AspNet.WebApi.Client" version="5.2.3" />
<PackageReference Include="Microsoft.AspNet.WebApi.Core" version="5.2.3" />
<PackageReference Include="NLog.Extensions.Logging" Version="1.5.4" />
<PackageReference Include="NLog.WindowsEventLog" Version="4.6.7" />
<PackageReference Include="System.Diagnostics.EventLog" Version="4.5.0" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.5.0" />
<PackageReference Include="System.Data.SqlClient" Version="4.6.1" />
<PackageReference Include="System.Linq" Version="4.3.0" />
<PackageReference Include="Microsoft.Win32.Registry" Version="4.5.0" />
</ItemGroup>

有没有更好的方法来完成上面提到的代码,比如使用 DefineConstants?

最佳答案

如果您想要更改的是具有一定共性的版本,那么我可能会想做类似的事情:

<PropertyGroup>
<VersionWebApiClient>5.2.3</VersionWebApiClient>
<VersionWebApiClient Condition="...todo...">5.2.7</VersionWebApiClient>
<!-- ... for the other things ... -->
<PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="$(VersionWebApiClient)" />
<!-- ... for the other things ... -->
</ItemGroup>

这个:

  1. 允许最常见的值是简单的默认值
  2. 允许明确覆盖每个目标框架
  3. 不重复实际的包引用

关于c# - 如何为一个库定位多个框架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59156790/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com