As Patrick O’Hara wrote, NuGet will not make changes to a C++/CLI project for you. See GitHub Issue NuGet/Home#1121 – Cannot install managed packages into a CLI project. However, using the NuGet command line utility, NuGet.exe
, you can have NuGet download and unpack the desired package(s).
For a complete example, here were steps that I took to add a reference to OptimizedPriorityQueue 1.0.0 in a Visual Studio 2013 C++/CLI project:
- Open the Package Manager Console if not already open (TOOLS > NuGet Package Manager > Package Manager Console).
-
In the Package Manager Console, install the NuGet.CommandLine package:
Install-Package NuGet.CommandLine
(Note: As of this writing, the latest version of NuGet.CommandLine is 2.8.6. It may be different for you.)
-
Within your project folder, there should now be a
.nuget\packages.config
XML file with the following contents:<?xml version="1.0" encoding="utf-8"?> <packages> <package id="NuGet.CommandLine" version="2.8.6" /> </packages>
-
In a text editor such as Notepad++, add a
<package>
element for the desired package. In this case, I added:<package id="OptimizedPriorityQueue" version="1.0.0" />
.. within the
<packages>
element. -
Open a command prompt (I opened a VS2013 Developer Command Prompt, but a regular command prompt should work.)
cd
into the project folder.-
Run the following command, changing the version number of NuGet.CommandLine if different:
.\packages\NuGet.CommandLine.2.8.6\tools\NuGet.exe Install -NonInteractive -OutputDirectory packages .nuget\packages.config
For me, the output was:
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.
- Navigate to the DLLs that NuGet unpacked to the
packages
subdirectory of your project folder and click the Add button. Click OK to close the Add Reference dialog. -
You should now be able to use the assembly in your C++/CLI project:
using namespace Priority_Queue; //...