如何解决必须使用PackageReference&的错误?

人气:967 发布:2022-10-16 标签: c# winforms windows-runtime visual-studio-2017

问题描述

WindowsRuntime添加到WinForms项目后,构建项目失败,并返回错误&必须使用PackageReference&qot;。构建日志更准确:

C:[...]Visual Studio 2017ProjectsProjectnamepackagesMicrosoft.Windows.SDK.Contracts.10.0.18362.2005uildMicrosoft.Windows.SDK.Contracts.targets(4,5):错误:必须使用PackageReference

我是这样做的:

Install-Package Microsoft.Windows.SDK合同

参考:

C:程序文件(X86)参考AssembliesMicrosoftFramework.NETCorev4.5System.Runtime.WindowsRuntime.dll, C:程序文件(X86)参考AssembliesMicrosoftFramework.NETFrameworkv4.5FacadesSystem.Runtime.dll C:程序文件(X86)参考AssembliesMicrosoftFramework.NETFrameworkv4.5FacadesSystem.Threading.Tasks.dll C:程序文件(X86)参考AssembliesMicrosoftFramework.NETFrameworkv4.5FacadesSystem.IO.dll C:程序文件(X86)参考AssembliesMicrosoftFramework.NETFrameworkv4.5FacadesSystem.Runtime.InteropServices.WindowsRuntime.dll.

这可能是.NET版本的问题吗?在项目的Packages.config中有4.6,而项目的目标是4.5。

<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Windows.SDK.Contracts" version="10.0.18362.2005" targetFramework="net45"/>
<package id="System.Runtime.WindowsRuntime" version="4.6.0" targetFramework="net45" />
<package id="System.Runtime.WindowsRuntime.UI.Xaml" version="4.6.0" targetFramework="net45" />
</packages>

没有编译错误...只有这个奇怪的&q;PackageReference&q;错误。

推荐答案

VS2017/VS2019-将Packages.config迁移到PackageReference

VS2019-&>Solution Explorer-&>右键单击packages.config-&>将Packages.config迁移到PackageReference

898