This is a nuget/paket main scaffold component to create others packages
-
Build and run tests
-
.NET official package manager to generate
.nupkg
file -
Integrated with Nuget to manage dependencies, with more clear files and allow use Git dependencies
1. Install .NET Core
-
Use Chocolatey
choco install dotnetcore-sdk
Or download from https://dotnet.microsoft.com/download
-
Restart your terminal and check if the cli
dotnet
is in your$PATH
environment variable
2. Install Nuget
Use Chocolatey
choco install nuget.commandline
2.1 Install Azure Artifacts Credential Provider
Optionally, you can install with Chocolatey too
# Install nuget AUTH PROVIDER
# to push package for feed authenticate
choco install nuget-credentialprovider-vss
This is required to push
.nupkg
packages to Azure Artifacts
3. Install Paket
Use .NET Core tools to install paket command line locally
dotnet tool install -g paket
If you got any error using paket
with .NET Core, try install using chocolatey
choco install paket
PS: Install globally if you will use paket in others projects. You can use globally also if your project not use .NET Core.
Use Chocolatey
# Install base Azure CLI (command line)
choco install azure-cli
# Install Azure Devops extensions
az extension add --name azure-devops
paket restore
dotnet restore
# Build the solution
dotnet build
# Run all tests
dotnet test
Your project folders structure should be:
- π ComponentBase
The .NET solution group projects
- π ComponentBase.sln
- π ComponentBase.Tests
The project with Unit and/or Integration tests
- π ComponentBase.Core
The project with your library/component core
-
Make sure that project builds and all tests are passed
# Build the solution dotnet build # Run all tests dotnet test
-
Generate the
.nupkg
file# Pack your component to the path nupkg/*.nupkg dotnet pack --include-symbols --configuration Release --output .\nupkg [your-component-project]
PS: If you not pass the --outputs flag, the
.nupkg
file is generated in:[your-component-project]/bin/Release
by defaultOr use Visual Studio and right click on your project component under Solution explorer, and click Pack.
If you got a
Pack task
error with .NET Core CLI or in Visual Studio, usePaket pack
command:paket pack --template [your-component-project]\[your-component-project].csproj.paket.template --build-config Release --symbols .\nupkg
The preferrable option is create a paket.local
file in your consumer project/application,
and add the source path of your package. The source
property could be a path that contains a .nupkg
file. In this case, you need build and pack your component first:
- Build/Pack your component project first
# Use Visual Studio: Build => Build Solution
# or use dotnet core CLI
dotnet build
- Create the paket.local
file in your consumer root solution project/application
paket.local
nuget [my-component-id] -> source [my-component-solution]\[my-component-project]\[nupkg-folder] version [my-component-version]
For more information, see the official documentation: The paket.local file
-
After generated the
.nupkg
file, create a folder accessible to you (local directory or network share) as package repo:Publish the package to local repo using
nuget add
:nuget add [my-component.{version-number}].nupkg -source [your/local-repo/directory]
Using Paket
-
Add your local folder like a
source
to thepaket.dependencies
file, in a project/application that will use this package like a dependency:source D:\source\nuget_repo source ~/source/nuget_repo source \\server\nuget_repo # Paket supports relative directory to the paket.dependencies too source directory/relative/to/paket.dependencies
PS: Pay attention to avoid commit this file with the
my/local/path
to your CVS repository (like git). This is only to local tests.If you wish add a commit with the hardcoded path, add a common directory for everyone, for example:
C:\Program Files\Microsoft SDK\NuGetLocal
-
Add the packageId like a dependency into
paket.dependencies
file of your application:
Using Nuget
-
If your destiny project/application uses only Nuget like a package manager (without
Paket
), you can add the nuget repo folder mentioned above with Visual Studio:For more information, see these tutorials:
-
Restore the project to provide authentication
nuget restore
-
Push to the Azure Artifacts feed
# See the nuget.config file <packageSources> tag nuget push -Source "[your-feed-name]" -ApiKey az [path/to/nupkg-file].nupkg
Using Paket
-
Add your remote feed URL like a
source
to thepaket.dependencies
file, in a project/application that will use this package like a dependency:# [organization]: Your organization in Azure Devops # [feed]: Your feed/server name, created in Azure Artifacts source https://pkgs.dev.azure.com/[organization]/_packaging/[feed]/nuget/v3/index.json # Paket supports relative directory to the paket.dependencies too source directory/relative/to/paket.dependencies
-
Add the packageId like a dependency into
paket.dependencies
file of your application:
# [YourAppProject]: Is project name inside of the solution, that to use this dependency like a reference
## Using dotnet core
paket add --project [YourAppProject]/[YourAppProject].csproj {YourComponent.PackageIdName}
## Using .NET Framework
.\.paket\paket.exe add --project [YourAppProject]/[YourAppProject].csproj {YourComponent.PackageIdName}
As result will be added in the paket.dependencies
file:
And in the [YourComponent]/paket.references
file:
Using Nuget
-
If your destiny project/application uses only Nuget like a package manager (without
Paket
), you can add the remote feed URL mentioned above with Visual Studio:Where:
- [my-organization]: The name of the remote feed/server
- [organization]: replace with your organization name defined in Azure Devops
- [feed]: replace with your private feed (by organization or project) where the package that will be used like an dependency was uploaded.
For more information, see this official Microsoft tutorial:
-
Add the packageId like a dependency into
package.config
or using the tag<PackageReference>
in the[YourComponent]\YourComponent.csproj
XML file. You can do this using Visual Studio:
Right click
on References under the componentproject => Manage Nuget Packages
- On the next screen, search by the packageId and click on
Install
button
See the wiki pages in: CsharpPackagetBase Wiki