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

后端 未结 7 1739
暗喜
暗喜 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:45

    The answers above have issues with second-level dependencies (at least in my case on Visual Studio 2019).

    To solve the issue, I usually create an empty c# console application and reference all the packages there.

    Then I use this post build snippet to copy everything except the project main artifacts to a common store named packages in the solution folder.

      
        
          $(SolutionDir)\packages
        
    
        
          
        
    
        
        
    
        
    
        
          
        
    
        
    
      
    

    The whole packages folder is then deployed with a custom task in the c++/cli project.

    This solution is suitable if the referenced packages target AnyCPU otherwise some tinkering is necessary to use different folders for each processor architecture, and probably won't work.

    This solution is not elegant, however solves the purpose to reliable consume nuget packages (indirectly) from a c++/cli project.

    The plus of this solution with respected to other ones posted here, is that paths are not versioned, therefore c++/cli projects won't ever be changed during normal package upgrade.

提交回复
热议问题