Skip to content

Commit d775633

Browse files
authored
Merge pull request #13 from webmaster442/next
Next
2 parents 52b0d67 + 2d14fe1 commit d775633

36 files changed

+4129
-1882
lines changed

000-start.md

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
:::parent
2+
3+
[toc maxlevel="2"] Contents
4+
5+
:::content
6+
7+
![cheat sheet header](img/header.svg)
8+
9+
<hr class="pagebreak">
10+
11+
## Authors
12+
13+
* Ruzsinszki Gábor - https://www.linkedin.com/in/gabor-ruzsinszki-b564a8181/
14+
15+
## License
16+
17+
This work is licensed under a [Creative Commons Attribution-ShareAlike 4.0 International License](https://creativecommons.org/licenses/by-sa/4.0/).
18+
19+
The .NET Logo is copyright of the .NET authors. - https://github.com/dotnet/brand
20+
21+
![CC BY SA](img/by-sa.svg)
22+
23+
24+
The project is open-source and available on GitHub. You can contribute to it by visiting project's GitHub repository: https://github.com/webmaster442/ultimatedotnetcheatsheet
25+
26+
![QR Code](img/qrcode.svg)
27+
28+
## Changelog
29+
30+
* **2024.02.29**
31+
32+
Initial release
33+
34+
* **2024.03.08**
35+
36+
Generic math interfaces extended & various small improvements
37+
38+
* **2024.04.08**
39+
40+
* Grammar fixes by CsabaDu
41+
* dotnet commands extended with previously missing commands
42+
* Print layout changes
43+
* Installable as a web app
44+
* Cryptography and UI chapters
45+
46+
* **2024.05.12**
47+
48+
* PWA & website: added Github project link and print support
49+
* Extended LINQ chapter
50+
* Added powershell commands section
51+
* Added reflection section
52+
* Format strings: Added few examples
53+
* Extended Exceptions chapter

010-basiccommands.md

+152
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
# Dotnet basic commands
2+
3+
* Check .NET version: `dotnet --version`
4+
* List installed .NET SDKs: `dotnet --list-sdks`
5+
* Show up-to-date status of installed .NET SDKs and .NET Runtimes: `dotnet sdk check`
6+
7+
## New
8+
9+
* Create new gitignore file in current dir: `dotnet new gitignore`
10+
* Create new editorconfig file in current dir: `dotnet new editorconfig`
11+
* Create new solution with name: `dotnet new sln -n "Name of solution"`
12+
* Create new class libary: `dotnet new classlib -n "Name of lib"`
13+
* Create new console app: `dotnet new console -n "Program name"`
14+
* Create new nunit test project: `dotnet new nunit -n "test project name"`
15+
* Create new xunit test project: `dotnet new xunit -n "test project name"`
16+
17+
## Solution management
18+
19+
* List projects in solution: `dotnet sln [solution.sln] list `
20+
* Add project to solution: `dotnet sln [solution.sln] add [project.csproj]`
21+
* Remove project from solution: `dotnet sln [solution.sln] remove [project.csproj]`
22+
23+
Note: solution file name can be ignored if folder only contains one `.sln` file.
24+
25+
## Package management
26+
27+
* List package references for project: `dotnet list [project.csproj] package`
28+
* List package references for solution: `dotnet list [solution.sln] package`
29+
* Add or update a package reference: `dotnet add [project.csproj] package [packagename]`
30+
* Remove a package reference: `dotnet remove [project.csproj] package [packagename]`
31+
* Restore package dependencies of project: `dotnet restore [project.csproj]`
32+
* Restore package dependencies of solution: `dotnet restore [solution.sln]`
33+
* Pack current project to nuget package: `dotnet pack [project.csproj]`
34+
35+
## Build & Run
36+
37+
* Build solution in debug mode: `dotnet build [solution.sln] -c DEBUG`
38+
* Build solution in release mode: `dotnet build [solution.sln] -c RELEASE`
39+
* Build project in debug mode: `dotnet build [project.csproj] -c DEBUG`
40+
* Build project in release mode: `dotnet build [project.csproj] -c RELEASE`
41+
* Clean output of a project: `dotnet clean [project.csproj]`
42+
* Clean output of a solution: `dotnet clean [solution.sln]`
43+
* Run a compiled assembly: `dotnet run [assembly.dll]`
44+
* Run tests: `dotnet test [testproject.csproj]` or `dotnet test [solution.sln]`
45+
46+
## Tool management
47+
48+
* Install a tool: `dotnet tool install [tool Name]`
49+
* Install a tool globaly: `dotnet tool install -g [tool Name]`
50+
* List installed tools: `dotnet tool list`
51+
* List globaly installed tools: `dotnet tool list -g`
52+
* Remove a tool: `dotnet tool uninstall [tool Name]`
53+
* Remove a globaly installed tool: `dotnet tool uninstall -g [tool Name]`
54+
* Update a tool: `dotnet tool update [tool Name]`
55+
* Update a globaly installed tool: `dotnet tool update -g [tool Name]`
56+
57+
Globally means that the tool is installed to the users profile, instead of the current project/solution.
58+
59+
## NuGet
60+
61+
* Display all cache directories: `dotnet nuget locals all --list`
62+
* Clear all files from all local cache directories: `dotnet nuget locals all --clear`
63+
* Push a package to the NuGet repository: `dotnet nuget push [package.nupkg] -k [api key]`
64+
* Push a package to a custom NuGet feed: `dotnet nuget push [package.nupkg] -k [api key] -s [feed url]`
65+
* Push all .nupkg files in the current directory to a local feed directory: `dotnet nuget push "*.nupkg" -s [feed directory]`
66+
* List all configured NuGet sources: `dotnet nuget list source [source name]`
67+
* Remove a NuGet source: `dotnet nuget remove source`
68+
* Add a NuGet source: `dotnet nuget add source [url or local path] -n [source name]`
69+
* Update a NuGet source: `dotnet nuget update source [source name]`
70+
71+
## Formating
72+
73+
* Create a new editorconfig file: `dotnet new editorconfig`
74+
* Format all code in the solution or a project: `dotnet format [solution.sln or project.csproj]`
75+
* Verify that all code is correctly formatted: `dotnet format --verify-no-changes`
76+
77+
## Workloads
78+
79+
* List all available workloads: `dotnet workload search`
80+
* Install an optional workload: `dotnet workload install [workload id]`
81+
* Uninstall a workload: `dotnet workload uninstall [workload id]`
82+
* List installed workloads: `dotnet workload list`
83+
* Repair workload installations: `dotnet workload repair`
84+
* Update installed workloads: `dotnet workload update`
85+
* Install workload needed for a project or a solution: `dotnet workload restore [soluton.sln or project.csproj]`
86+
87+
## Tools
88+
89+
* Install a tool: `dotnet tool install --global [tool name]`
90+
* Uninstall a tool: `dotnet tool uninstall --global [tool name]`
91+
* Lists all tools that are currently installed: `dotnet tool list --global`
92+
* Searches all .NET tools that are published to NuGet: `dotnet tool search [tool name]`
93+
94+
Global tools are installed in `$HOME/.dotnet/tools` on Linux and macOS. On Windows they are installed in the `%USERPROFILE%\.dotnet\tools` folder. Instead of the `--global` switch use the `--tool-path [folder]` to install the tool to a custom directory. If no `--global` or `--tool-path` is specified, then the tool is installed to the current C# project.
95+
96+
## Useful tools
97+
98+
* **dotnet-ef**
99+
100+
The command-line interface (CLI) tools for Entity Framework Core perform design-time development tasks. For example, they create migrations, apply migrations, and generate code for a model based on an existing database. The commands are an extension to the cross-platform dotnet command, which is part of the .NET Core SDK. These tools work with .NET Core projects.
101+
102+
Install with: `dotnet tool install --global dotnet-ef`
103+
104+
More info: https://learn.microsoft.com/en-us/ef/core/cli/dotnet
105+
106+
* **csharprepl**
107+
108+
A cross-platform command line REPL for the rapid experimentation and exploration of C#. It supports IntelliSense, installing NuGet packages, and referencing local .NET projects and assemblies.
109+
110+
Install with: `dotnet tool install -g csharprepl`
111+
112+
More info: https://github.com/waf/CSharpRepl
113+
114+
* **IronPython**
115+
116+
IronPython is an open-source implementation of the Python programming language that is tightly integrated with .NET. IronPython can use .NET and Python libraries, and other .NET languages can use Python code just as easily.
117+
118+
Install with: `dotnet tool install -g IronPython.Console`
119+
120+
More info: https://ironpython.net/
121+
122+
* **dotnet-format**
123+
124+
Dotnet-format is a code formatter for dotnet that applies style preferences to a project or solution. Preferences will be read from an `.editorconfig` file, if present, otherwise a default set of preferences will be used.
125+
126+
Install with: `dotnet tool install -g dotnet-format`
127+
128+
More info: https://github.com/dotnet/format
129+
130+
* **.NET Upgrade Assistant**
131+
132+
The .NET Upgrade Assistant is a Visual Studio extension and command-line tool that's designed to assist with upgrading apps to the latest version of .NET.
133+
134+
Install with: `dotnet tool install -g upgrade-assistant`
135+
136+
More info: https://dotnet.microsoft.com/en-us/platform/upgrade-assistant
137+
138+
* **SlnGen**
139+
140+
SlnGen is a Visual Studio solution file generator. Visual Studio solutions generally do not scale well for large project trees. They are scoped views of a set of projects. Enterprise-level builds use custom logic like traversal to convey how they should be built by a hosted build environment. Maintaining Visual Studio solutions becomes hard because you have to keep them in sync with the other build logic. Instead, SlnGen reads the project references of a given project to create a Visual Studio solution on demand. For example, you can run it against a unit test project and be presented with a Visual Studio solution containing the unit test project and all of its project references.
141+
142+
Install with: `dotnet tool install --global Microsoft.VisualStudio.SlnGen.Tool --add-source https://api.nuget.org/v3/index.json --ignore-failed-sources`
143+
144+
More info: https://github.com/microsoft/slngen
145+
146+
* **Roslynator Cli**
147+
148+
Roslynator is a set of code analysis tools for C#, powered by Roslyn.
149+
150+
Install with: `dotnet tool install -g roslynator.dotnet.cli`
151+
152+
More info: https://josefpihrt.github.io/docs/roslynator/cli

020-project.md

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Project file XML settings
2+
3+
* Enable implicit usings:
4+
5+
```xml
6+
<PropertyGroup>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
</PropertyGroup>
9+
```
10+
11+
* Enable nullable reference types
12+
13+
```xml
14+
<PropertyGroup>
15+
<Nullable>enable</Nullable>
16+
</PropertyGroup>
17+
```
18+
* Set internals visible to an other project
19+
20+
```xml
21+
<ItemGroup>
22+
<InternalsVisibleTo Include="ProjectName"/>
23+
</ItemGroup>
24+
```
25+
* Do not append target framework to output path
26+
27+
```xml
28+
<PropertyGroup>
29+
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
30+
</PropertyGroup>
31+
```
32+
* Set Assembly version based on build date (year.month.date)
33+
34+
```xml
35+
<PropertyGroup>
36+
<Version>
37+
$([System.DateTime]::UtcNow.ToString("yyyy")).$([System.DateTime]::UtcNow.ToString("MM"))
38+
.$([System.DateTime]::UtcNow.ToString("dd")).0
39+
</Version>
40+
<AssemblyVersion>
41+
$([System.DateTime]::UtcNow.ToString("yyyy")).$([System.DateTime]::UtcNow.ToString("MM"))
42+
.$([System.DateTime]::UtcNow.ToString("dd")).0
43+
</AssemblyVersion>
44+
<FileVersion>
45+
$([System.DateTime]::UtcNow.ToString("yyyy")).$([System.DateTime]::UtcNow.ToString("MM"))
46+
.$([System.DateTime]::UtcNow.ToString("dd")).0
47+
</FileVersion>
48+
</PropertyGroup>
49+
```
50+
51+
* Disable Source Link Source Revision including in Assembly info:
52+
53+
```xml
54+
<PropertyGroup>
55+
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
56+
</PropertyGroup>
57+
```
58+
59+
* Allow Unsafe code:
60+
61+
```xml
62+
<PropertyGroup>
63+
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
64+
</PropertyGroup>
65+
```

030-powershell.md

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Usefull Powershell commands & scripts
2+
3+
* Enable long path support (Windows 10 version 1607 or later)
4+
5+
```powershell
6+
New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem" `
7+
-Name "LongPathsEnabled" -Value 1 -PropertyType DWORD -Force
8+
```
9+
10+
* Delete bin and obj directories produced by build
11+
12+
```powershell
13+
function RemoveBinObj {
14+
$directories = Get-ChildItem -Directory -Recurse | Where-Object { $_.Name -eq "bin" -or $_.Name -eq "obj" }
15+
foreach ($directory in $directories) {
16+
Write-Host "Deleting $($directory.FullName)" -ForegroundColor Yellow
17+
Remove-Item $directory.FullName -Recurse -Force
18+
}
19+
Write-Host "Cleanup complete!" -ForegroundColor Green
20+
}
21+
22+
RemoveBinObj
23+
```

0 commit comments

Comments
 (0)