Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Neither PackageIcon nor PackageIconUrl work in dotnet build

I'm using visual studio 2017. I have a project for which I would like to generate a nuget with an Icon. If I use

...
<PackageIconUrl>http://blabla/icon.png</PackageIconUrl>

I get the following error :

error NU5048: The 'PackageIconUrl'/'iconUrl' element is deprecated. Consider using the 
'PackageIcon'/'icon' element instead. Learn more at https://aka.ms/deprecateIconUrl 
[D:\myproject.csproj]

Fine, So I change my project to be something like :

...
    <PackageIcon>core.png</PackageIcon>
...
    <Content Include="..\Shared\core.png" Link="core.png" Pack="true" PackagePath="\" >
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </Content>

When I build my project now (dotnet build Myproject.csproj) I don't get any compilation errors. However, when I want to view the generate nupkg in "Nuget Package explorer". I get the error :

The element 'metadata' in namespace 'http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd' 
has invalid child elment 'icon' in namespace 'http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd'.
List of possible elements expected : 'contentFiles, desription, licenseUrl, projectUrl, language, 
releaseNotes, frameworkAssemblies, summary, iconUrl, packageTypes, dependencies, copyright, 
developmentDependency, repositoru, tags, references, title, serviceable' in namespace 
'http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd'.

(so it seems the generated embedded nuspec has a wrong xml namespace - I have no idea how I can make it generate the new namespace) This is a Catch-22. So it seems the only option is to leave the icon out.

(I also have visual studio 2019 and recently installed the .net core 3.0.100 SDK)

like image 377
Willy Van den Driessche Avatar asked Nov 01 '25 15:11

Willy Van den Driessche


1 Answers

The move from <iconUrl>/<PackageIconUrl> to <icon>/<PackageIcon> is fairly new. While nuget.org supports parsing packages which use <icon> rather than <iconUrl>, some other package servers don't yet.

It sounds like you're simply browsing a directory with the NuGet Package Explorer, so the cause is probably that this doesn't yet understand <icon>.

While <iconUrl> is deprecated, I've found that it still works on nuget.org, so you should be able to continue using it until the rest of the tooling catches up. Alternatively if you don't actually care about browsing packages stored in a local directory and just care about nuget.org, then you can start using <icon>.

You might even be able to use both - I haven't checked.

like image 64
canton7 Avatar answered Nov 04 '25 06:11

canton7



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!