1

I have a C++/CLI DLL that interfaces a third party native DLL. I want to pack this as Nuget.

I followed this official MS guide, this blog post and read through this other question.

So here is what I did:

First, I created the proper nuspec file:

<?xml version="1.0"?>
<package >
  <metadata>
    <id>CPlusPlusNativeIFace</id>
    <version>1.0.4</version>
    <title>CPlusPlusNativeIFace</title>
    <authors>Jens Rabe</authors>
    <owners>Who owns that</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>A DLL that makes a native third-party DLL available to .net</description>
    <releaseNotes>foo</releaseNotes>
    <copyright>errm...</copyright>
    <tags>foo bar</tags>
  </metadata>
  <files>
    <file src="..\Release\**" target="runtimes/win-x86/lib/net461" />
    <file src="..\x64\Release\**" target="runtimes/win-x64/lib/net461" />
    <file src="DummyAny\**" target="ref\net461" />
  </files>
</package>

Then I compiled the DLL for Release x86 and Release X64. Then I created the DummyAny folder, copied the contents of the x86 one in, and used the corflags utility like in Links 2 and 3 to strip the 32 bit flag.

When I now nuget pack and nuget add, and try to reference that package in another project, I always get:

Could not install package 'CPlusPlusNativeIFace 1.0.4'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.6.1', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.

I double checked that the files are right:

  • I have the x86 stuff in runtimes/win-x86/lib/net461
  • I have the x64 stuff in runtimes/win-x64/lib/net461
  • I have a ref/net461 folder with the manipulated dll in

But I still can't load the package.

I also tried putting the CPU specific DLLs into runtimes/win-x86/native and runtimes/win-x64/native to no avail.

What else am I missing? Does that not work for C++/CLI projects built against .net Framework?

rabejens
  • 7,594
  • 11
  • 56
  • 104

1 Answers1

3

Turned out that the official MS documentation was not usable here.

This question was/is listed as "related" here and the accepted answer there made it work for me. I used the example project on Github as a reference.

So here is how I got it to work:

  1. Opened the project properties, went to Configuration Properties / General, selected All Configurations and All Platforms, and as Output Directory, I specified: $(ProjectDir)bin\$(Platform)\$(Configuration)\
  2. Rebuilt the project for x86 and x64 in Release mode
  3. Adapted the Nuspec to be like this:
    <?xml version="1.0"?>
    <package >
    <metadata>
    <id>CPlusPlusNativeIFace</id>
    <version>1.0.5</version>
    <title>Third Party Proxy</title>
    <authors>Jens Rabe</authors>
    <owners>foo</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>bar</description>
    <releaseNotes>Further experimenting with nuget</releaseNotes>
    <copyright>baz moo</copyright>
    <tags>quux bletch</tags>
    </metadata>
    <files>
    <file src="bin\Win32\Release\**" target="build\x86" />
    <file src="bin\x64\Release\**" target="build\x64" />
    <file src="bin\Win32\Release\**" target="lib\net461" />
    <file src="CPlusPlusNativeIFace.props" target="build\net461" />
    </files>
    </package>
    
  4. Added a CPlusPlusNativeIFace.props which contains the following:
    <?xml version="1.0" encoding="utf-8"?>
    <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <ItemGroup>
    <Reference Include="CPlusPlusNativeIFace" Condition="'$(Platform)' == 'x86'">
      <HintPath>$(MSBuildThisFileDirectory)..\x86\CPlusPlusNativeIFace.dll</HintPath>
    </Reference>
    <Reference Include="CPlusPlusNativeIFace" Condition="'$(Platform)' == 'x64'">
      <HintPath>$(MSBuildThisFileDirectory)..\x64\CPlusPlusNativeIFace.dll</HintPath>
    </Reference>
    </ItemGroup>
    </Project>
    

Now I can do nuget pack CPlusPlusNativeIFace.nuspec and I get a Nuget package that installs correctly.

rabejens
  • 7,594
  • 11
  • 56
  • 104