Search code examples
c#asp.net-coreasp.net-core-cli

Custom NET CORE CLI tool does not run on build


I have written a small test tool

namespace dotnet_cqsgen
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            File.WriteAllText(@"c:\temp\test.txt", "Hello");

        }
    }
}

Published it to a local nuget repo and added this to a host core project

  <ItemGroup>
    <DotNetCliToolReference Include="dotnet-cqsgen" Version="1.0.3" />    
  </ItemGroup>

Also the tool csproj

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.2</TargetFramework>
    <RootNamespace>dotnet_cqsgen</RootNamespace>
    <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
    <PackageType>DotnetCliTool</PackageType>
    <Version>1.0.3</Version>
  </PropertyGroup>    
</Project>

Though when I build the host project neither Hello world is written to console or text file is generated at c:\temp

What am I doing wrong?

Update:

  <Target Name="MyCliToolTarget" AfterTargets="Build">
    <Exec Command="dotnet cqsgen" />
  </Target>

Solution

  • Like suggested by Panagiotis Kanavos you you also need to call the cli tool

      <Target Name="MyCliToolTarget" AfterTargets="Build">
        <Exec Command="dotnet cqsgen" />
      </Target>