Is there an official NuGet single-string package identifier? - nuget

For a dependency management system, I'm looking to see if there is an official single-string format identifying NuGet packages, which combines package name and version. I couldn't find any information on this, the official documentation always separating the package name from the version.
I am thinking for example of what is done for Maven, npm or pip:
Maven: groupId:artifactId:version
npm: <name>#<version>
pip: name==version
Thanks

No, there isn't anything like this in the NuGet world. The used package identifier strings mostly depend on the usage and tool, e. g.:
Package Manager → Install-Package My.Package -Version 19.5.3
.NET CLI → dotnet add package My.Package --version 19.5.3
packages.config → <package id="My.Package" version="19.5.3" />
<PackageReference> → <PackageReference Include="My.Package" Version="19.5.3" />

Related

Nuget pack for assemblies that are append with version

I have to tag every .dll with it's version from assembly,
so from Service.dll it becomes: Service-v1.0.0.21455.dll
I tried this two approaches, but each has flows:
Build > Rename > Pack with nuget pack Service.csproj
The challenge is that after I do so, Nuget can't find missing Service.dll
Of course, because it's bin/Release/Service-v1.0.0.21455.dll
Build > Rename > Pack with nuget pack .nuspec
Issue I'm facing here is that dependencies are missing withing the nuget package
This is brief explanation, let me know if it's 'even possible'/'make sense'/'you need more details'

Nuget nuspec specify private dependency

Essentially this.
I have a NuGet package that has a dependency, it gets installed alongside the package.
However, NuGet adds both the package and recursive dependency package as a reference.
MsBuild has the <private> tag to distinguish one type of dependency from the other, has NuGet been changed in the last 5 years to support this?
I can't find any hints that it does.
Tx
If you are using the PackageReference format of referencing NuGet packages (instead of packages.config), it allows to control the assets consumed by the project and forwarded to dependencies per referenced package. This also allows to sepcify that all assets of the package are "private" which causes the reference to not be added to the packed nupkg:
<ItemGroup>
<PackageReference Include="My.BuildTimeOnly.Dependency"
Version="1.2.3"
PrivateAssets="all" />
</ItemGroup>

How can I force dependent project to install nuget package used in dependency?

I developed a nuget package "nuget_X" installed on a project "project_1".
I have a second project "project_2" that reference "project_1".
If "project_1" is published as nuget package "nuget_1", I can force "project_2" to reference "nuget_X" by declaring "nuget_X" as dependency of "nuget_1"
But "project_1" is referenced as "ProjectReference". So, how can I configure "nuget_X" or "project_1" to force "project_2" to install "nuget_X"?
PackageReference on Visual Studio 2017 don't allow to force nuget of dependency to be installed when using ProjectReference. But it allow to produce an acceptable equivalent result. for more details, see comments.

VSTS Automated Build NuGet Packager/Publisher

My package builds successfully and is uploaded to the Packages feed in VSTS however I can't seem to figure out how to edit the Description and Author of the package so that my set values show in the Package feed.
From what I read I put my content in the NuGet Packager under additional build properties and when I look at the log file I see this:
...NuGet.exe pack "...csproj" -OutputDirectory "..." -Properties Configuration=release;Description="My Description";Authors="Me";Owners="My Company"
From the documentation I believe I did this right(but clearly I did not). It does seem a bit confusing as to what goes in "Additional build properties" vs NuGet Arguments.
Again my goal is get the Description and Author that I set to be viewable from the NuGet Package Manager within Visual Studio.
You could create a package according to the .nuspec file.
Steps:
Generate .nuspec file for your project (command: nugget spec).
For example: (Include author and description token)
<?xml version="1.0"?>
<package >
<metadata>
<id>CommLib1</id>
<version>1.0.0.6</version>
<title>CommLib1</title>
<authors>$author$</authors>
<owners>$author$</owners>
<licenseUrl>http://LICENSE_URL_HERE_OR_DELETE_THIS_LINE</licenseUrl>
<projectUrl>http://PROJECT_URL_HERE_OR_DELETE_THIS_LINE</projectUrl>
<iconUrl>http://ICON_URL_HERE_OR_DELETE_THIS_LINE</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>$description$</description>
<releaseNotes>Summary of changes made in this release of the package.</releaseNotes>
<copyright>Copyright 2016</copyright>
<tags>Tag1 Tag2</tags>
</metadata>
</package>
Include this file to source control
Specify Nuget Arguments (token in step 1) of Nuget Packager build step
Update1:
In general, you just need to update AssemblyInfo.cs file of your project (Author=>AssemblyCompany; Description=>AssemblyDescription; Version=>AssemblyVersion), it creates package according to this data unless it can't retrieve metadata from your assembly (I have a project has this issue).
So, steps:
Make sure nuget could retrieve necessary metadata by creating package through nuget.exe command directly in your local/build machine (nuget pack [XX].csproj)
Create a build definition (1. Visual Studio Build 2. Nuget Packager with default value 3. Nuget Publisher)
If it's building the package then there are no problems with your NuGet Packager build step. Two things need to change though.
In order to specify properties like you are doing there MUST be a tokenized *.nuspec file in the same directory as the solution file with the same name and of course the *.nuspec file needs to be checked in to VSTS/TFS.
The token name for description can't be Description.
For more details on the *.nuspec file please see the solution here:
Nuget.exe pack WARNING: Description was not specified. Using 'Description'

Avoid dependency of a pure code snippet package

Example:
Nuget package A is a set of code snippets (it does not contain an assembly).
Nuget package B is a normal assembly and it is using package A - just for internal means.
Question: What can I do, to avoid, that package A is also installed, when somone installes package B?
Found something in documentation of nuget:
Starting from version 2.7, the pack command will ignore entries in the packages.config file which have an attribute developmentDependency set to true and will not include that package as a dependency in the created package. For example, consider the following packages.config file in the source project
That seems to solve the problem.