Ошибка must use packagereference

After adding WindowsRuntime to a WinForms-project, building the project fails with Error «Must use PackageReference». The build log is more precise:

C:[…]Visual Studio 2017ProjectsProjectnamepackagesMicrosoft.Windows.SDK.Contracts.10.0.18362.2005buildMicrosoft.Windows.SDK.Contracts.targets(4,5): error : Must use PackageReference

Here’s what I did:

Install-Package Microsoft.Windows.SDK.Contracts

with references to:

  • C:Program Files (x86)Reference AssembliesMicrosoftFramework.NETCorev4.5System.Runtime.WindowsRuntime.dll,
  • C:Program Files (x86)Reference AssembliesMicrosoftFramework.NETFrameworkv4.5FacadesSystem.Runtime.dll
  • C:Program Files (x86)Reference AssembliesMicrosoftFramework.NETFrameworkv4.5FacadesSystem.Threading.Tasks.dll
  • C:Program Files (x86)Reference AssembliesMicrosoftFramework.NETFrameworkv4.5FacadesSystem.IO.dll
  • C:Program Files (x86)Reference AssembliesMicrosoftFramework.NETFrameworkv4.5FacadesSystem.Runtime.InteropServices.WindowsRuntime.dll.

Is it maybe a thing with the .NET version? In the project’s packages.config there is 4.6 while the project targets 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>

There are no compile errors… only this strange «PackageReference» error.

ΩmegaMan's user avatar

ΩmegaMan

29.1k10 gold badges99 silver badges121 bronze badges

asked Oct 24, 2019 at 11:19

Joe's user avatar

8

VS2017/VS2019 -> Solution Explorer -> right-click References -> «Migrate packages.config to PackageReference»

VS2019 -> Solution Explorer -> right-click packages.config -> «Migrate packages.config to PackageReference»

I think this happens when you add a .NET core library to a .NET standard project.

answered Jan 18, 2020 at 16:10

patrick's user avatar

patrickpatrick

16k29 gold badges99 silver badges162 bronze badges

2

Solution that worked for me was to:

  1. Run a Clean on the project in question
  2. Close Visual Studio
  3. Navigate to the project folder on disk and delete the obj folder
  4. Reopen Visual Studio and Build

answered Dec 17, 2020 at 12:08

Chris's user avatar

ChrisChris

1411 silver badge2 bronze badges

1

Could be becuse of nugetpackage, for WPF use WPF one.

answered Jul 13, 2020 at 18:57

Taran's user avatar

TaranTaran

2,81524 silver badges22 bronze badges

Go to your .csproj and remove the references to the package.
On my case they were at the end of the XML file

answered Dec 22, 2020 at 22:19

Lugube's user avatar

1

For now, it works. Thanks to both of you.

In the meantime, I got another issue (by installing packages):
Install-Package : Unable to find fallback package folder ModernWpfUis

I found out the solution (link below) but it was like a kind of magic for me.
https://stackoverflow.com/questions/48333699/unable-to-open-the-nuget-package-manager-console

After it, I dealt with the original issue and can use ModernWpfUI but I can’t describe the main reason…

  • Remove From My Forums
  • Question

  • Обновил WebView 5.1.1 из Microsoft Toolkit до версии 6.0.0 и получил ошибку

    must use packagereference.

    Она происходит с библиотекой Microsoft.Windows.Sdk.Contracts.

    Что не так?

    Помогите исправить

Answers

  • Здравствуйте,

    Вы пробовали : Tools -> Options -> Nuget Package Manager -> Package Manager Settings -> там указываете, чтобы Package Management использовал PackageReference ?


    Если Вам помог чей-либо ответ, пожалуйста, не забывайте жать на кнопку «Предложить как ответ» или «Проголосовать за полезное сообщение» Мнения, высказанные здесь, являются отражение моих личных взглядов, а не позиции
    корпорации Microsoft. Вся информация предоставляется «как есть» без каких-либо гарантий.

    • Marked as answer by

      Thursday, November 21, 2019 8:08 AM

c++visual-studio-2017windows-runtimewinforms

After adding WindowsRuntime to a WinForms-project, building the project fails with Error «Must use PackageReference». The build log is more precise:

C:[…]Visual Studio 2017ProjectsProjectnamepackagesMicrosoft.Windows.SDK.Contracts.10.0.18362.2005buildMicrosoft.Windows.SDK.Contracts.targets(4,5): error : Must use PackageReference

Here’s what I did:

Install-Package Microsoft.Windows.SDK.Contracts

with references to:

  • C:Program Files (x86)Reference AssembliesMicrosoftFramework.NETCorev4.5System.Runtime.WindowsRuntime.dll,
  • C:Program Files (x86)Reference AssembliesMicrosoftFramework.NETFrameworkv4.5FacadesSystem.Runtime.dll
  • C:Program Files (x86)Reference AssembliesMicrosoftFramework.NETFrameworkv4.5FacadesSystem.Threading.Tasks.dll
  • C:Program Files (x86)Reference AssembliesMicrosoftFramework.NETFrameworkv4.5FacadesSystem.IO.dll
  • C:Program Files (x86)Reference AssembliesMicrosoftFramework.NETFrameworkv4.5FacadesSystem.Runtime.InteropServices.WindowsRuntime.dll.

Is it maybe a thing with the .NET version? In the project’s packages.config there is 4.6 while the project targets 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>

There are no compile errors… only this strange «PackageReference» error.

Solution 1

VS2017/VS2019 -> Solution Explorer -> right-click References -> «Migrate packages.config to PackageReference»

VS2019 -> Solution Explorer -> right-click packages.config -> «Migrate packages.config to PackageReference»

I think this happens when you add a .NET core library to a .NET standard project.

Solution 2

Solution that worked for me was to:

  1. Run a Clean on the project in question
  2. Close Visual Studio
  3. Navigate to the project folder on disk and delete the obj folder
  4. Reopen Visual Studio and Build

Related videos on Youtube

How to Fix NullReferenceException in C#! (4 Step Process)

16 : 10

How to Fix NullReferenceException in C#! (4 Step Process)

Understanding errors and how to fix them

05 : 58

Understanding errors and how to fix them

Webpack Compile Error and fix

01 : 02

Webpack Compile Error and fix

Chap4 013 Check and fix data entry errors

16 : 58

Chap4 013 Check and fix data entry errors

How to resolve "Error in plot.new() : figure margins too large" in RStudio : Tutorial # 17

00 : 53

How to resolve «Error in plot.new() : figure margins too large» in RStudio : Tutorial # 17

How to fix Couldn't decompress package error in Unity3D

00 : 25

How to fix Couldn’t decompress package error in Unity3D

Every Pip Error solved (3 different methods)

09 : 48

Every Pip Error solved (3 different methods)

How To Fix Python "Could not packages due to an Environment: [WinError 5] Access is denied:"

03 : 27

How To Fix Python «Could not packages due to an Environment: [WinError 5] Access is denied:»

Problem Installing Packages in RStudio

07 : 38

Problem Installing Packages in RStudio

CI/CD for Nuget packages

24 : 53

Fix Configuration Parser Error - Error Parsing - Parser Returned Error 0xC00CE556

02 : 14

Fix Configuration Parser Error — Error Parsing — Parser Returned Error 0xC00CE556

Conda install and update do not work also solving environment get errors - PYTHON

01 : 36

Conda install and update do not work also solving environment get errors — PYTHON

NuGet PackageReference Versions SOLUTION Wide

04 : 34

NuGet PackageReference Versions SOLUTION Wide

TypeError: Router.use() requires a middleware function but got a Object | Node Js error

02 : 26

TypeError: Router.use() requires a middleware function but got a Object | Node Js error

Fix Error Code 2330 On Windows 10

01 : 56

Fix Error Code 2330 On Windows 10

(Cocoa error 3840.) (JSON text did not start with array or object and option to allow fragments not

01 : 22

(Cocoa error 3840.) (JSON text did not start with array or object and option to allow fragments not

Comments

  • After adding WindowsRuntime to a WinForms-project, building the project fails with Error «Must use PackageReference». The build log is more precise:

    C:[…]Visual Studio 2017ProjectsProjectnamepackagesMicrosoft.Windows.SDK.Contracts.10.0.18362.2005buildMicrosoft.Windows.SDK.Contracts.targets(4,5): error : Must use PackageReference

    Here’s what I did:

    Install-Package Microsoft.Windows.SDK.Contracts

    with references to:

    • C:Program Files (x86)Reference AssembliesMicrosoftFramework.NETCorev4.5System.Runtime.WindowsRuntime.dll,
    • C:Program Files (x86)Reference AssembliesMicrosoftFramework.NETFrameworkv4.5FacadesSystem.Runtime.dll
    • C:Program Files (x86)Reference AssembliesMicrosoftFramework.NETFrameworkv4.5FacadesSystem.Threading.Tasks.dll
    • C:Program Files (x86)Reference AssembliesMicrosoftFramework.NETFrameworkv4.5FacadesSystem.IO.dll
    • C:Program Files (x86)Reference AssembliesMicrosoftFramework.NETFrameworkv4.5FacadesSystem.Runtime.InteropServices.WindowsRuntime.dll.

    Is it maybe a thing with the .NET version? In the project’s packages.config there is 4.6 while the project targets 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>
    

    There are no compile errors… only this strange «PackageReference» error.

    • Do you mean you are trying to use net .core references in a System.Windows.Forms project?

    • Have you set, in Tools -> Options -> Nuget Package Manager -> General -> Package Management to use PackageReference as Package management format? The 4.6 version is related to the System.Runtime.WindowsRuntime dependency, not the .Net Framework.

    • @Jimi, the error occurs when Default package management format is set to Packages.config as well as if it is set to PackageReference. I cleared the NuGet cache and the solution after changing this value. When I installed Microsoft.Windows.SDK.Contracts, the value was Packages.config… did I have to change the value before running Install-Package?

    • Uninstall any NuGet packages related to Microsoft.Windows.SDK.Contracts, set PackageReference as default format, re-install all packages using NuGet Package Manager.

    • @Joe First reference is in a .net core named folder… C:Program Files (x86)Reference AssembliesMicrosoftFramework.NETCorev4.5System.Runtime.W‌​indowsRuntime.dll

    • @bradbury9 you are very mindful! I added the .NET Core library with despair but then figured out that the reference to the .NET4.5 library was sufficient… and somehow forgot to delete the .NET Core reference.

    • @Jimi thank you so much! Your advise worked.

  • I have installed using NuGet the new package Microsoft.Web.WebView2 and I have also installed Microsoft Edge Chromium. After that, I have rebuild application and I have receive “Must use PackageReference» error ! I have done Patrick proposal and build now work as before. Thanks

  • I was missing migration option in References context menu from VS2019, but it can also be found at packages.config context menu.

  • There is a nuget package cache in the obj folder, which must be removed to clear that error message.

  • Yes that is, this error happened to mi after install Microsoft.Windows.SDK.Contracts and I had to remove all reference in the file you mention

Recents

Понравилась статья? Поделить с друзьями:
  • Ошибка net err cleartext not permitted
  • Ошибка mup sys
  • Ошибка multiple irp complete requests windows 10
  • Ошибка net err cert date invalid как исправить
  • Ошибка net err cert common name invalid