microsoft / MixedReality-HolographicRemoting-Samples

Code samples for using Microsoft's Holographic Remoting library.
Other
141 stars 47 forks source link

Nuget packages can't easily be used from managed projects #77

Closed dfields-msft closed 8 months ago

dfields-msft commented 1 year ago

Describe the bug When consuming either of the Holographic App Remoting packages (i.e. Windows/OpenXR) from a managed project, the native binaries are not copied to the output directory properly. Note that the Windows package can be used from C# with CSWinRT, and the OpenXR package can be used from C# with Silk.NET (with some manual bindings for the Remoting extensions...). For dotnet to deploy the native binaries auto-magically, the package should provide the following layout (similarly for other architectures/runtime-identifiers as needed):

runtimes/win-x64/native/... <-- desktop binaries go here runtimes/win10-x64/nativeassets/uap10.0/... <-- UWP binaries go here

Note, Remoting + StereoKit is a tasty combo, and can be easily used by simply referencing https://www.nuget.org/packages/StereoKit.HolographicRemoting!

To Reproduce

  1. dotnet new console
  2. dotnet add package Microsoft.Holographic.AppRemoting
  3. dotnet add package Microsoft.Windows.CsWinRT
  4. Add the following to Program.cs:
    using var context = Microsoft.Holographic.AppRemoting.RemoteContext.Create();
  5. Make the following required changes to the .csproj:
    1. Change TargetFramework to net7.0-windows10.0.19041.0
    2. Add property CsWinRTIncludes with value Microsoft.Holographic.AppRemoting
  6. Make the following accomodations to the .csproj to enable the current Remoting nuget package (arguably, the nuget package should handle this automatically too...):
    1. Add GeneratePathProperty="true" to the PackageReference for the Remoting package (only needed to support the next step)
    2. Add the following snippet to reference the .winmd:
      <ItemGroup>
      <Reference Include="$(PkgMicrosoft_Holographic_Remoting)\build\native\include\10.0.19041.0\Microsoft.Holographic.AppRemoting.winmd">
      <Implementation>Microsoft.Holographic.AppRemoting.dll</Implementation>
      </Reference>
      </ItemGroup>
  7. dotnet run

Expected: Program runs and prints "Hello, world!" Actual: "Class not registered" exception thrown since CsWinRT can't find the native dll.

Workaround To work around this, the following snippet can be used, but it's limited to hard-coding a single architecture (dotnet knows how to dynamically select the proper native binaries for the current architecture from the nuget package at runtime):

<ItemGroup>
  <Content Include="$(PkgMicrosoft_Holographic_Remoting)\build\native\bin\x64\Desktop\*.dll">
    <Link>%(Filename)%(Extension)</Link>
    <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
  </Content>
</ItemGroup>
chairobl commented 8 months ago

Hi @dfields-msft, since the issue was inactive for some time now I'd be closing it. If it is still relevant feel free to reopen it :)