简体   繁体   中英

How to add a Reference to the Windows.ApplicationModel.DataTransfer namespace in Visual Studio 2019 on Windows 10 PRO

Windows 10 Pro, Visual Studio 2019, .Net version 4.8.03752 (Clean installation of everything a few days ago).

I'm trying to add the Windows.ApplicationModel.DataTransfer namespace to my C# project in Visual Studio 2019 (free edition). I cannot find anything to add under References->Add References->Assemblies.

The documentation for ClipboardContentOptions states that the dll is Windows.ApplicationModel.DataTransfer.dll so I search for the dll and find versions in

C:\\Windows\\System32 (799Kb) C:\\Windows\\SysWOW64 (566Kb),

I attempt to add these dlls via References->AddReference->Browse and in both cases get the error

A Reference to <path to dll> could not be added. Please make sure that the file is accessible and that it is a valid assembly or COM component

What's going on here and how do I add a Reference to this namespace?

Thanks in advance.

Windows.ApplicationModel.DataTransfer is a WinRT API namespace. The easiest way to gain access to these namespaces is to add the Microsoft.Windows.SDK.Contracts NuGet package as follows:

  1. Open your project/solution in Visual Studio.

  2. Ensure you are targeting .NET Framework 4.6.1+ or .NET Core 3.0+ per NuGet package requirements.

  3. Convert any old package.config references in your project to the newer PackageReference format, by right-clicking the package.config reference and clicking Migrate package.config to PackageReference .

  4. In Solution Explorer, right-click References then click Manage NuGet References.

  5. Click the Browse heading then type Microsoft.Windows.SDK.Contracts into the search box.

  6. Click the Microsoft.Windows.SDK.Contracts (trusted by Microsoft) package then click the Install button on the right.

Alternatively, you can add a reference to Windows.winmd from the appropriate SDK folder typically located at C:\\Program Files (x86)\\Windows Kits\\10\\UnionMetadata .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM