Common .NET commands needed to run solutions in VSCode
ctrl + shift + p
-> .NET Generate Assets
- for checking command usages, do
dotnet --help
- this is a nested command, you can also
dotnet build --help
- this is a nested command, you can also
- you can list templates using
dotnet new list
- search local templates
dotnet new list <fuzzy_search_input>
- search local templates
- you can also search online templates using
dotnet new search "Clean Architecture"
- you can search by author too by passing
--author mariyam
or--author="mariyam"
- then install template via package name, like
dotnet new install Custom.Online.Template
- This will install locally, now just create template like usual
dotnet new custom-template
- you can search by author too by passing
- A very important argument that can be passed is
--dry-run
to well, do what it says.- usage,
dotnet new gitignore --dry-run -v diag
- usage,
- you can recursively add all projects to sln using
dotnet sln add **/*.csproj
- then do
dotnet sln list
to see all projects in solution. - you can add references using
add
, eg:dotnet add Playground reference Playground2
- adds
ItemGroup > ProjectReference#Include
in.csproj
file
- adds
- list all references of a project,
dotnet list Playground/ reference
- add package,
dotnet add Playground package Error 0r
- you can also list packages, using
dotnet list Playground/ package
dotnet new gitignore
dotnet new globaljson
dotnet new editorconfig
- to apply config, do
dotnet format
optionally with verbose-v detailed
- to apply config, do
dotnet tool list
or globably with--global
(obviously, lol)dotnet tool install --global dotnetsay
- excute
dotnetsay
- excute
- create new console app
dotnet new console -o Playground
- write it, run it.
- in
.csproj
of project, addPackAsTool
as True, toPropertyGroup
- set
ToolCommandName
inPropertyGroup
as well, give some name.
- set
- do
dotnet pack -c Release -o CompanyToolAssets
or just "assets", whatever.- should save as
.nupkg
in assets.
- should save as
- can install globally now using
dotnet tool install --global --add-source assets/ MyTool
or whatever folder name. - sayconf
- use
dotnet tool run
to run local commands etc, very handy. Underused functions. - you can also search for tools
dotnet tool search dotnetsay
<fuzzy_input> - there is also a runtime option you can pass
--fx-version 7.0.0
to target another version.
dotnet new sln --name "BigProject"
- if
--name
is not specified, some convention is followed, just remove it using rm.
dotnet new webapi -lang "c#" -n "S5L2-Sandbox" -f "net7.0" -o S5L2-Sandbox -d -v diag
-
^ Note here,
.\
was not used when sepcifying output directory, usually, just -n is enough, it will automatically create directory, use -o if you want folder name to be different, or when grouping projects under specific folders. -
simpler way of adding projects.
dotnet new webapi -n API --use-controllers
dotnet new classlib -n Application
dotnet new console -o Playground
- difference between using
-o
and-n
is that, -n will autoamtiaclly create directory as same name. There might be slight difference based on naming convention, no confirmed. But using -o Will specify output folder. if -n is not specified, then same as folder is given to program. Just try it out.
- difference between using
dotnet sln add S5L2-Sandbox/S5L2-Sandbox.csproj
- ^ again, see how
.\
was omitted as we are in the same directory, this is different in windows.
dotnet run --project S5L2-Sandbox --launch-profile "https"
- ^ the command already looks for .csproj file, so just passing the directory here is fine.
dotnet watch --no-hot-reload --project .NET-Server/src/API run --environment "Development"
- ^ another way to run, with hot reload.
dotnet add API/API.csproj reference Application/Application.csproj
- ^ adding reference.
dotnet sln list
dotnet restore
dotnet --list-sdks
dotnet --info
dotnet --list-runtimes
- ^ common helpful commands.
- For commands to run for project setup, see
OT-ProjectSetup.sh
- If you have 2 projects, just create sln and add projects to sln first.
- Run startup project
dotnet run --project API
- You can run
.dll
's directly,dotnet MyProgram.dll
- You may pass arguments here too, refer to image at top.
dotnet add /workspaces/NETReact-Server/Persistence/Persistence.csproj package Microsoft.EntityFrameworkCore.Sqlite -v 8.0.1 -s https://api.nuget.org/v3/index.json
- adds reference in Persistence .csproj
- to list available dotnet tools ->
dotnet tool list -g
- for global tool installs, https://www.nuget.org/packages/dotnet-ef
dotnet tool install --global dotnet-ef --version 8.0.1
- probably have to match runtime version of .NET, but not sure about EF core version for projects
- you can check available dotnet-ef commands in the nuget page as well.
- update by doing
dotnet tool update
instead ofinstall
- for initial migration
dotnet ef migrations add InitialCreate -s API -p Persistence
dotnet add /workspaces/NETReact-Server/API/API.csproj package Microsoft.EntityFrameworkCore.Design -v 8.0.1 -s https://api.nuget.org/v3/index.json
- adds reference in API .csproj
dotnet watch --project API
- Had issue with ConString, use
dotnet watch --project API run --environment "Development"
instead. - Hot reload still have some issues, Author complaisn about .NET 7, I have issues in .NET 8.
- So add the
--no-hot-reload
flag to watch command
- So add the
- updated file structure so use
dotnet watch --no-hot-reload --project .NET-Server/src/API run --environment "Development"
instead
dotnet add /workspaces/.NET-React/.NET-Server/src/Application/Application.csproj package MediatR -v 12.2.0 -s https://api.nuget.org/v3/index.json
- use
dotnet build
in project level to update inter-project changes, as references dlls.- keep dotnet watch running during development so inter project changes will be available via dlls.
# Make File Executeable Using `chmod +x OT-ProjectSetup.sh"
# Run File Using `./OT-ProjectSetup.sh`
#!/usr/bin/env bash
green="\033[1;32m"
reset="\033[m"
echo "Creating Main Project Directory"
echo -e "${green}Skipped Creating Directory, Building in Current Directory${reset}"
# mkdir Reactivities
# cd Reactivities
echo -e "${green}Adding Git Ignore File${reset}"
dotnet new gitignore
echo -e "${green}Creating Solution & Projects${reset}"
dotnet new sln
dotnet new webapi -n API --use-controllers
dotnet new classlib -n Application
dotnet new classlib -n Domain
dotnet new classlib -n Persistence
echo -e "${green}Adding Projects To The Solution${reset}"
dotnet sln add API/API.csproj
dotnet sln add Application/Application.csproj
dotnet sln add Domain/Domain.csproj
dotnet sln add Persistence/Persistence.csproj
echo -e "${green}Setting Up Project Dependancies${reset}"
dotnet add API/API.csproj reference Application/Application.csproj
dotnet add Application/Application.csproj reference Domain/Domain.csproj
dotnet add Application/Application.csproj reference Persistence/Persistence.csproj
dotnet add Persistence/Persistence.csproj reference Domain/Domain.csproj
echo -e "${green}Executing Restore${reset}"
dotnet restore
echo -e "${green}Finished!${reset}"
echo "Listing Solution Linked Projects.."
dotnet sln list
dotnet new gitignore
dotnet new sln
dotnet new console -lang "c#" -n "One" -f "net8.0" -o src/First/one -d -v diag
dotnet new console -lang "c#" -n "Twi" -f "net8.0" -o src/First/two -d -v diag
dotnet new web -lang "c#" -n "Second" -f "net8.0" -o src/Second -d -v diag
dotnet sln add src/First/one
dotnet sln add src/First/two
dotnet sln add src/Second
dotnet run --project src/Second
![](https://private-user-images.githubusercontent.com/81725875/366835470-a44f6ada-3ec4-4e22-8c42-dfe303708914.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkwNjA4NjUsIm5iZiI6MTczOTA2MDU2NSwicGF0aCI6Ii84MTcyNTg3NS8zNjY4MzU0NzAtYTQ0ZjZhZGEtM2VjNC00ZTIyLThjNDItZGZlMzAzNzA4OTE0LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMDklMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjA5VDAwMjI0NVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTZhM2ZhYzkxY2EyYjNjMzg1NmZiOTkzMTg5OTQyZTYyMDlhYTA3NTM2MGM1YTU3MWJhNWQ2MWI2M2U4MzhiMmQmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.FoI4xoDZUWDqHnlF_iBe1gDaOqni7MU2AlLkspYXkq0)
Amichai Mantinband, 2022, YouTube, https://www.youtube.com/watch?v=gPoUSBnrYFU
Amichai Mantinband, 2022, YouTube, https://www.youtube.com/watch?v=gPoUSBnrYFU
you can also pass arguments here.
Amichai Mantinband, 2022, YouTube, https://www.youtube.com/watch?v=gPoUSBnrYFU
Amichai Mantinband, 2022, YouTube, https://www.youtube.com/watch?v=gPoUSBnrYFU
![](https://private-user-images.githubusercontent.com/81725875/366849497-39da4512-d438-46fd-9f30-5f8634258a54.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkwNjA4NjUsIm5iZiI6MTczOTA2MDU2NSwicGF0aCI6Ii84MTcyNTg3NS8zNjY4NDk0OTctMzlkYTQ1MTItZDQzOC00NmZkLTlmMzAtNWY4NjM0MjU4YTU0LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMDklMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjA5VDAwMjI0NVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTQ3M2JjNmQ5NTUyZmY3NGE2NWJhOGJjZWRkZjQwM2RlZTk2NzQwNGRlYzVjY2ExYmYyNTlmMzE2ZTQ3MmQ0ZWImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.mBoWfMYCgspGmz2M42vduOEsEuoW6fYdjUHYoAu2iL4)
Amichai Mantinband, 2022, YouTube, https://www.youtube.com/watch?v=gPoUSBnrYFU
![](https://private-user-images.githubusercontent.com/81725875/366849685-e1246ffa-58a5-45f6-8c6a-101fcae89339.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkwNjA4NjUsIm5iZiI6MTczOTA2MDU2NSwicGF0aCI6Ii84MTcyNTg3NS8zNjY4NDk2ODUtZTEyNDZmZmEtNThhNS00NWY2LThjNmEtMTAxZmNhZTg5MzM5LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMDklMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjA5VDAwMjI0NVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTUzMTFiZDM0NjE4YWZjMjFmNzE3NzU5Nzg0MWU0MjM5NTllYzA0OWE5OWNlN2M3MGRiMTkyZjFkNTRlZjg0NDEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.OWP21KWtgmgw4SHMBIoDRGR0gdZ-3KgAxVxSJzhbx5o)
Amichai Mantinband, 2022, YouTube, https://www.youtube.com/watch?v=gPoUSBnrYFU
![](https://private-user-images.githubusercontent.com/81725875/366850292-7a4fc1ec-06ac-4ac6-bd6f-dfb36ed6542c.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkwNjA4NjUsIm5iZiI6MTczOTA2MDU2NSwicGF0aCI6Ii84MTcyNTg3NS8zNjY4NTAyOTItN2E0ZmMxZWMtMDZhYy00YWM2LWJkNmYtZGZiMzZlZDY1NDJjLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMDklMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjA5VDAwMjI0NVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWE3YWRjNTNkMjZlOTg4MjJkMTkzODAyN2YwZjdmMjc3MTMyNTNmMDUyZDUyN2M5Y2UzZDlhM2NhY2VmYjkyZjgmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.q76AQvHfkLuWK__G3P2o7E3eqPtxCmaqsoJQEJuIPcs)
Amichai Mantinband, 2022, YouTube, https://www.youtube.com/watch?v=gPoUSBnrYFU
![](https://private-user-images.githubusercontent.com/81725875/366855217-0677e8bf-4883-4aa9-808f-ef3f34bfc589.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkwNjA4NjUsIm5iZiI6MTczOTA2MDU2NSwicGF0aCI6Ii84MTcyNTg3NS8zNjY4NTUyMTctMDY3N2U4YmYtNDg4My00YWE5LTgwOGYtZWYzZjM0YmZjNTg5LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMDklMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjA5VDAwMjI0NVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWQ5NGVjMzhjM2M4NDQyNDljOWE2MTZjZGU4OGVhYWYwMDRkNzVlMWVkYjliYzY5MmU4ZTc2NGY4ZWMxMjk1NDUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.NZxj0XnHi2SbcGOVpZXjHUOwB_nR709UooQDke8-YQA)
Amichai Mantinband, 2022, YouTube, https://www.youtube.com/watch?v=gPoUSBnrYFU
![](https://private-user-images.githubusercontent.com/81725875/366859427-c0d75ad1-7346-481a-a210-d4ec4166b788.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkwNjA4NjUsIm5iZiI6MTczOTA2MDU2NSwicGF0aCI6Ii84MTcyNTg3NS8zNjY4NTk0MjctYzBkNzVhZDEtNzM0Ni00ODFhLWEyMTAtZDRlYzQxNjZiNzg4LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMDklMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjA5VDAwMjI0NVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWU2NTc2ZmNlNmIyODczMDVkZWZkMGRjNWU3YjUxOWUxMmYzY2UxYjQ5Njk4NGEzMjM4Nzg0MTBmZWZmNzBmNWMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.GjTy6fp3VJlxwVECfdBiXreULUSoFZ1cmawWcwmFxsY)
Amichai Mantinband, 2022, YouTube, https://www.youtube.com/watch?v=gPoUSBnrYFU