DEV Community

Swapnil Takalkar
Swapnil Takalkar

Posted on • Edited on

How to build solution, run tests, create package using .Net commands.

Ever wondered that how build is executed in the build pipeline? Or maybe how tests are run in the build pipeline?

Well, DevOps certainly knows that. But .Net developers usually build the solution from visual studio using the menu.

Sometimes there will be too many errors or a glitch but commands can help you to know exact errors and eliminate the glitch if any.
Also these commands will be useful to build a pipeline.

Let’s get into the topic.

Pre requisite:

  • .Net framework (.Net core or above recommended)
  • Powershell or Developers Command Prompt for VS

Open the powershell/Developers Command Prompt and go to the directory where solution is located.

1) dotnet clean - Cleans the solution by removing obj, bin folders where build related files are being stored.

Image description

2) dotnet restore - Restore all the dependencies such as NuGet packages from the repository.

Image description

3) dotnet build - Build the solution, which will be ready to run.

Image description

4) dotnet test - Runs the tests from all of the test projects.

Image description

5) dotnet pack - Packs the solution so that it can be uploaded as an artifact.

Image description

6) dotnet publish - Publish the solution. Creates required files that needs to run the application in the publish folder.

Image description

Top comments (0)