Desktop C# - Referencing Windows.Devices
Asked Answered
D

3

9

I am trying to create a classic desktop application for Windows 10 in C# that will be able to talk to BLE devices. I followed the instructions (Bluetooth 4.0 (low energy) API for windows desktop C# application) and added the tag to the project file

<TargetPlatformVersion>10.0.10156</TargetPlatformVersion>

and reloaded the project. I am given access to the Windows namespace only: references dialog

I don't know what I did in one of my testings, but once that list got populated with a whole lot of other namespaces, giving me the ability to check Windows.Devices namespace, which is essential for my project. I can now add the Windows.Devices via Recent option, but can not add any other namespace...

Do you guys have any idea what should I do to access the list of all Windows.x.y namespaces?

Dania answered 28/5, 2016 at 7:8 Comment(5)
You probably used a more correct platform version in that other project. 10.0.10156 is a beta version number. More correct would be 10.0.10240 (the first shipping version) or 10.0.10586 (the current version). You must have the corresponding SDK version installed on the machine. Look in the C:\Program Files (x86)\Windows Kits\10\Include directory.Aragonite
Tried with 10.0.10240, 10.0.10240.0 10.0.10586 and nothing.. only Windows appears in the list. Is the version 255.255.255.255 even ok?Dania
Update - I created a new project and adding C:\Program Files (x86)\Windows Kits\10\UnionMetadata\Windows.winmd and C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETCore\v4.5\System.Runtime.WindowsRuntime.dll allowed me to include Windows.Devices namespace without selecting Windows.Device in the References dialog.Dania
That worked for me as well - add this as answer ;)Agronomics
It worked for me too, 2 years after the post.Blossomblot
K
13

To access Windows.Devices and other WinRT API's from .NET Framework code,

  1. Add the NuGet package Microsoft.Windows.SDK.Contracts to the project
  2. Configure the project to support Package References (right-click packages.config, select Migrate packages.config to PackageReference...)
Katharinekatharsis answered 17/6, 2020 at 2:59 Comment(0)
B
3

From the OP's author comment:

Update - I created a new project and adding C:\Program Files (x86)\Windows Kits\10\UnionMetadata\Windows.winmd and C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETCore\v4.5\System.Runtime.WindowsRuntime.dll allowed me to include Windows.Devices namespace without selecting Windows.Device in the References dialog.

This worked for various of us.

Blossomblot answered 25/9, 2019 at 14:59 Comment(0)
L
2

There is now a Windows.SDK.Contracts NuGet package which helps with this issue. I wasn't able to add the above DLLs, but the nuget package worked.

The Windows 10 WinRT API Pack enables you to add the latest Windows Runtime APIs support to your .NET Framework 4.5+ and .NET Core 3.0+ libraries and apps.

This package includes all the supported Windows Runtime APIs up to Windows 10 version 1903.

Lonely answered 27/2, 2020 at 15:0 Comment(1)
thanks for the tip. ive seen this as a requirement in a few projects. now i know exactly what it is for. extremely useful.Estaminet

© 2022 - 2024 — McMap. All rights reserved.