I wrote a .net core console program that generates some code to help me speed up my development process. Now I would like to distribute this console program via NuGet, so I can use the tool in other projects like the command line tools from Entity Framework. But I read everywhere, that NuGet is only used for class libraries. But I want my package to be able to run and it should not be used for imports and stuff like that. And obviously Microsoft did that with the Entity Framework Tools, so I think there must be a way.
Can anybody point me in the right direction?
I found this question (Best practice to include console app in NuGet ) but the problem is, that the answer is, that it is not possible, which it is, as you can see with the EF Tools.
I found a solution and allready sucessfully shared the console package on nuget.org
You can create a command line extension for the dotnet
tools. Like dotnet ef
you can create a dotnet myAwesomeTool
command. The only thing that you need to do is the Following:
Create a console application and add the following code to your .csproj
<PackageId>Company.MyAwesomeTool</PackageId>
<AssemblyName>dotnet-myAwesomeTool</AssemblyName>
<PackageType>DotnetCliTool</PackageType>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
Build the solution and you will find a nuget package in your bin folder. This nuget package can be distributed and when you have installed it, you can run dotnet myAwesomeTool
in the projects where the nuget is installed. Works like a charm for me =)
To install it on other projects, add this to the csproj:
<ItemGroup>
<PackageReference Include="company.MyAwesomeTool" Version="1.0.0" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="company.MyAwesomeTool" Version="1.0.0" />
</ItemGroup>
For more infos: https://blog.maartenballiauw.be/post/2017/04/10/extending-dotnet-cli-with-custom-tools.html