DEV Community

netsi1964 🙏🏻
netsi1964 🙏🏻

Posted on

Run command when dotnet project builds

Sometimes you want some other action to happen before or after your dotnet application builds, for instance you would run a NPM command to build a TailwindCSS project to get latest CSS for your webapp. Dotnet can do that through a configuration, like this one shown here.

Say "Building" when your app is building

Simply add this to your .csproj file:

<Project Sdk="Microsoft.NET.Sdk.Web">
...
<Target Name="SayBuilding" BeforeTargets="Build">
  <Exec Command="say building" />
</Target>
Enter fullscreen mode Exit fullscreen mode

This Target block will execute the command say building which on MacOs will make your computer simply say "building".

This is not a practical thing to do, but you can replace the command with any command, like running a npx command. If you have build targets you can use them also, and you can also use AfterTargets instead.

Top comments (0)