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.

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs