Good news, everyone! It is remarkably easy to make a new dotnet CLI (Command Line Interface) tool! I recently created a CLI tool for one of my new projects, Tact.NET RPC, and in this post I will be referencing that project as my example.
The Basics
Step 1) Create your CLI Console App
All you have to do is...
- Create a normal .NET Core Console App.
- NOTE: Currently, the dotnet CLI only supports netcoreapp1.0
- Rename the assembly to be prefixed with "dotnet-"
- dotnet pack the project and put the package in your local NuGet package source
...that is it! It is literally that easy to create your CLI tool!
Recommendation: use Microsoft.Extensions.Configuration to parse your command line arguments in a standard way.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp1.0</TargetFramework>
<AssemblyName>dotnet-tactrpcgen</AssemblyName>
<PackageId>Tact.Rpc.Generator</PackageId>
<Version>1.0.3</Version>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="1.1.1" />
</ItemGroup>
</Project>
Step 2) Consume your CLI Tool NuGet Package
Edit your csproj file and add a DotNetCliToolReference element that references your package.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard1.6</TargetFramework>
</PropertyGroup>
<ItemGroup>
<DotNetCliToolReference Include="Tact.Rpc.Generator" Version="1.0.3" />
</ItemGroup>
</Project>
Now you are able to invoke your console app via the dotnet command line whenever it is executed in the same path as the csproj.
That's it; it really is that easy!
Development Tips
Here is a simple way to automate the creation and consumption of your CLI tool NuGet package during development.
Create a local package directory
I recommend that you create a packages folder at the root of your solution along with a NuGet.config file; this will allow you to automatically build and consume NuGet packages from this location.
<configuration>
<packageSources>
<add key="LocalPackages" value="packages" />
</packageSources>
</configuration>
Pack on post build
Go back and update your CLI tool's csproj to include a post build step that packs your project and places the output in your package folder. (There is a csproj GeneratePackageOnBuild setting, however at this time I do not believe that you can customize the output directory, so instead I recommend using a post build step.)
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp1.0</TargetFramework>
<AssemblyName>dotnet-tactrpcgen</AssemblyName>
<PackageId>Tact.Rpc.Generator</PackageId>
<RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent>
<PostBuildEvent>
dotnet pack $(SolutionDir)rpc\src\Tact.Rpc.Generator -o $(SolutionDir)packages --no-build
</PostBuildEvent>
<Version>1.0.3</Version>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="1.1.1" />
</ItemGroup>
</Project>
Execute on pre build
Obviously this is a completely optional step that should only be used when necessary; in the case of Tact.NET RPC, the active code generation is powered by the CLI tool, and thus it needs to run every build.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard1.6</TargetFramework>
<PreBuildEvent>
cd $(SolutionDir)rpc\demo\Demo.Rpc
dotnet tactrpcgen
</PreBuildEvent>
</PropertyGroup>
<ItemGroup>
<DotNetCliToolReference Include="Tact.Rpc.Generator" Version="1.0.3" />
</ItemGroup>
</Project>
Increment version to update
NOTE: Despite updating the your local package directory each build, the package will actually be cached in your global NuGet cache, and thus updates will not be picked up unless you increment the version number.
Enjoy,
Tom
The code generator module utilizes the "parse information" to build the test saddle source code.
ReplyDeletemélybölcsős fuvarozás Europa-Road Kft.
Thanks For https://crackerpc.com/startisback-6/k You can also visit my Website windowsroom.com
ReplyDeletePakistan no.1 Article in my softcrackersstore.com site Now just 1 click to download!
ReplyDeleteGoodSync Crack
Brave Browser Crack
VSDC Video Editor Pro Crack
Thank you so much for sharing.
ReplyDeletephotosweeper crack
autodesk-powermill crack
kls backup pro crack
airparrot crack
auslogics boostspeed premium crack
snaptube crack
Nice content
ReplyDeleteWrestling game
granny chapter 3
Zooba
Zaruto Wallpaper
Thanks for the great post you posted. I like the way you describe the unique content. The points you raise are valid and reasonable. I am a tech support expert telling you about.
ReplyDeletebest cryptocurrency exchange|
kraken exchange|
uniswap exchange |
crypto.com exchange|
Cryptocurrencies have evolved and managed to leave a mark in the next chapter of the financial industry along with tech improvisations. It has been quite the journey for the digital currencies from no financial worth to hundreds of dollars’ worth. robinhood wallet | robinhood crypto wallet
ReplyDeleteFinances in our world were given an online existence and backed with digital cryptography, it is now known as cryptocurrency. To make crypto easily accessible to the entire world, crypto exchange platforms came to life along with crypto wallets to provide a safe space for your crypto funds.
ReplyDeleteCoinbase.com login |
Pro.coinbase.com Login |
Coinbase Wallet
Binance is a cryptocurrency exchange that provides a platform for trading various cryptocurrencies. In addition, it provides a crypto wallet for its traders, where they can store their electronic funds.
ReplyDeletebinance us login
The exchange also has supporting programs that help traders make investment decisions. In addition, Binance has its blockchain-based token, Binance Coin.
binance.com login
These are genuinely fantastic ideas about blogging really. You have touched some very nice points here. Please keep up this good writing.
ReplyDeleteB Sc 1st NC Result
If you have the details that you need to fill up your Uphold sign-up form then you need to jump to the next section to start the sign-up and login process.
ReplyDeleteuphold login
Kraken is considered one of the most preferred crypto exchanges for Bitcoin trading. Trading Bitcoin kraken is safer on this exchange.
kraken login
The principal justification behind these is to get the youngster's advantage up and get the inventive energies siphoning and capability commendably all through the juvenile years. Clearly, PC games entered the picture sooner or later after the young person sorted out some way to press a catch and will continue into adulthood in an astonishing number of cases. toys remote control toys
ReplyDeleteUphold is available on both desktop computers and smartphones, so to get started with this cryptocurrency exchange platform, you must either visit Uphold.com or find the uphold app in your phone’s app store.
ReplyDeleteuphold wallet|uphold exchange|blockfi wallet|block fi wallet | blockfi app |
Thanks for giving such a wonderful informative information. The detailed read above has been fully-equipped to first, introduce you to the Kucoin App and then take you through exclusive details on the subject. Reading through the data piece above, you are now aware of all the pros and cons that an easily-created KuCoin login account could bring to you, along with significant details on the United States’ jurisdiction that doesn’t allow the exchange to function there and also the list of major crypto available on it.
ReplyDeleteFor More About:- Binance smart chain wallet$Kucoin.com$Kucoin Wallet