MyGet doesn't show nuget package Self-contained icons

608 Views Asked by At

I've been migrating our nuget packages to using Self-contained icons support. When I publish them to MyGet, we're not seeing the icon image in Visual Studio package manager UI.

Is this a bug? Has anyone else published a nuget package to MyGet using self-contained icons and they show in the VS package manager UI?

1

There are 1 best solutions below

3
On

Sure. It is an issue and check this link. Self-contained icons which is packed into the nupkg cannot be used on the local nuget package source.

So my suggestions are that:

Suggestions

One suggestion is that you could upload your nuget package into nuget.org.

Second is to use icon Url. Unload your icon on a website.

New-sdk format lib pack:

<PackageIconUrl> https://company.com/icon.png </PackageIconUrl>

nuspec file with this:

<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
  <metadata minClientVersion="3.3">
    <icon>images\icon.png</icon>
    <iconUrl>https://company.com/icon.png</iconUrl>
  </metadata>
  <files>
    <file src="..\..\icon.png" target="images\icon.png" />
  </files>
</package>

Update 1

Actually, PackageIconUrl and iconUrl are removed. And thanks for your guidance.

But when I tested in a new-sdk style(net core or net standard) lib project, I can use these on csproj file:

 <PropertyGroup>
        <PackageId>moqq</PackageId>
        <Version>1.0.0</Version>
        <Authors>me</Authors>
        <PackageIcon>images\test.png</PackageIcon>              
 </PropertyGroup>
 <ItemGroup>
        <None Include="mysql.png" Pack="true" PackagePath="images"></None>
 </ItemGroup>

That use the PackageIcon node seems to work. And for new-sdk project, use dotnet pack command line or just right-click on the project on the Solution Explorer-->Pack.

Note: My VS is VS2019 Community 16.8.6 and if your VS2019 is too old, please update it first.

Also, PackageSources5 is local feed.

enter image description here

Besides, if you used a non-sdk style net framework project, it actually can be done. You should use msbuild -t:pack rather than traditional nuget pack with custom nuspec file.

1) install a nuget package called NuGet.Build.Tasks.Pack on the lib project and remember that you should use PackageReference format to install it. If not, you should right-click on the packages.config file-->Migrate packages.config into PackageReference.

2) delete bin and obj file and also nuspec file in your project folder, the file is redundant and if it exists, it will affect the msbuild -t:pack.

3) add these on the csproj file at the bottom of the csproj file:

<PropertyGroup>
        <PackageId>moqqq</PackageId>
        <Version>1.0.0</Version>
        <Authors>me</Authors>
        <PackageIcon>images\test.png</PackageIcon>
        <PackageIconUrl></PackageIconUrl> 
         
</PropertyGroup>
<ItemGroup>
        <None Include="test.png" Pack="true" PackagePath="images"></None> 
</ItemGroup>

You could also add on csproj file:

<PropertyGroup>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>

After that, click Rebuild button and it could generate the nupkg file under project folder\Debug or Release\.

enter image description here

enter image description here