本文介绍了C++ 项目中 NuGet 包的 PackageReference的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我参与了一个项目,我们在 Visual Studioe 中将 packages.config 文件用于 NuGet 包,然后通过项目文件中的 Import 语句包含每个包依赖项.

I'm part of a project where we use packages.config files for NuGet packages in Visual Studioe and then include each package dependency through the Import statement in our project files.

如果您总是想要这些包,这可以正常工作,但是我们有一些条件包,如果开发人员不需要/不想要它,我们希望将其排除.我找到了 PackageReference标签,这将使依赖更加清晰,并让我们有条件地包含包.

This works fine if you always want the packages, but we have some conditional packages that we'd like to exclude if the developer doesn't need/want it. I found the PackageReference tag, that would make the dependency much cleaner and would let us include the packages conditionally.

C# 项目似乎完全支持它,但我不知道 C++ 项目是否支持它.

It seems to be fully supported in C# projects, but I can't figure out if it's supported for C++ projects or not.

我已尝试删除我们所有的 packages.config 文件并将所有引用替换为 PackageReference 标签,但 PackageReference 标签似乎没有被包管理器接收.我也尝试了所有我能找到的适用于 Visual Studio 的迁移工具",但没有运气.

I have tried deleting all of our packages.config files and replacing all references with PackageReference tags, but the PackageReference tag doesn't seem to be picked up by the package manager. I've gone through all the "migration tools" that I could find for Visual Studio too, with no luck.

是否可以将其用于 C++ 项目?如果没有,是否有一种解决方法可以让我有条件地排除某些包?

Is it possible to use it for C++ projects? If not, is there a workaround that lets me exclude certain packages conditionally?

我使用的是 Visual Studio Professional 15.6.7.

I'm using Visual Studio Professional 15.6.7.

推荐答案

目前,C++ 项目支持PackageReference.NuGet 团队正在评估它以支持未来版本.您可能已经通过一些技巧让它工作了,但是如果您创建一个新的 c++ 项目并尝试将此包安装为 PackageReference,它将不允许您.所以我建议你继续为你的 C++ 项目和库使用 packages.config.

At this moment, PackageReference is not yet supported for C++ projects. NuGet team is evaluating it to support for future releases. You might had made it work through some hacks but if you create a new c++ project and tries to install this package as PackageReference, it won't allow you. So I recommend you to continue using packages.config for your c++ projects and libraries.

此外,您可以在 Visual Studio UserVoice 站点上添加您对此功能的请求或投票:在vcxproj中使用PackageReference.当有足够的社区投票并为此反馈添加评论时,产品团队成员会认真对待此反馈.

Besides, you can add your request or vote for this feature on the Visual Studio UserVoice site: Use PackageReference in vcxproj. When there are enough communities vote and add comments for this feedback, the product team member will take this feedback seriously.

如果没有,是否有一种解决方法可以让我有条件地排除某些包?

您可以在自定义目标文件中包含条件引用,并将 dll 部署到包的 tools 文件夹中,这样 Nuget 不会自动将它们添加为引用.

You can include the conditional references in the custom targets file and deploy the dlls in the tools folder of the package so they are not added as references by Nuget automatically.

认证:NuGet 更新和条件参考

希望这会有所帮助.

这篇关于C++ 项目中 NuGet 包的 PackageReference的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-03 20:59