Create NuGet package for C++/CLI (mixed) assembly

后端 未结 1 688
野性不改
野性不改 2021-02-08 08:24

I have created a C++/CLI (mixed) assembly which has a managed wrapper class around some unmanaged C++ code. The managed part targets .NET 4.6.1, I got a file entry.cpp

1条回答
  •  星月不相逢
    2021-02-08 09:01

    I don't know if this could still help you, but I've managed to pack both x64 and x86 C++ code, and a C# wrapper that was compiled on AnyCPU.

    On My C# project, I have two Platforms: "x86" and "x64".

    On my Nuget folder, I have the following structure:

    \Project
        \Project.1.0.nuspec
        \build
            \x64
                \*.dll
                \*.pdb
            \x86
                \*.dll
                \*.pdb
            \Project.targets
        \lib
            \net452
                \Wrapper.dll
                \Wrapper.pdb
    

    Project.nuspec:

    
    
        
            Project
            1.0
            nilsonneto
            nilsonneto
            false
            Example.
            
                
            
        
        
            
    
            
            
    
            
            
        
    
    

    Project.targets:

    
    
     
        
        
          %(RecursiveDir)%(FileName)%(Extension)
          PreserveNewest
        
      
    
    

    Notice the $(Platform), which is where the name of the Platform being build on Visual Studio will be placed, which is why I separated the C++ DLLs in folders with the same name as the Platforms in Visual Studio.

    And according to the documentation (https://docs.microsoft.com/en-us/nuget/create-packages/native-packages), all native DLLs have to be placed in the \build directory.

    Native NuGet packages targeting native then provide files in \build, \content, and \tools folders; \lib is not used in this case (NuGet cannot directly add references to a C++ project). A package may also include targets and props files in \build that NuGet will automatically import into projects that consume the package. Those files must be named the same as the package ID with the .targets and/or .props extensions.

    So, just adjust the folder names based on the Platforms you support on the .NET project and your set.

    0 讨论(0)
提交回复
热议问题