DEV Community

Karthik Chintala
Karthik Chintala

Posted on • Originally published at coderethinked.com on

Run dotnet core projects without opening visual studio

In this blog post, we’ll see how to run dotnet core projects without opening visual studio. We all know Visual Studio is a great IDE and most developers already have visual studio installed on their computers.

In the microservice world, if we have .net core as our backend and we will sometimes have to launch multiple instances of visual studio and run them.

I had this trouble running multiple instances of Visual Studio for our product, but the laptop suffers to perform well though it has 32 GB of memory as I’ve to keep other programs open (like SQL server, vs code, etc).

What if I say we can run the .net core applications without launching visual studio at all? Yes, we can do this with .NET CLI.

Prerequisites

To do this, you have to install .NET CLI, which is a command line interface for developing, building, running, and publishing .net apps.

.NET CLI comes with .NET SDK. Starting with .NET Core 3.1 SDK, the .NET CLI is baked into .NET Core SDK. So, install a .NET SDK to get it working.

Checking the dotnet version with CLI

Once you’ve installed .NET SDK, you can check the version of the dotnet installed SDK by running the following command

dotnet --info
Enter fullscreen mode Exit fullscreen mode

Running the app with .NET CLI

Here is what dotnet run command can do for us

dotnet run [-a|--arch <ARCHITECTURE>] [-c|--configuration <CONFIGURATION>]
    [-f|--framework <FRAMEWORK>] [--force] [--interactive]
    [--launch-profile <NAME>] [--no-build]
    [--no-dependencies] [--no-launch-profile] [--no-restore]
    [--os <OS>] [--project <PATH>] [-r|--runtime <RUNTIME_IDENTIFIER>]
    [-v|--verbosity <LEVEL>] [[--] [application arguments]]

dotnet run -h|--help

Enter fullscreen mode Exit fullscreen mode

To launch the .net core app without the visual studio

  • launch your favorite terminal
  • navigate to the project folder
  • enter dotnet run in the terminal and press Enter.

This should build the project and run the app, you should see port numbers with http and https in the terminal. The output should look something like this

dotnet run with default profile

When F5 key is pressed, Visual Studio launches the URL in a browser window, but the dotnet run command does not launch the URL in any browser window. You have to do it manually.

If we don’t provide any arguments to the dotnet run command line just as we did, it will launch the application with the default profile. You can find profiles in properties\\launchSettings.json file.

The default profile is the one with the same project name in the launchSettings.json file. You can define as many profiles as you want. Here is my launchSettings.json file

{
  "$schema": "<https://json.schemastore.org/launchsettings.json>",
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "<http://localhost:50206>",
      "sslPort": 44364
    }
  },
  "profiles": {
    "dotnet_cli_test": {
      "commandName": "Project",
      "dotnetRunMessages": true,
      "launchBrowser": true,
      "launchUrl": "swagger",
      "applicationUrl": "<https://localhost:7136>;<http://localhost:5008>",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "swagger": {
      "commandName": "Project",
      "launchBrowser": true,
      "launchUrl": "swagger",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "launchUrl": "swagger",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }
}

Enter fullscreen mode Exit fullscreen mode

Launching dotnet run with a different profile name

If you have multiple profiles configured in launchSettings.json file and want to run other profile other than the default one you can use the —launch-profile switch on the dotnet run command.

It should look something like this

dotnet run --launch-profile 'swagger'

Enter fullscreen mode Exit fullscreen mode

Here is how the output looks.

dotnet run with custom launch profile

This time the port numbers were assigned automatically because our swagger profile does not have any application url’s defined.

That’s it. This is how .NET CLI can run .NET Core applications in the command line without opening visual studio IDE.

Command Line programs take way less memory than a Visual Studio IDE.

That’s okay for running programs but how do I get the power of IDE?

Well, you can use text editors (Visual Studio Code, Atom) that has C# extensions. Once you’ve installed extensions in Visual Studio Code you get similar features that are in a visual studio like intellisense, running tests, debugging, navigating through files, etc.

Yes, Visual Studio Code may not replace Visual Studio’s capabilities as an IDE. But, I’ll say you can live with what you have in Visual Studio Code for normal editing stuff.

Conclusion

In this post, we have seen how to install .NET CLI and how to run a .NET Core project without opening visual studio by making use of the .NET CLI command dotnet run and we’ve seen how to run a project with a different profile other than the default.

.NET CLI is much more than just running your project.

The .NET CLI has several commands which are mostly used for building, deploying, and running applications.

References

The post Run dotnet core projects without opening visual studio appeared first on Code Rethinked.

Top comments (0)