microsoft / Azure-Kinect-Sensor-SDK

A cross platform (Linux and Windows) user mode SDK to read data from your Azure Kinect device.
https://Azure.com/Kinect
MIT License
1.49k stars 618 forks source link

Cannot reference Sensor SDK from .NET Class Library #894

Open dotMorten opened 4 years ago

dotMorten commented 4 years ago

Describe the bug Create a new .NET Standard Class Library, and you'll be prevented from referencing the SDK due to the class library being AnyCPU. This limitation should not be put on libraries but only on applications.

To Reproduce

  1. Create a new .NET Standard Class Library
  2. Add the Microsoft.Azure.Kinect.Sensor nuget package
  3. Notice the error in the output window:
1>C:\Users\mn\.nuget\packages\microsoft.azure.kinect.sensor\1.3.0\build\netstandard2.0\Microsoft.Azure.Kinect.Sensor.targets(4,5): error : Azure Kinect only supports the x86/x64 platform ('AnyCPU' not supported)
1>Done building project "Microsoft.Azure.Kinect.BodyTracking.csproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Expected behavior Check should only be done on applications, not libraries.

Suggested fix Change the targets file to also check on output type:

  <Target Name="EnsureAzureKinectPlatform" BeforeTargets="PrepareForBuild">
    <Error Condition="'$(Platform)' != 'x64' AND '$(Platform)' != 'x86' AND '$(OutputType)'!='Library'" Text="Azure Kinect only supports the x86/x64 platform ('$(Platform)' not supported)" />
  </Target>

Side note Since such a class library would transitively bring in the kinect sensor package, you should also add the same build files in the nuget package to /buildTransitive/ to ensure the .targets file are run on applications not directly referencing that nuget package.

Screenshots image

Desktop (please complete the following information):

Additional context

dotMorten commented 4 years ago

In addition referencing the project from a .NET Core WPF app, you'll hit a similar issue because it doesn't use the $(Platform) value, but relies on runtime identifiers instead.

Brent-A commented 4 years ago

Thanks. We should be publishing a new alpha after we complete #822 and I'll try integrating those suggestions to the NuGet release.

FYI, #822 adds some APIs to expose raw handle access that will make it possible to interop with the body tracking SDK.

vpenades commented 4 years ago

Is this still an issue? I thought it would be fixed for 1.4.0...

dotMorten commented 4 years ago

@qm13 Was this addressed?

qm13 commented 4 years ago

@dotMorten my bad. I believe this is still an issue.

tmoody460 commented 4 years ago

Any chance there's a workaround for this until this can get fixed?