msbuild - 如何在 MSBuild 中获取已安装 nuget 的版本?
问题描述
我必须显示特定于用户版本的错误消息(根据当前安装的 nuget 版本,哪些功能不起作用)。
有没有办法通过 MSBuild 检测特定 nuget 包正在使用的版本?
我知道一种在文件系统中搜索 DLL 并检测版本的方法,但这似乎不是干净的解决方案。有什么开箱即用的吗?
解决方案
有一个目标可用于这样的自定义,它以前是 1.* 中构建的一部分,但仍然存在兼容性:ResolvePackageDependencies
.
您可以像这样在 msbuild 中使用它:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.*" />
<PackageReference Include="DasMulli.Win32.ServiceUtils" Version="*" />
</ItemGroup>
<Target Name="PrintPackageReferences" DependsOnTargets="RunResolvePackageDependencies">
<Message Text="Dependencies:%0A @(PackageDefinitions->'%(Name), Version: %(Version)', '%0A ')" Importance="High" />
</Target>
</Project>
哪个(在撰写本文时)产生:
> dotnet msbuild -restore -t:PrintPackageReferences -nologo
Restore completed in 14.56 ms for C:\demos\testcons\testcons.csproj.
Dependencies:
DasMulli.Win32.ServiceUtils, Version: 1.2.0
Newtonsoft.Json, Version: 12.0.2
推荐阅读
- pygame - Pygame Midi libasound_module_conf_pulse.so 错误 + 无法打开从站
- sql - SQL Server:从另一个 CTE 查询中获取 DISTINCT TOP 列表
- android - Android LocationListener,onStatusChanged 和 onProviderDisabled 上的 AbstractMethodError
- r - Rstudio:找不到对象
- java - Oracle 的 MyBatis 查询中的两个删除?
- javascript - 单击锚点后如何关闭汉堡菜单
- python - OOP 设计问题 - 'postulantet' 对象没有属性 'tabla_postulante'
- python - 如何将表名格式化为 SQLite CREATE TABLE?
- admob - 我可以给用户奖励视频积分吗
- php - 如果用户从购物车中删除商品,如何运行功能?