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.
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.
Once you’ve installed .NET SDK, you can check the version of the dotnet installed SDK by running the following command
dotnet --info
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
To launch the .net core app without the visual studio
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
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" } } } }
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'
Here is how the output looks.
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.
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.
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.
Karthik is a passionate Full Stack developer working primarily on .NET Core, microservices, distributed systems, VUE and JavaScript. He also loves NBA basketball so you might find some NBA examples in his posts and he owns this blog.
In this post, we’ll see how to test gRPC Server applications using different clients. And… Read More
In this post, we'll create a new gRPC project in ASP.NET Core and see what's… Read More
Programmatically evaluating policies is useful when we want to provide access or hide some data… Read More
We saw how we could set up policy-based authorization in our previous article. In this… Read More
What is policy-based authorization and how to set up policy-based authorization with handlers and policies… Read More
What is role-based authorization? As the name says, role-based authorization authorizes a user based on… Read More
This website uses cookies.