Skip to content

Latest commit

 

History

History
91 lines (73 loc) · 2.63 KB

NuGet.md

File metadata and controls

91 lines (73 loc) · 2.63 KB

Get detailed information for NuGet package using https://nuget.info

https://nuget.info/packages/Newtonsoft.Json/12.0.0

You can also use the NuGetPackageExplorer.

Project Files

Modify *.csproj file for NuGet support

<PropertyGroup Label="NuGet">  
  <Authors>Foo Bar</Authors>
  <Copyright>Copyright 2024</Copyright>
  <Description>Helper classes</Description>
  <IsPackable>true</IsPackable>
  <PackageId>Package.Name</PackageId>
  <PackageProjectUrl>http://foo.com/package.name</PackageProjectUrl>
  <PackageTags>utils</PackageTags>
  <RepositoryType>git</RepositoryType>
  <RepositoryUrl>http://foo.com/package.name.git</RepositoryUrl>
  <SymbolPackageFormat>snupkg</SymbolPackageFormat>
  <GenerateDocumentationFile>true</GenerateDocumentationFile>
  <IncludeSymbols>true</IncludeSymbols>
</PropertyGroup>

Source Link

To enable SourceLink, additional packages are required:

  <ItemGroup>
    <SourceLinkAzureDevOpsServerGitHost Include="my.devops.com:8080" />
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.SourceLink.AzureDevOpsServer.Git" Version="8.0.0" PrivateAssets="All" />
  </ItemGroup>

Instead of RepositoryUrl we can use PublishRepositoryUrl to create the URL automatically on build:

<PublishRepositoryUrl>true</PublishRepositoryUrl>

Generate Software-Bill-Of-Materials (SBOM)

The SBOM Tool generates a SPDX 2.2 compatible SBOM file for the NuGet package:

Install the tool:

winget install Microsoft.SbomTool
dotnet tool install --global Microsoft.Sbom.DotNetTool

Add the build target:

dotnet package add Microsoft.Sbom.Targets
<ItemGroup>
	<PackageReference Include="Microsoft.Sbom.Targets" Version="3.0.0">
		<PrivateAssets>all</PrivateAssets>
		<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
	</PackageReference>
</ItemGroup>

Enable the generation of the BOM:

<PropertyGroup>
	<GenerateSBOM>true</GenerateSBOM>
</PropertyGroup>

Publish Package

dotnet pack --configuration 'Release'
dotnet nuget push 'bin/Release/MyLibrary.1.0.0.nupkg' --api-key 'APIKEY' --source 'https://api.nuget.org/v3/index.json'

Weblinks