JandaBox 0.8.1

dotnet add package JandaBox --version 0.8.1                
NuGet\Install-Package JandaBox -Version 0.8.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="JandaBox" Version="0.8.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add JandaBox --version 0.8.1                
#r "nuget: JandaBox, 0.8.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install JandaBox as a Cake Addin
#addin nuget:?package=JandaBox&version=0.8.1

// Install JandaBox as a Cake Tool
#tool nuget:?package=JandaBox&version=0.8.1                

JandaBox

Build NuGet NuGet Version

Out of the box .NET8 templates

Template Name                            Short Name  Language  Tags
---------------------------------------  ----------  --------  ----------------
JandaBox ASP.NET Core Web API            webapibox   [C#]      JandaBox/WebApi
JandaBox Console App                     consolebox  [C#]      JandaBox/Console
JandaBox NuGet Class Library             nugetbox    [C#]      JandaBox/NuGet
JandaBox Service Classes and Extensions  servicebox  [C#]      JandaBox/Service

Learn more about templates in the wiki pages.

Quick Start

To install JandaBox templates use dotnet command.

dotnet new install JandaBox

You are now ready to use the templates from command line or from Visual Studio.

helloworld

Console Application

Create .NET8 console application with dependency injection, Serilog and configuration.

dotnet new consolebox -n HelloWorld

HelloWorld basic console app using command line interface

jandabox

Web API

Create .NET8 web API from webapibox template.

dotnet new webapibox -n MyWebService

Service Files

Add new service interface, implementation and extsions.

dotnet new servicebox -n DemoService --nameSpace MyApp.Services --logger

Add a new service tutorial

This tutorial demonstrates how to add simple service to the console application created with JandaBox.

Create demo console application.

C:\Demo>dotnet new consolebox
The template "JandaBox Console App" was created successfully.

Go to the source folder and create Services directory.

C:\Demo>cd src\Demo
C:\Demo\src\Demo>mkdir Services
C:\Demo\src\Demo>cd Services
C:\Demo\src\Demo\Services

Add demo service

dotnet new servicebox -n DemoService --nameSpace Demo.Services --logger
The template "JandaBox Service Classes and Extensions" was created successfully.

The template provides following files:

IDemoService.cs
namespace Demo.Services
{
    public interface IDemoService
    {

    }
}
DemoService.cs
using Microsoft.Extensions.Logging;

namespace Demo.Services
{
    internal class DemoService : IDemoService
    {
        private readonly ILogger<DemoService> _logger;

        public DemoService(ILogger<DemoService> logger) 
        {
            _logger = logger;
        }
    }
}
DemoServiceExtensions.cs
using Microsoft.Extensions.DependencyInjection;

namespace Demo.Services
{
    public static class DemoServiceExtensions
    {
        public static IServiceCollection AddDemoService(this IServiceCollection services)
        {
            return services.AddTransient<IDemoService, DemoService>();
        }
    }
}

You can do the same from the Visual Studio.

jandabox

Class Library into NuGet tutorial

This tutorial demonstrates how to create a new library, push it to GitHub, and publish it on NuGet.org using the JandaBox nugetbox template. Additionally, this tutorial provides explanations on why and how to create PAT tokens and NuGet.org tokens.

Here's what we aim to accomplish:

  1. The library will be named AnyoneDrive and will be available under the MIT license.
  2. The package's author is Matt Janda.
  3. Semantic versioning, as provided by GitVersion, will be used for versioning the library.
  4. The package will be published on GitHub under the Jandini owner.
  5. Automatic building and publishing of the package will be handled by GitHub actions.
  6. The package will be published to a private GitHub packages registry for each branch and commit. This approach allows you to create NuGet packages and test them without the need to publish them to the public NuGet.org.
  7. The package will be published to Nuget.org only after a tag is created.

Please note that you should replace Jandini and AnyoneDrive with your GitHub owner and your repository name, respectively.

Let's get started!

  • Create a new EMPTY repository in GitHub.

    • Head over to GitHub's repository creation page.
    • Create a new repository, making sure not to add a README.md, .gitignore, or license file.
    • Your repository will have a home at https://github.com/Jandini/AnyoneDrive.git.
  • Open your command line or terminal and run the following command to create a new project:

    dotnet new nugetbox -n AnyoneDrive --nuget --tagNugetOrg --license --authors "Matt Janda" --user Jandini --actions --gitVersion
    

    This command will create a new project named "AnyoneDrive". Once created, navigate to the folder and list its contents:

    cd AnyoneDrive
    dir
    

    The directory structure should resemble the following:

    06/10/2023  22:56    <DIR>          .github
    06/10/2023  22:56    <DIR>          src
    06/10/2023  22:56             6,001 .gitignore
    06/10/2023  22:56               241 GitVersion.yml
    06/10/2023  22:56             6,643 icon.png
    06/10/2023  22:56             1,067 LICENSE
    06/10/2023  22:56               476 README.md
    
  • Add the project to GitHub repository.

    Initialize a local Git repository and simultaneously create a new branch:

    git init -b main
    

    Add the remote origin to the local repository:

    git remote add origin https://github.com/Jandini/AnyoneDrive.git
    

    Stage all the files before creating the first commit:

    git add .
    

    Create the initial commit:

    git commit -m "First commit"
    

    Push the new branch to the remote GitHub repository, using -u to set the upstream branch that doesn't exist yet in the remote repository:

    git push -u origin main
    

You've successfully created a new project and made it available on GitHub. To view your repository, visit https://github.com/Jandini/AnyoneDrive

image-20231006231234635

The GitHub Actions have started executing the "Build" action, which is currently failing as expected. To investigate further, go to GitHub Actions by navigating to https://github.com/Jandini/AnyoneDrive/actions and check the build details to understand why it's failing.

The build is failing at the "Setup" step, and you'll see the following error message:

Error: The NUGET_AUTH_TOKEN environment variable was not provided. In this step, add the following: 
env:
  NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}

The NUGET_AUTH_TOKEN is an environment variable used in the context of the NuGet package manager, which is a package manager for .NET development. NuGet is used to manage and distribute libraries, frameworks, and tools for .NET applications.

This error occurs because the Setup step is attempting to configure dotnet to have access (source-url) to your private GitHub NuGet registry. You can find this configuration in your GitHub Actions workflow file at https://github.com/Jandini/AnyoneDrive/blob/main/.github/workflows/build.yml#L28:

- name: Setup
  uses: actions/setup-dotnet@v1
  with:
    dotnet-version: 7.0.x
    source-url: https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json

To resolve this issue, you should NOT follow the error's recommendation and use NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}. The GITHUB_TOKEN has read access only to your private GitHub NuGet registry, which will enable the Setup stage to proceed successfully.

However, the "Push" step will fail due to insufficient permissions with the provided GITHUB_TOKEN.

- name: Push
  # Push packages into private github repository 
  if: github.ref == 'refs/heads/main'
  run: dotnet nuget push "../bin/Release/*.nupkg" -k ${{ secrets.PACKAGE_REGISTRY_TOKEN }} -s https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json --skip-duplicate

In the workflow file (build.yml), the definition of NUGET_AUTH_TOKEN assigns the PACKAGE_REGISTRY_TOKEN secret string as follows:

env:
    NUGET_AUTH_TOKEN: ${{ secrets.PACKAGE_REGISTRY_TOKEN }}

The build is currently failing because your repository does not have the secret string that contains the Personal Access Token (PAT) required for successful execution.

Now, let's create a Personal Access Token (PAT) and add it to the secrets of your GitHub repository:

  1. Generate a PAT:

    • Go to your User Profile > Settings > Developer settings > Personal access tokens. Alternatively, you can follow this link: GitHub Token Settings.
    • Click on Generate new token (classic) and authenticate your user.
    • In the Note field, enter a name for your token (it can be anything you prefer).
    • Set the Expiration time according to your preference.
    • Select the following scopes:
      • write:packages - Allows you to upload packages to GitHub Package Registry.
      • read:packages - Enables downloading packages from GitHub Package Registry.
    • Click Generate Token.

    Be sure to copy the generated token and keep it in a secure place. This token can be used in multiple repositories.

  2. Add the Token to Repository Secrets:

    • Navigate to your AnyoneDrive repository on GitHub.
    • Go to Settings > Secrets and variables > Actions. You can access it directly via this link: Repository Secrets.
    • Click on New repository secret.
    • Set the Name to PACKAGE_REGISTRY_TOKEN, matching what's declared in your build.yml.
    • Paste the PAT token you obtained earlier into the Secret text box.

Now, the secret PACKAGE_REGISTRY_TOKEN is securely stored within your GitHub repository. Please note that you can update an existing secret if your PAT token expires. However, you won't be able to view the current value for security reasons.

Return to GitHub Actions and re-run any previously failed jobs. You should now have a successful build, and the first NuGet package will be available in your GitHub private NuGet registry.

image-20231007001333416

Resources

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.8.1 194 7/7/2024
0.8.0 112 6/30/2024
0.7.0 659 7/9/2023
0.6.0 385 4/11/2023
0.5.0 278 3/27/2023
0.4.0 272 3/26/2023
0.3.0 289 3/18/2023
0.2.0 370 2/17/2023
0.1.0 299 2/16/2023