DotNetCore.Artisan 1.0.0

dotnet add package DotNetCore.Artisan --version 1.0.0                
NuGet\Install-Package DotNetCore.Artisan -Version 1.0.0                
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="DotNetCore.Artisan" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DotNetCore.Artisan --version 1.0.0                
#r "nuget: DotNetCore.Artisan, 1.0.0"                
#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 DotNetCore.Artisan as a Cake Addin
#addin nuget:?package=DotNetCore.Artisan&version=1.0.0

// Install DotNetCore.Artisan as a Cake Tool
#tool nuget:?package=DotNetCore.Artisan&version=1.0.0                

DotNetCore.Artisan

With this package you will be able to add artisan commands to your dotnet core project and run your own custom commands while you are at production. Inspired from Laravel The commands will have the IServiceProvider injected into their constuctor so you can create your scope to have the DbContext and other scoped dependencies.

Note: The commands will be added as Transient.

Installation

This is available in nuget package store.

You also can add it with dotnet cli with the following command.

dotnet add package DotNetCore.Artisan

Usage

First you need to change your Program.cs to make sure that on run it checks for artisan commands. Please change your Program.cs to the following:

CreateHostBuilder(args).Build().RunWithCommands(args);

Note: Noticed the change? normally it is Run() which will run your app but we first check if we are running with any of the registered commands and if not then it will run normally

For this next step I am used to give the terminal their own Folder so you can create a "Terminal" folder and add a Kernel.cs in there.

Kernel.cs file will handle the registeration of your commands into IServiceCollection like below:

    public static class Kernel
    {
        public static IServiceCollection AddDefaultArtisan(this IServiceCollection services)
        {
            services.AddArtisanTerminal(options => {
                options.AddCommand<YOUR_CUSTOM_COMMAND>();
            });
            return services;
        }
    }

The command that your are going to add into your ArtisanCommands must implement the ITerminalCommand which will get a name and has an "Execute" method which your main code will be placed there. Also you can use IServiceProvider inside your ITerminalCommand from the constructor for getting the scoped dependencies or normal Transient dependencies.

I hope you find this useful and have a nice time programming 😉

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.1 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
1.0.0 8,008 1/30/2021