15 Useful Command Line in Terminal That I Had Used
Use By Developers to execute commands.
As a Developer, you should know the command line from different terminals such as Package Manager Console on Visual Studio, PowerShell, iTerm on a Mac. There are a lot of other terminals that developers are using. The most popular one is PowerShell that you can use on Windows, and on Visual Studio, there is Package Manager Console. Another terminal used by programmers is the powerful iTerm2 that is only available for Mac users. Using those terminals, you could execute simple command lines. In this article, I will share some commands lines that, as a Developer, you should know and use.
Package Manager Console
A Package Manage Console is a terminal console in a Visual Studio used on Windows Operating System. In a Visual Studio, while you an implementing solution, you will need to install some NuGet Packages, which could be done from the software's interface, but you have to Browser through all the packages to find the ones you need. Using the Package Manager Console could save you more time than the Search Box. If you want to install any package, the general command line plus the package's name will help you:
If you are looking to install some package like Newtonsoft.Json or any other one on a specific project you want, you can use the command line below. Otherwise, if you want a package installed on the complete solution, you can do that to make sure your command line ends with the name of the package you wish to install. If you are installing a package on a complete solution, you don't need the name of your project.
Install-Package Newtonsoft.Json -ProjectName MyProject
To check if a package has a new version for an update that you could use is:
If you know or find a package with a new version, you can update it using:
Regarding updating NuGet packages, you should be careful it is recommended that those packages be compatible with the SDK you are using for your project. That will ensure that your project can be executable when you start it on Visual Studio.
Let me clarify the command lines above. Always you have command, but to be functionally working, you will need some extra information. In the case of the NuGet Packages, you will need to use the name of the package you need to install. If you want any package to be installed on a specific project, then you need to use the name of that project.
So in a Web project that you are working on, you can use the command line created and manage your database with Migration. You need to make sure you create a name for your Migration in the command line for this to work. Also, that is done only for Data Layers that is responsible for your database. You can use the command line below:
You can create your database with Migration by using a command-line containing a command and the name of the Migration you have made to build your database on a Server. You will need to say:
Creating your Migration via command line instead of coding will save you a lot of time as your code will be automatically generated with a simple command.
If you want to implement a database that is already created on a SQL Server, you need to use:
To achieve that, you need to expand this command line with the name of your database and the connection to the server to make sure it is a working connection that can engineer your database from your Server into Visual Studio.
You can take a look at the command line below. It will generate the DbContext that is needed in C# for your database. You could create a database with the connection to the server, so make sure you replace the dot in the command above with your service name and where you got "MyDatabaseName" you need to put the name of your database. It would be best to use the name NuGet package for the provider it is required. So your command will look like this, and you can copy it but make sure you replace two elements that I have mentioned above which are the dot and the name of your database:
Scaffold-DbContext -Connection "Server=.;Database=MyDatabaseName;Integrated Security=True;" -Provider Microsoft.EntityFrameworkCore.SqlServer
If you are looking to install PowerShell on your computer, you will need different commands, which will depend on your operating system. If you are on Windows, use:
dotnet tool install --global PowerShell
To install on Mac, use:
brew install --cask powershell
To verify if your install is working correctly on Mac, you can use a command line:
In case there is a new version of PowerShell released, use the upgrade and update formula:
brew upgrade powershell — cask
If you are a programmer who is using a Docker, you can save memory in your computer. So you need to download a Docker tool on your device, register for the Docker Hub and pull the image for any tool you want. So after you install Docker, you have to set it up and start it running. Use the following command to create:
docker run -d -p 80:80 docker/getting-started
- d (runs the container in the detached mode)
- -p 80:80 (map port 80 of the host and 80 port in the container
- docker/getting-started is an image you get in the Docker that helps you start the Docker
Next, to make sure your Docker is running correctly, you need to go to Dashboard and check for "Docker Desktop is running".
If you need a tool to use, you can do it in Docker, so you have to pull the image with:
docker pull PoweShell
The command should pull you the image of PowerShell in your Docker, but you can replace it with any name of a tool you want. Using SQL Server on Mac is also an option while creating your database with T-SQL on DBeaver. To pull the image for the SQL Server 2019, you use:
docker pull mcr.microsoft.com/mssql/server:2019-latest
The way to make it run is using the following command:
docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=<YourStrong@Passw0rd>" \ -p 1433:1433 --name sql1 -h sql1 \ -d mcr.microsoft.com/mssql/server:2019-latest
In the location of <YourStrong@Passw0rd>, you need to create your password for the SQL Server. Your port on a host and port need to "p1433:1433".
For a Mac user, you have to install Homebrew which you can do via command line:
brew install gh
In Conclusion, you can use any terminal like PowerShell to install any tool you need as a developer. You can create and manage a database which I show with Package Manager Console, but you can do it with PowerShell that is Command Line Interface, for which you need to make sure you have installed "dotnet ef" to make it work.