作为Patrick O'Hara wrote,NuGet不会为您更改C++/CLI项目.见GitHub Issue NuGet/Home#1121 - Cannot install managed packages into a CLI project.但是,使用NuGet命令行实用程序NuGet.exe
,可以让NuGet下载并解压缩所需的包.
下面是我在Visual Studio 2013 C++/CLI项目中添加对OptimizedPriorityQueue 1.0.0的引用的完整示例:
- Open the Package Manager Console if not already open (TOOLS > NuGet Package Manager > Package Manager Console).
在Package Manager控制台中,安装NuGet.命令行包:
Install-Package NuGet.CommandLine
(注:在 compose 本文时,NuGet.CommandLine的最新版本是2.8.6.对你来说可能会有所不同.)
在项目文件夹中,现在应该有一个包含以下内容的.nuget\packages.config
XML文件:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NuGet.CommandLine" version="2.8.6" />
</packages>
在文本编辑器(如Notepad++)中,为所需的包添加<package>
元素.在这种情况下,我补充说:
<package id="OptimizedPriorityQueue" version="1.0.0" />
..在<packages>
元素内.
打开命令提示符(我打开了VS2013开发人员命令提示符,但常规命令提示符应该可以.)
cd
添加到项目文件夹中.
运行以下命令,更改NuGet的版本号.命令行(如果不同):
.\packages\NuGet.CommandLine.2.8.6\tools\NuGet.exe Install -NonInteractive -OutputDirectory packages .nuget\packages.config
对我来说,结果是:
Installing 'OptimizedPriorityQueue 1.0.0.0'.
Successfully installed 'OptimizedPriorityQueue 1.0.0.0'.
All packages listed in packages.config are already installed.
- Right click on the project in Visual Studio and select Properties. Under Common Properties > References, click the Add New Reference… button.
- Select Browse on the left hand side. Next to the Add Reference dialog's OK and Cancel buttons, there is a Browse… button. Click that to open a file selection dialog.
- 导航到要解压缩到项目文件夹
packages
子目录的DLL,然后单击Add按钮.单击OK关闭"添加引用"对话框.
现在您应该能够在C++/CLI项目中使用该程序集:
using namespace Priority_Queue;
//...