33

We are hosting our own nuget server through Teamcity. Is there any other way to add an icon to a .nuspec file other than specifying a web url (http://....)?

Or is there a place in Teamcity that these icons could be hosted?

Michael
  • 3,350
  • 2
  • 21
  • 35

7 Answers7

61

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://learn.microsoft.com/en-us/nuget/reference/nuspec#icon

<iconUrl> is now deprecated.

Wiktor Bednarz
  • 1,553
  • 10
  • 15
  • 3
    This answer should really be the correct answer now as mentioned iconUrl is deprecated. – bytedev Nov 07 '19 at 07:55
  • 1
    but which schema should be used for this? i get "icon" is not valid element errors when packing nuget's... – Chris Watts Mar 10 '20 at 11:08
  • @ChrisWatts, you may need to upgrade your nuget.exe you're using to package. I had the same issue, but then I grabbed the latest, https://www.nuget.org/downloads. Also, I had better luck renaming my icon file to "icon.png". – J. Horn May 21 '20 at 16:23
  • 1
    important safety tip the backslash on @target is necessary or it won't work when you consume the package. – escape-llc Dec 14 '20 at 15:03
  • We started doing this, but this now forces the icon file into the project when they request the nuget package. Is there anyway to stop this? – Rudy Scoggins Feb 04 '21 at 14:14
15

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>
Hakan Fıstık
  • 16,800
  • 14
  • 110
  • 131
techsill
  • 159
  • 1
  • 2
  • 4
    Icon url will be deprecated: https://learn.microsoft.com/en-us/nuget/reference/msbuild-targets#packageiconurl – Mugen Jun 20 '20 at 07:22
7

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.

Stef Heyenrath
  • 9,335
  • 12
  • 66
  • 121
Matt
  • 3,684
  • 1
  • 17
  • 19
  • 1
    Helpful reminder: make sure the URL does not require login. I hosted on my company wiki, had to mark the wiki page "public". :) – Vimes Feb 15 '18 at 20:06
  • 1
    Given Icon URL is deprecated, this should not be the accepted answer any more (if its possible to change) – Bartosz Dec 07 '20 at 15:55
5

The Documentation is as following

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="YOUR_PATH_TO_ICON\icon.png" Pack="true" PackagePath="\" />
</ItemGroup>
Hakan Fıstık
  • 16,800
  • 14
  • 110
  • 131
0

You can host icons on your TeamCity server, quoting Orn Kristjansson in TeamCity to serve static HTML page:

It's a Tomcat server, just go on your file system where you installed Teamcity and you should be able to find out where you can park some html that will then be available on the Teamcity urls.

So copy your icons into C:\...\TeamCity\webapps\ROOT\ and the will be served as static files.

0xced
  • 25,219
  • 10
  • 103
  • 255
-2

I have a work around solution. I tried successfully on windows 10. It is useful if you have to install your application on the offline PC, without internet.

  • step 1:
    add tag to the content of nuspec file. Something like the following:

    <metadata> <id>....</id> ... <iconUrl>file://C:\app.ico</iconUrl> ... <copyright>....</copyright> </metadata>

  • step 2: generate the nupkg file from the above nuspec

  • step 3: generate the exe file from nupkg file

  • step 4: put the app.ico file at location: C:\app.ico . You can choose any location according to <iconUrl> in the nuspec file. Almost windows PC have "C" drive disk. So that it is comfortable to install .exe in the other PC if you use "C" drive).

  • step 5: run exe file to install application on PC.

========= RESULT =============

At C:\Users\"user_name"\AppData\Local\"app_name" you can see the app.ico appears on the installed application folder.

I hope it may help you!

-3

You can add file to nuspec content folder and specify link in such manner: "file://content/images/icon.ico" You can find more info here: Packages containing Icon and License

mlist
  • 33
  • 2
  • 6
  • 2
    Have you tried this? The page you refer to looks more like a proposal than an actual documentation. And wouldn't the content files be added to the project you install the package to? You can of course just delete those files afterwards, but still... – Michael Mar 16 '17 at 08:30
  • 1
    The link is dead. This seems to be the relevant issue in GitHub: https://github.com/NuGet/Home/issues/352 – reduckted Jan 30 '18 at 09:29