简体   繁体   English

如何在 Windows 10 PRO 上的 Visual Studio 2019 中添加对 Windows.ApplicationModel.DataTransfer 命名空间的引用

[英]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). Windows 10 专业版、Visual Studio 2019、.Net 版本 4.8.03752(几天前干净安装所有东西)。

I'm trying to add the Windows.ApplicationModel.DataTransfer namespace to my C# project in Visual Studio 2019 (free edition).我正在尝试将 Windows.ApplicationModel.DataTransfer 命名空间添加到 Visual Studio 2019(免费版)中的 C# 项目。 I cannot find anything to add under References->Add References->Assemblies.我在 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 ClipboardContentOptions 的文档指出 dll 是 Windows.ApplicationModel.DataTransfer.dll 所以我搜索 dll 并在

C:\\Windows\\System32 (799Kb) C:\\Windows\\SysWOW64 (566Kb), 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我尝试通过 References->AddReference->Browse 添加这些 dll,在这两种情况下都会出现错误

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. Windows.ApplicationModel.DataTransfer是 WinRT API 命名空间。 The easiest way to gain access to these namespaces is to add the Microsoft.Windows.SDK.Contracts NuGet package as follows:访问这些命名空间的最简单方法是添加Microsoft.Windows.SDK.Contracts NuGet 包,如下所示:

  1. Open your project/solution in Visual Studio.在 Visual Studio 中打开您的项目/解决方案。

  2. Ensure you are targeting .NET Framework 4.6.1+ or .NET Core 3.0+ per NuGet package requirements.根据 NuGet 包要求,确保您的目标是 .NET Framework 4.6.1+ 或 .NET Core 3.0+。

  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 .通过右键单击 package.config 引用并单击Migrate package.config to PackageReference ,将项目中任何旧的 package.config 引用转换为较新的 PackageReference 格式。

  4. In Solution Explorer, right-click References then click Manage NuGet References.在解决方案资源管理器中,右键单击“引用”,然后单击“管理 NuGet 引用”。

  5. Click the Browse heading then type Microsoft.Windows.SDK.Contracts into the search box.单击浏览标题,然后在搜索框中键入Microsoft.Windows.SDK.Contracts

  6. Click the Microsoft.Windows.SDK.Contracts (trusted by Microsoft) package then click the Install button on the right.单击Microsoft.Windows.SDK.Contracts (受Microsoft.Windows.SDK.Contracts信任)包,然后单击右侧的安装按钮。

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 .或者,您可以从通常位于C:\\Program Files (x86)\\Windows Kits\\10\\UnionMetadata的相应 SDK 文件夹中添加对Windows.winmd的引用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法找到Windows.ApplicationModel - Unable to find Windows.ApplicationModel 如何在 Visual Studio 中修复 Windows 应用程序包的目标框架参考 - How to fix target framework reference for windows application pack in visual studio Windows 10 VM上的Visual Studio-性能不佳 - Visual Studio on Windows 10 VM - poor performance 如何在 Windows 10 上的 Visual Studio 2017 中卸载 .NET Framework 4.8? - How to uninstall .NET Framework 4.8 in Visual Studio 2017 on Windows 10? 什么是适当的方法/如何在Visual Studio 2017/2019中打包Visual Basic Windows服务项目? - What is the appropriate way/How to package a Visual Basic Windows Service Project in Visual Studio 2017/2019? Visual Studio 2015 + Windows 10部署 - Visual Studio 2015 + Windows 10 Deployment 如何将 Windows Driver Kit (WDK) 安装到 Visual Studio 2017 Pro 中以对 WinUSB 进行编程? - How do I install Windows Driver Kit (WDK) into Visual Studio 2017 Pro in order to program WinUSB? Visual Studio:缺少对“Windows”的程序集引用 - Visual Studio: Missing assembly reference to “Windows” 如何在 Visual Studio 2019 中的 Windows Forms 应用程序中打印变量? - How do I print a variable in a Windows Forms Application in Visual Studio 2019? Visual Studio 2019 Locals 和 Autos Windows 中的日期时间格式 - DateTime format in Visual Studio 2019 Locals and Autos Windows
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM