Search code examples
asp.net-coremsbuild.net-coredotnet-cli

Writing tasks using dotnet cli


My .net core application is getting amazing, and all the bros want to use it. I need to give them a fail safe way to get the project running, as well as a strategy for adding publish tasks down the road.

Right now, thanks to help I received in this question and this question, I run my application using the following command.

dotnet watch run --environment "Development"

I'd love it if I can get my devs using something more straightforward, maybe a custom task ala npm scripts:

dotnet run dev

I understand there is infrastructure to support this kind of thing via msbuild in a .csproj file, but the docs haven't worked out for me.


Solution

  • Nodejs has amazing cli and scripting features, thats what we use in our project for devops tooling.

    simply add a package.json with scripts:

    {
      scripts : {
        start: "dotnet watch run --environment Development",
      }
    }
    

    Now you can start your app either using: npm start or: npm run start, you can add tons of scripts if you want.

    If you want more freedom for developers to choose look at how to make a cli tool yourself. its very easy and i feel using a scripting language gives more freedom then using any msbuild/C# code tooling. and cli arguments parsing npm package.

    This ofcourse needs every developer to have node installed though.

    we did something like this in the commandline: ourAppName start --watch --environment Development --config Debug (ofc these are default flags). With nodejs you can spawn new processes and giving these processes new Environment Variables so its easy to overwrite, even appsettings this way.