jmmorato / openddsharp

OpenDDS wrapper for .NET languages
http://www.openddsharp.com
GNU Lesser General Public License v3.0
53 stars 12 forks source link

Cannot build nuget package to include the wrapper dll #172

Closed mellegge closed 1 year ago

mellegge commented 1 year ago

Visual Studio 2022, Windows 10 I build the getting started HelloWorld IDL project and two dll files are created - one of which is the wrapper DLL. I cannot build the HelloWorld project in VS because the code is looking for the Env Variable (set by the runtime parameter win-x64) when using the command line to build.

To generate the nuget package I have created another VS2022 project which references the MarshallHelper and the TypeSupport files from the HelloWorld project. When I build and package it sort of works. My consumer app can load the nuget package and see the Generated IDL types. However, when I try to run my consumer project it fails when looking for the wrapper dll. I tried adding the wrapper dll as a reference to my nuget package generator VS 2022 project but it complains it is an unsupported DLL. Sure enough when I look at the wrapper dll in JetBrains DotPeek it says it is unsupported.

so 1) What is this wrapper dll and why does VS complain it is unsupported? 2) Any suggestions how to create a nuget package that includes the main DLL and the wrapper DLL? 3) Alternatively how can I build the getting started app in VS? If I could do that then I could probably generate a nuget package from VS with the required files.

Not I have changed the traget framework to be net7.0 in al projects.

Thanks Mel

jmmorato commented 1 year ago
  1. What is this wrapper dll and why does VS complain it is unsupported?

It is a C library generated with the native OpenDDS code. As it is native dll and not a .Net assembly, it cannot be added directly to VS C# project

  1. Any suggestions how to create a nuget package that includes the main DLL and the wrapper DLL?

The main reference is included automatically if you are using ProjectReferences

For the native DLLs, you can see an example in the OpenDDSharp.Native project, change your dll path and remove the platforms you don't need:

<!-- Native dependency from this project. -->
    <ProjectNativeDepsReleasex64 Include="..\..\Native\build_x64\OpenDDSWrapper\Release\OpenDDSWrapper.dll" Visible="false" />
    <None Include="@(ProjectNativeDepsReleasex64)" Pack="true" PackagePath="runtimes\win-x64\native" Visible="false">
      <CopyToOutputDirectory Condition="('$(Configuration)|$(Platform)'=='Release|x64' And '$(OS)' == 'Windows_NT') Or '$(Configuration)|$(RuntimeIdentifier)'=='Release|win-x64'">PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory Condition="('$(Configuration)|$(Platform)'=='Release|x64' And '$(OS)' == 'Windows_NT') Or '$(Configuration)|$(RuntimeIdentifier)'=='Release|win-x64'">PreserveNewest</CopyToPublishDirectory>
    </None>

    <ProjectNativeDepsDebugx64 Include="..\..\Native\build_x64\OpenDDSWrapper\Debug\OpenDDSWrapper.dll" Visible="false" />
    <None Include="@(ProjectNativeDepsDebugx64)" Pack="false" Visible="false">
      <CopyToOutputDirectory Condition="('$(Configuration)|$(Platform)'=='Debug|x64' And '$(OS)' == 'Windows_NT') Or '$(Configuration)|$(RuntimeIdentifier)'=='Debug|win-x64'">PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory Condition="('$(Configuration)|$(Platform)'=='Debug|x64' And '$(OS)' == 'Windows_NT') Or '$(Configuration)|$(RuntimeIdentifier)'=='Debug|win-x64'">PreserveNewest</CopyToPublishDirectory>
    </None>

    <ProjectNativeDepsReleasex86 Include="..\..\Native\build_x86\OpenDDSWrapper\Release\OpenDDSWrapper.dll" Visible="false" />
    <None Include="@(ProjectNativeDepsReleasex86)" Pack="true" PackagePath="runtimes\win-x86\native" Visible="false">
      <CopyToOutputDirectory Condition="'$(Configuration)|$(Platform)'=='Release|x86' Or '$(Configuration)|$(RuntimeIdentifier)'=='Release|win-x86'">PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory Condition="'$(Configuration)|$(Platform)'=='Release|x86' Or '$(Configuration)|$(RuntimeIdentifier)'=='Release|win-x86'">PreserveNewest</CopyToPublishDirectory>
    </None>

    <ProjectNativeDepsDebugx86 Include="..\..\Native\build_x86\OpenDDSWrapper\Debug\OpenDDSWrapper.dll" Visible="false" />
    <None Include="@(ProjectNativeDepsDebugx86)" Pack="false" Visible="false">
      <CopyToOutputDirectory Condition="'$(Configuration)|$(Platform)'=='Debug|x86' Or '$(Configuration)|$(RuntimeIdentifier)'=='Debug|win-x86'">PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory Condition="'$(Configuration)|$(Platform)'=='Debug|x86' Or '$(Configuration)|$(RuntimeIdentifier)'=='Debug|win-x86'">PreserveNewest</CopyToPublishDirectory>
    </None>

    <None Include="..\..\Native\build_Linux\OpenDDSWrapper\libOpenDDSWrapper.so" Pack="true" PackagePath="runtimes/linux-x64/native" Visible="false">
      <CopyToOutputDirectory Condition="$([MSBuild]::IsOSPlatform('Linux'))">PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory Condition="$([MSBuild]::IsOSPlatform('Linux'))">PreserveNewest</CopyToPublishDirectory>
    </None>

    <None Include="..\..\Native\build_MacOS\OpenDDSWrapper\libOpenDDSWrapper.dylib" Pack="true" PackagePath="runtimes/osx-x64/native" Visible="false">
      <CopyToOutputDirectory Condition="$([MSBuild]::IsOSPlatform('OSX'))">PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory Condition="$([MSBuild]::IsOSPlatform('OSX'))">PreserveNewest</CopyToPublishDirectory>
    </None>
  </ItemGroup>
  1. Alternatively how can I build the getting started app in VS? If I could do that then I could probably generate a nuget package from VS with the required files.

Add <UseCurrentRuntimeIdentifier>true</UseCurrentRuntimeIdentifier> to your csproj to select your current platform runtime identifier, but that will not solve the native dll inclusion, just allow you to select the correct runtime when building with VS

mellegge commented 1 year ago

Thank you. I now have a working nuget package.