简体   繁体   中英

Error “NU1101: Unable to find package xyz” with dotnet publish .NET 5 and win-x64

I'm trying to publish the most barebone WinForms app as single file, it is just a button that shows a MessageBox, targeting Windows and .NET 5.

I have installed .NET SDK 5.0.102, then VS 16.8.5 which installed 5.0.103.

I've got some other errors earlier when trying to publish the app, and by googling here and there I got to this point.

Now dotnet publish fails with this error:

path.csproj: error NU1101: Unable to find package packagename. No packages exist with this id in source(s) (etc).

Three times, with these packages missing:

Microsoft.NETCore.App.Runtime.win-x64

Microsoft.WindowsDesktop.App.Runtime.win-x64

Microsoft.AspNetCore.App.Runtime.win-x64

It is an offline computer, so I understand the "issue", even though I don't understand why the SDK installation or VS aren't also dumping all the packages somewhere on the disk.

However, if I go to the NuGet page for these packages, their description is:

"Internal implementation package not meant for direct consumption. Please do not reference directly."

And that makes me think that there must be another way to properly fix this problem.

What am I supposed to do?

Thank you!

Update/Edit to add more details and the.csproj file:

It is a clean Windows 7 Ultimate x64 installation with rollups up to 2019-12 (because 2020-01 has issues). There is no antivirus or other software that could interfere, I've only installed drivers, .NET SDK 5.0.102, .NET Framework 4.7.2 SDK, then installed Visual Studio 2019 16.8.5 from a layout (verified), and VS also installed .NET SDK version 5.0.103 "from Visual Studio".

This is what I do:

Open Visual Studio, create a new project using template "Windows Forms App (.NET)". I've also tried with leaving its default name and location, but I never use names with spaces or non-English letters and numbers anyway.

If I just launch the app from the editor, it builds and works fine.

Then I open Developer Command Prompt and run this:

dotnet publish -c Release -r win-x64 --self-contained true

I get the above errors. Same with just:

dotnet publish -c Release -r win-x64

This is the untouched.csproj file:

<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">

  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <UseWindowsForms>true</UseWindowsForms>
  </PropertyGroup>

</Project>

If I change the target framework to .NET 5.0 the.csproj file stays the same, except for TargetFramework, which changes to 'net5.0-windows'. Then I get the Warning NETSDK1137 (It is no longer necessary to use the Microsoft.NET.Sdk.WindowsDesktop SDK. Consider changing the Sdk attribute of the root Project element to 'Microsoft.NET.Sdk'.), but whether I change that or not, the errors when publishing stay the same as before.

I've also tried changing the.csproj file to the one in this page: https://docs.microsoft.com/en-us/dotnet/core/deploying/single-file

(Tried with it entirely as it is there, or by just adding some missing properties, if anything I would get other errors that way.)

If I try other ways to publish instead of using the command line, I still get errors.

I think you have some wrong PackageReference node under your csproj file.

I think you have added like these on your csproj file:

<ItemGroup>
        <PackageReference Include="Microsoft.NETCore.App.Runtime.win-x64" Version="5.0.3"></PackageReference>
        <PackageReference Include="Microsoft.WindowsDesktop.App.Runtime.win-x64" Version="5.0.3"></PackageReference>
        <PackageReference Include="Microsoft.AspNetCore.App.Runtime.win-x64" Version="5.0.3"></PackageReference>
</ItemGroup>

If so, you should note that these are internal implementation runtime packages for Net5.0 , and they are not installed by nuget.

在此处输入图像描述

And they are still contained under Net Core 5.0 Sdk. If you change your Platfrom to x64 , it already enables these runtime packages.

So please remove these xml node and then re-publish your winform project.

Besides , if the issue still persists, please share your csproj file with us and we could troubleshoot the issue more puickly.

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