How to add an icon to a nuget package?

No, this is the only option using the iconUrl property - See the NuSpec Reference

I would generally choose to host shared images like this on a CDN service rather than TeamCity - CloudFlare provide a free service.


As of NuGet 5.3.0 you can now use <icon> to provide a relative path to your JPEG or PNG icon file located within your package.

<package>
  <metadata>
    ...
    <icon>images\icon.png</icon>
    ...
  </metadata>
  <files>
    ...
    <file src="..\icon.png" target="images\" />
    ...
  </files>
</package>

Source: https://docs.microsoft.com/en-us/nuget/reference/nuspec#icon

<iconUrl> is now deprecated.


PackageIconUrl is deprecated in favor of the PackageIcon property
Starting with NuGet 5.3 and Visual Studio 2019 version 16.3

So the way to do it is to add the following to your .csproj

<PropertyGroup>
    <PackageIcon>icon.png</PackageIcon>
</PropertyGroup>

<ItemGroup>
    <None Include="images\icon.png" Pack="true" PackagePath="\" />
</ItemGroup>

You most likely to change the Include property depending on your Image is.

Documentation


If you have your icon in a GitHub repository, you can locate it on GitHub.com, right click and "Copy image address". Then place this in your .nuspec. This worked for me:

<iconUrl>https://github.com/tcs1896/SharpChecker/blob/master/SharpChecker/SharpChecker/SharpChecker/Icon.png?raw=true</iconUrl>