简体   繁体   中英

How to add shared C# NuGet dependencies to a C++/Cli project?

Context: A Visual Studio solution with 2 assemblies, Cs and Cpp.

  • Cs is a C# / .net45 dll
  • Cpp is a C++/Cli dll, a C++ dll compiled with /clr.

I have some dependencies that are pure C# projects from nuget.org. I use the original packages provided by the authors. Adding them to the Cs project works fine, but not to Cpp.

How can I add the C# package to the C++ project?

Since it's C++/Cli, I can easily use .net objects, and I use eg in the C++ library stuff from the C# library. But somehow nuget only allows me to select C# projects to add a C# dependency to, not C++ /clr ones.

In your C++/CLI project, just add a reference (Menu->References->Add New Reference->Browse->Browse...) to the nlog.dll that nuget downloads to your [solutionfolder]/packages/nlog... folder. That seems to work for me.

The way I've done it, is to make a "nugetmaster", which references all the nugets the other two projects will use. Build that one first, and reference the nuget assemblies manually within each project. Added bonus is to have more control on versions, only once place to update all other projects. And this scales well.

Another approach is similar to the one above - create a shared C# assembly used by them both, which also implements all the code using the nuget assemblies. And only expose wrappers.

Please refer to NuGet documentation especially the "-IncludeReferencedProjects" parameter.

"From a project" section; http://docs.nuget.org/docs/creating-packages/creating-and-publishing-a-package

Regards...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM