到目前为止,我正在根据下载的框架使该标准库成为目标。例如,对于.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' 
 OR '$(TargetFramework)' == 'net471'
 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所述
如果您要更改的是versions >>,并且它们具有一定的共性,那么我可能会想做类似的事情:
<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)" /> </ItemGroup>
此: