Embedded into NuGet package icon doesn't appear in VS - visual-studio

I generate a nuget package using my nuspec file below:
<?xml version="1.0" encoding="utf-8"?>
<package >
<metadata>
<id>CommonLib</id>
<version>1.2.3</version>
<authors>ABC</authors>
<owners>ULC</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<license type="file">Licenses\License.txt</license>
<icon>Icons\Icon.PNG</icon>
<description>Common References</description>
<copyright>Copyright (c) 2020</copyright>
<tags>Common</tags>
<dependencies>
<group targetFramework="net48" />
</dependencies>
</metadata>
<files>
<file src="lib\net48\Common*.dll" target="lib/net48" />
<file src="Licenses\License.txt" target="Licenses\" />
<file src="Icons\Icon.PNG" target="Icons\" />
</files>
</package>
The folder structure for the source data for packing is as the following:
RootDir
Icons
Icon.png
lib
net48
Abc.dll
Common1.dll
Common2.dll
xyz.dll
Licenses
License.txt
My.nuspec
I successfully generate it. However, whether I host it locally or in my Azure Artifacts as private feed, then when I browse in VS2017 (that's what I currently have installed) to install for a project then the generated package doesn't show its embedded icon, instead, it shows the default nuget pack icon. I tried browsing either from my local feed or from Azure private feed, same thing. What's the reason my embedded into nuget pack icon is not being used?

Embedded into NuGet package icon doesn't appear in VS
Actually, this is a well-known issue for nuget and for creating our own nuget feed, package source, or local address, the nuget icon cannot be displayed in the package manage UI. See this similar issue.
So if you add comments in this github link to get the staff's attention so that they can focus on the issue and fix it.
In your situation, you use private local nuget feed to install such nuget package and it cannot be realized and the latest version nuget.exe v5.5.1 does not support this so far.
Solution
Please upload your nuget package into nuget.org website an then use nuget.org nuget feed to install your nuget package.
And nuget.org supports the sustom icon to show your nuget package.
And then you can directly use nuget.org to install your own nuget package.
l have test it:
local feed:
nuget.org website:
Besides, you could suggest this feature in Our User Voice Forum to reflect your thoughts

Related

NuGet nuspec dependency - how to include a private NuGet gallery

Fixed - see Sara Lui's link to document in comments.
I have created several NuGet packages which are available on our private Corporate NuGet gallery.
Several of these packages are dependent upon one common package.
However, when I add this to my Nuspec file:
<?xml version="1.0"?>
<package >
<metadata>
...
<dependencies>
<dependency id="MyCommonPackage" version="1.0">
</dependency>
</dependencies>
</metadata>
</package>
Then it fails to install because it can't find "MyCommonPackage" - it's not looking for it in our corporate gallery:
NotFound
https://api.nuget.org/v3-flatcontainer/MyCommonPackage/index.json
NotFound
https://dotnetmyget.blob.core.windows.net/artifacts/roslyn/nuget/v3/flatcontainer/MyCommonPackage/index.json
Visual Studio has this gallery referenced, but I suspect I need to reference it in the nuspec file (just not seeing how to do this).
I fixed it by referring to link provided by #Sara Lui:
please check this doc: https://learn.microsoft.com/en-us/nuget/create-packages/creating-a-package and make sure the required file 'MyCommonPackage' is under the folder structure before we run the nuget pack command to generate the .nupkg file.
I removed the package references, deleted the folders from the NuGet gallery and then re-published them from the bottom-up. This time it just worked like a dream (with no changes apart from re-publishing).

Internally distribute a Visual Studio Template using Nuget and SVN

Suppose we have a Visual Studio template that we would like to distribute within our organization. This template is hosted on an SVN server. I would like users to be able to point Nuget to the SVN location and get the template installed in the proper location just like any other package. Is this possible?
Is this possible?
We can do it but individuals do NOT recommend it.
How
According to the NuGet document:
Put simply, a NuGet package is a single ZIP file with the .nupkg
extension that contains compiled code (DLLs), other files related to
that code, and a descriptive manifest that includes information like
the package's version number. Developers with code to share create
packages and publish them to a public or private host. Package
consumers obtain those packages from suitable hosts, add them to their
projects, and then call a package's functionality in their project
code. NuGet itself then handles all of the intermediate details.
However, the Visual Studio Template is a file with the .zip extension, which could not be recognized by NuGet. Even if we point NuGet to the SVN location, NuGet still can not recognize it.
To resolve this issue, we have to create a NuGet package to include this Visual Studio Template .zip file, like:
<files>
<file src="TestDemo.zip" target="Tools\TestDemo.zip" />
</files>
Besides, there is another question, when we install this nuget package to the project, this Visual Studio Template .zip file would be downloaded to the \packages folder in the solution folder. We have to move it to the Visual Studio Templates folder.
So, we have to add .targets with copy task in that nuget package to copy zip file to the Visual Studio Templates folder.
The content of .targets file:
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="CopyTemplate" BeforeTargets="Build">
<Message Text="Copy Template to template folder."></Message>
<Copy
SourceFiles="$(SolutionDir)packages\MyTemplatePackage.1.0.0\Tools\TestDemo.zip"
DestinationFolder="$(USERPROFILE)\Documents\Visual Studio 2017\Templates\ProjectTemplates"
/>
</Target>
</Project>
Finally, the .nuspec file like following:
<?xml version="1.0"?>
<package >
<metadata>
<id>MyTemplatePackage</id>
<version>1.0.0</version>
<authors>Tester</authors>
<owners>Tester</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Package description</description>
<releaseNotes>Summary of changes made in this release of the package.</releaseNotes>
<copyright>Copyright 2018</copyright>
<tags>Tag1 Tag2</tags>
</metadata>
<files>
<file src="TestDemo.zip" target="Tools\TestDemo.zip" />
<file src="MyTemplatePackage.targets" target="Build\MyTemplatePackage.targets" />
</files>
</package>
Then pack this .nuspec file, add this nuget package to the SVN location, add the SVN location to the nuget package source, you can install this nuget package to the project, and build the project, Visual Studio will download that nuget package and copy .zip file to the Visual Studio Templates folder.
I have created a sample test nuget package and it work fine on my side with Visual Studio 2017, you can test it on VS2017: https://1drv.ms/u/s!Ai1sp_yvodHf2Vax7TzuC6HQUD5w
Why not recommend
Just as you can see above, it is not easy and simple to do this, we have to do a lot of things to create that nuget package. What`s more, in order to get the template we have to create a project and install that package and build the project. It pulls in too many extra operations. Besides, when you change anything in the template, you have to re-create this package and install it.
Since this template is hosted on an SVN server, you can just check it to the Visual Studio template folder, this will be more effective.
Hope this complicated answer helps.

NuGet package from PCL

I have a PCL library I want to distribute as NuGet package.
Screenshot of the PCL application library properties page:
csproj file:
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkProfile>Profile111</TargetFrameworkProfile>
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
Steps to reproduce my problem:
Clone both repos from:
NuGet package
Console application + PCL library
Build the NugetPackage project + nuget spec + nuget pack
Create a local nuget package repository pointing to the project folder.
Open the NugetConsole solution and try installing the package in both projects.
Some references I used:
https://learn.microsoft.com/en-us/nuget/schema/target-frameworks
https://learn.microsoft.com/en-us/nuget/schema/nuspec
https://portablelibraryprofiles.stephencleary.com/
http://blog.stephencleary.com/2012/05/framework-profiles-in-net.html
How can I make a nuget package from a PCL library and use it in a PCL library?
I have downloaded your nuget package and test projects, I can created the nuget package and installed it to the both projects. Following are my detailed steps:
1. Create nuget package:
Download the nuget project, then build the project+nuget spec+nuget pack:
Here is the .nuspec file:
<?xml version="1.0"?>
<package >
<metadata>
<id>My.Package</id>
<version>1.0.0</version>
<authors>Tester</authors>
<owners>Tester</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Package description</description>
<releaseNotes>Summary of changes made in this release of the package.</releaseNotes>
<copyright>Copyright 2018</copyright>
<tags>Tag1 Tag2</tags>
</metadata>
<files>
<file src="bin\**" target="lib\portable-net45+wp8\" />
</files>
</package>
Note: Since you are planning use this package into PCL library, so the target should be .net45 + Profile49, according to the document Portable Class Library (PCL) profiles, nuget target should be portable-net45+wp8:
2. Install that package to both projects:
Download those two test projects from GitHub, and open it with Visual Studio 2017, then copy the created package to the local nuget feed:
Open Package manager Console, install the package with following command:
install-package My.Package -source D:\LocalServer
So the nuget package is correct install in both projects.
Note: I have seen following code in your project file of console application:
<ItemGroup>
<PackageReference Include="My.Package">
<Version>1.0.0</Version>
</PackageReference>
</ItemGroup>
Please remove it, this is not a correct way to add nuget package.

Can NuGet install the source of a binary alongside so the reference can be debugged?

I am not very familiar with NuGet and I am wondering if NuGet offers a similar feature to Maven where I can choose to not only install the binary of a dependency but also its source code and documentation.
So, when debugging my solution, I can follow the debugger into code running within a dependency declared and managed with NuGet. This would also have the advantage that when the binary package is updated, NuGet would pull the matching source code.
NuGet supports symbol packages which allow you to debug into a NuGet package's source code in Visual Studio.
However this only works if the creator of the NuGet package published a symbol package.
Yes, it is supported. Here is the relevant documentation:
Creating and Publishing a Symbol Package
Here is an example of our NuSpec-File. It ist so generic, that it's literally the same for every package:
<?xml version="1.0"?>
<package >
<metadata>
<id>$id$</id>
<title>$title$</title>
<tags>$tags$</tags>
<owners>$owners$</owners>
<authors>$authors$</authors>
<version>$version$</version>
<description>$description$</description>
<copyright>$copyright$</copyright>
<requireLicenseAcceptance>$requireLicenseAcceptance$</requireLicenseAcceptance>
<releaseNotes>$releaseNotes$</releaseNotes>
</metadata>
<files>
<file src="readme.txt" />
<file src="\bin\Release\*.pdb" target="lib\net45" />
<file src="**\*.cs" target="src" exclude="obj\**"/>
<file src="**\*.vb" target="src" exclude="obj\**"/>
</files>
</package>
We also use the Visual Studio Extension "NuGet Deploy", you can find it in the VS Gallery.
If you still cannot Step into your package source code, make sure you loaded the symbols. Check it during dubugging in the Pane "DEBUG->Windows->Modules"

Show NuGet package release notes

The nuspec reference says about the releaseNotes tag
v1.5 A description of the changes made in each release of the package. This field only shows up when the Updates tab is selected and the package is an update to a previously installed package. It is displayed where the Description would normally be displayed.
I created two nuspec files, both containing (with different version tags of course)
<?xml version="1.0"?>
<package >
<metadata>
<id>TestReleaseNotes</id>
<version>1.0</version>
<authors>adrianm</authors>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Description</description>
<releaseNotes>Release notes</releaseNotes>
</metadata>
<files>
<file src="Test.cs" target="content" />
</files>
</package>
I installed 1.0 in VS2013 and selected the update tab but I can't see the release notes.
What am I missing?
Found this out myself.
The release notes are displayed if I open the "Manage NuGet packages" dialog from the project.
but not when I open it from the solution.
The behaviour is the same for my own packages as well as nuget.org
This still seems to be an issue in Visual Studio 2019 as at March 2021.
We publish a number of nuget packages internally using Azure. The Package Release Notes show up in the Azure UI but not in Visual Studio. However, the "Description" does show up in Visual Studio, so I've tweaked the Description to include the release notes. This is actually from the Directory.build.props file, but could equally well be embedded in the project file:
<PackageReleaseNotes>
Release notes added to .nuspec file as <Release Notes> and also to end of Description
</PackageReleaseNotes>
<!-- Don't indent text, it makes it hard to read in the nuget package manager-->
<Description>
Description:
This is the description of our internally produced nuget package
Release Notes:$(PackageReleaseNotes)
</Description>
This issue is tracked in the NuGet repo regarding VS2015.
https://github.com/NuGet/Home/issues/1823

Resources