Upload NuGet package, how to set the license? - nuget

I'm trying to upload a new NuGet package on the website.
https://www.nuget.org/packages/manage/upload
On the first attemp I received an error that says I need to specify the license.
I don't want but... ok.
So, my first attempt with a specified license failed. I read the linked documentation and I tried multiple times.
I tried with a <license> property and also including a license.txt file in the package.
These are my try with the .nuspec file and the error I receive:
<license type="MIT"/>
=> Error: Unsupported license type 'MIT'.
(I know it is wrong but I found this "example" here: https://github.com/NuGet/Home/wiki/Packaging-License-within-the-nupkg)
<license type="expression">MIT</license>
=> Error: To provide a better experience for older clients when a license expression is specified, must be set to 'https://licenses.nuget.org/MIT'.
<license type="expression">BSD-2-Clause OR MIT</license>
=> Error: To provide a better experience for older clients when a license expression is specified, must be set to 'https://licenses.nuget.org/BSD-2-Clause%20OR%20MIT'.
<license type="expression">https://licenses.nuget.org/MIT</license>
=> Error: Invalid license metadata: The license expression 'https://licenses.nuget.org/MIT' contains invalid characters.
I also tried with my license.txt without success.
What I'm doing exactly is: modify the mylibrary.nuspec file contained in a generated mylibrary.nupkg adding the <license> field.
Why? Because this VS studio project generatse the package using nuget.exe mylibrary.csproj file, and it does not contains the license.
I updated nuget.exe to the latest 5.1 version, but I don't want to modify the VS solution or project.
Any idea ?

Edit the .csproj file. Add the following:
Using License file:
<PropertyGroup>
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
</PropertyGroup>
<ItemGroup>
<None Include="licenses\LICENSE.txt" Pack="true"
PackagePath="LICENSE.txt"/>
</ItemGroup>
Using PackageLicenseExpression:
<PropertyGroup>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
</PropertyGroup>
For more details, see

In my case I had to set two properties:
PackageLicenseUrl - https://licenses.nuget.org/MIT
PackageLicenseExpression - MIT

Related

VSIX - Include PackageReference output groups

Currently we reference another project in the following way in order to include it completely in the VSIX package.
<ProjectReference Include="....csproj">
<Project>{8da36305-5468-465a-bf37-d87936b776d2}</Project>
<Name>ProjectName</Name>
<VSIXSubPath>SubDirectory</VSIXSubPath>
<IncludeOutputGroupsInVSIX>BuiltProjectOutputGroup%3bBuiltProjectOutputGroupDependencies%3bGetCopyToOutputDirectoryItems%3bSatelliteDllsProjectOutputGroup%3bDocumentationProjectOutputGroup%3b</IncludeOutputGroupsInVSIX>
<IncludeOutputGroupsInVSIXLocalOnly>DebugSymbolsProjectOutputGroup%3b</IncludeOutputGroupsInVSIXLocalOnly>
</ProjectReference>
This was working perfectly, until we have converted our 'old' Nuget references to the new PackageReference format. What we see is that the output files of the package references are not included in the VSIX package anymore. Is there an additional output group that we can include to solve this?
Can be solved by adding "ReferenceCopyLocalPathsOutputGroup" to IncludeOutputGroupsInVSIX.
Found it here: https://github.com/dotnet/msbuild/issues/3069
<ProjectReference Include="....csproj">
<Project>{8da36305-5468-465a-bf37-d87936b776d2}</Project>
<Name>ProjectName</Name>
<VSIXSubPath>SubDirectory</VSIXSubPath>
<IncludeOutputGroupsInVSIX>BuiltProjectOutputGroup%3bBuiltProjectOutputGroupDependencies%3bGetCopyToOutputDirectoryItems%3bSatelliteDllsProjectOutputGroup%3bDocumentationProjectOutputGroup%3bReferenceCopyLocalPathsOutputGroup%3b</IncludeOutputGroupsInVSIX>
<IncludeOutputGroupsInVSIXLocalOnly>DebugSymbolsProjectOutputGroup%3b</IncludeOutputGroupsInVSIXLocalOnly>
</ProjectReference>

Azure Devops: Building a multi-project solution in release mode, but looks in debug for missing assembly

I'm trying to build a multi-project solution in Azure DevOps for deployment to Azure. This solution builds fine on my local machine, but I get the following build error in Azure.
##[error]TCGTools.net\Controllers\SettingsController.cs(8,7): Error CS0246: The type or namespace name 'TCGSniperCore' could not be found (are you missing a using directive or an assembly reference?)
TCGSniperCore is a .netcore library in my solution. The MVC project references this library.
After skimming the full log file, I found that the solution is building the .netcore library in release mode, but then looks for the .dll in the debug folder.
Console output when building the library:
CopyFilesToOutputDirectory:
Copying file from "obj\Release\netcoreapp2.2\TCGSniperCore.dll" to
"bin\Release\netcoreapp2.2\TCGSniperCore.dll".
TCGSniperCore ->
D:\a\1\s\tcgsnipercore\bin\Release\netcoreapp2.2\TCGSniperCore.dll
Copying file from "obj\Release\netcoreapp2.2\TCGSniperCore.pdb" to
"bin\Release\netco
Console output when building the MVC project:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(2110,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "TCGSniperCore". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors. [D:\a\1\s\TCGTools.net\TCGTools.net.csproj]
For SearchPath "{HintPathFromItem}".
Considered "..\tcgsnipercore\bin\Debug\netcoreapp2.2\TCGSniperCore.dll", but it didn't exist.
For SearchPath "{RawFileName}".
Considered treating "TCGSniperCore" as a file name, but it didn't exist.
I have tried the following:
Ensuring both projects target .netcore2.2
Setting the Agent pool to Hosted VS2017 in Azure DevOps
Setting the BuildConfiguration variable to release
Reproducing on my local machine. I cannot. The solution builds fine.
Why is it looking for the assembly in /debug and not /release?
I found that it looks for the .dll based on the file path specified in the .csproj file. Edit the file (I used VS Code) and add/modify the hint path with $(configuration).
Before:
<ItemGroup>
<Reference Include="TCGSniperCore">
<HintPath>..\tcgsnipercore\bin\Debug\netcoreapp2.2\TCGSniperCore.dll</HintPath>
</Reference>
</ItemGroup>
After:
<ItemGroup>
<Reference Include="TCGSniperCore">
<HintPath>..\tcgsnipercore\bin\$(configuration)\netcoreapp2.2\TCGSniperCore.dll</HintPath>
</Reference>
</ItemGroup>
Thanks #D.J.

How can a add a custom license to my dotnet nuget package?

Today I tried to update my netstandard2.0 class library and got a warning that the <PackageLicenseUrl> element is deprecated. After doing some research, I added the following lines to my csproj file:
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
<!-- .... -->
<ItemGroup>
<None Include="..\LICENSE.txt" Pack="true" PackagePath="$(PackageLicenseFile)"/>
</ItemGroup>
Later, I tried to publish the package. dotnet pack runs without issue, but for dotnet nuget push xxx.1.0.2.nupkg -k xxx -s https://api.nuget.org/v3/index.json prints the following error:
info : "xxx.1.0.2.nupkg" wird per Push nach "'https://www.nuget.org/api/v2/package'" übertragen...
info : PUT https://www.nuget.org/api/v2/package/
warn : Your API key expires in 1 days. Visit https://www.nuget.org/account/apikeys to regenerate your API key.
info : BadRequest https://www.nuget.org/api/v2/package/ 1661 ms
error: Response status code does not indicate success: 400 (License files are not yet supported.).
Summary:
PackageLicenseUrl is deprecated but works
PackageLicenseFile is not implemented
Did I miss something?
The new NuGet client shipped before the NuGetGallery depolyed support for the feature. But it should be coming very soon. If you use a well known license, you can use the SDPX expression instead, and nuget.org will accept those already.
EDIT: nuget.org is now accepting packages with licence file. Announcement of the new licence feature here.

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'

Deploying PostSharp into a Source Repository with NuGet Package Restore

Is it possible to Deploy PostSharp into a Source Repository in conjunction with NuGet Package Restore?
I can get this working by committing the postsharp package, but that negates somewhat the value of the Package Restore feature.
Here’s what I did.
I was trying to set up postshap like so: Deploying post sharp into a source repo
I have set up nugget to use without commiting like so: Using NuGet Without Committing Packages to Source Control
I see this in my csproj
<Import Project="..\packages\PostSharp.2.1.6.13\tools\PostSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\nuget.targets" />
(I re-ordered them to no avail)
And my build server (CC.net) reports the following errors:
D:\wwwroot\www.snip.co.nz\http\www.snip.co.nz.csproj (714,3):
errorMSB4019: The imported project "D:\wwwroot\www.snip.co.nz\packages\PostSharp.2.1.6.13\tools\PostSharp.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.
CacheAttribute.cs (8,7):
errorCS0246: The type or namespace name 'PostSharp' could not be found (are you missing a using directive or an assembly reference?)
…etc…
You currently (v2.1.6.13) have to fix the csproj to support Package Restore,
within the Import target element add the condition shown here:
<Import Project="..\packages\PostSharp.2.1.6.13\tools\PostSharp.targets"
Condition="Exists('..\packages\PostSharp.2.1.6.13\tools\PostSharp.targets')" />