How can I make my managed NuGet package support C++/CLI projects?

后端 未结 7 1735
暗喜
暗喜 2020-12-04 14:03

I have made a NuGet package that works well when I use it from a C# project. It contains a DLL in the lib/net40 directory, and the DLL gets added as a reference

7条回答
  •  感情败类
    2020-12-04 14:23

    There seem to be actually a possibility to enable "regular" NuGet packages to be installed and automatically referenced from C++/CLI projects using following steps (at least with NuGet >= 2.5):

    1. Add (or modify) a build\.targets file to your project to be packaged and put following content into it (make sure to replace with an actual value):

      
      
        
        
          
            
            
              $(MSBuildThisFileDirectory)..\lib\native\.dll
            
          
        
      
      
    2. In the .nuspec of the packaged project add one or more file entries to also place the assembly in lib\native\ directory at the target machine:

      
        
          ...
        
        
          ...
          
          
          
      
          
          
        
        ...
      
      

    Even if NuGet does not add assembly references to C++/CLI projects, it still inserts any .props and .targets files provided by a package. And the custom target from step 1 will add a reference to our packaged assembly.

    One drawback of this solution, as far as I could see it, is that the reference added in such a way is not displayed in the Commpon Properties/Framework and References section of the C++/CLI project. There may also be others, so use it at your own risk...

提交回复
热议问题