2024-06-03 07:04:29 -07:00

161 lines
6.3 KiB
Markdown

---
type: "topic"
created: "2024-02-25T00:52:01.425Z"
updated: "2024-04-03T03:34:53.544Z"
---
# dotnet
```c#
public int Index { get; set; }
public int I⁀ndex { get; set; }
```
```bash
# https://learn.microsoft.com/en-us/dotnet/core/extensions/windows-service?pivots=dotnet-7-0#create-the-windows-service
sc.exe create "File-Watcher" binpath="C:\Windows\System32\config\systemprofile\AppData\Local\IFXApps\File-Watcher\File-Watcher.exe"
sc.exe create "Directory-Size" binpath="C:\Windows\System32\config\systemprofile\AppData\Local\IFXApps\Directory-Size\Directory-Size.exe"
sc.exe create "Parsing-Packets" binpath="C:\Windows\System32\config\systemprofile\AppData\Local\IFXApps\Parsing-Packets\Parsing-Packets.exe"
```
```conf Tue Jan 02 2024 10:01:33 GMT-0700 (Mountain Standard Time)
dotnet_diagnostic.CA1816.severity = none # CA1816: Call GC.SuppressFinalize correctly
dotnet_diagnostic.CA1854.severity = warning # CA1854: Prefer a 'TryGetValue' call over a Dictionary indexer access guarded by a 'ContainsKey' check to avoid double lookup
dotnet_diagnostic.CA1866.severity = none # CA1866: Use 'string.EndsWith(char)' instead of 'string.EndsWith(string)' when you have a string with a single char
dotnet_diagnostic.IDE0200.severity = warning # IDE0200: Lambda expression can be removed [Map]
```
```bash Fri Jan 05 2024 19:24:13 GMT-0700 (Mountain Standard Time)
dotnet add package Microsoft.Extensions.Hosting.Systemd --version 8.0.0
```
```c#
// https://blog.maartenballiauw.be/post/2021/05/25/running-a-net-application-as-a-service-on-linux-with-systemd.html
// https://stackoverflow.com/questions/71233335/use-systemd-on-asp-net-core-6-0-and-7-0
Host.CreateDefaultBuilder(args)
.UseSystemd() // add this
.ConfigureServices((hostContext, services) =>
{
services.AddHostedService<Worker>();
});
```
```bash
nano /etc/systemd/system/text-2-json.service
systemctl daemon-reload
systemctl status text-2-json.service
systemctl enable text-2-json.service
systemctl stop text-2-json.service
systemctl start text-2-json.service
systemctl restart text-2-json.service
systemctl status text-2-json.service
journalctl -u text-2-json.service
```
```conf
[Unit]
Description=Text 2 json
[Service]
Type=notify
ExecStart=/usr/sbin/text-2-json --port=53
[Install]
WantedBy=multi-user.target
```
```conf Mon Jan 08 2024 10:23:04 GMT-0700 (Mountain Standard Time)
dotnet_diagnostic.IDE0074.severity = warning # IDE0074: Use compound assignment
dotnet_diagnostic.IDE0058.severity = warning # IDE0058: Expression value is never used
dotnet_diagnostic.CA1511.severity = warning # CA1511: Use 'ArgumentException.ThrowIfNullOrEmpty' instead of explicitly throwing a new exception instance
dotnet_diagnostic.CA1862.severity = warning # CA1862: Prefer using 'string.Equals(string, StringComparison)' to perform a case-insensitive comparison, but keep in mind that this might cause subtle changes in behavior, so make sure to conduct thorough testing after applying the suggestion, or if culturally sensitive comparison is not required, consider using 'StringComparison.OrdinalIgnoreCase'
```
```conf Sun Feb 04 2024 14:03:10 GMT-0700 (Mountain Standard Time)
dotnet_diagnostic.CA1513.severity = none # Use 'ObjectDisposedException.ThrowIf' instead of explicitly throwing a new exception instance
```
```bash
dotnet dev-certs https --trust
set DOTNET_CLI_TELEMETRY_OPTOUT=1
setx DOTNET_CLI_TELEMETRY_OPTOUT 1
```
```bash
dotnet user-secrets list
cat ./input.json | dotnet user-secrets set
```
```C#
// https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/csharp-formatting-options
// csharp_new_line_before_open_brace = all
void MyMethod()
{
if (...)
{
...
}
}
// csharp_new_line_before_open_brace = none
void MyMethod() {
if (...) {
...
}
}
```
```json
// https://github.com/editorconfig-checker/editorconfig-checker
{
"scripts": {
"prettier.check": "prettier . --check",
"prettier.write": "prettier . --write",
"lint:editorconfig": "editorconfig-checker"
},
"devDependencies": {
"editorconfig-checker": "^5.1.5",
"prettier": "3.0.0"
}
}
```
```conf Wed Mar 20 2024 17:29:08 GMT-0700 (Mountain Standard Time)
# https://johnnyreilly.com/eslint-your-csharp-in-vs-code-with-roslyn-analyzers
# <EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
dotnet_analyzer_diagnostic.category-Design.severity = error
dotnet_analyzer_diagnostic.category-Documentation.severity = error
dotnet_analyzer_diagnostic.category-Globalization.severity = none
dotnet_analyzer_diagnostic.category-Interoperability.severity = error
dotnet_analyzer_diagnostic.category-Maintainability.severity = error
dotnet_analyzer_diagnostic.category-Naming.severity = none
dotnet_analyzer_diagnostic.category-Performance.severity = none
dotnet_analyzer_diagnostic.category-Reliability.severity = error
dotnet_analyzer_diagnostic.category-Security.severity = error
dotnet_analyzer_diagnostic.category-SingleFile.severity = error
dotnet_analyzer_diagnostic.category-Style.severity = error
dotnet_analyzer_diagnostic.category-Usage.severity = error
dotnet_diagnostic.CA2201.severity = none # CA2201: Exception type System.NullReferenceException is reserved by the runtime
dotnet_diagnostic.IDE0010.severity = none # Add missing cases to switch statement (IDE0010)
dotnet_diagnostic.IDE0048.severity = none # Parentheses preferences (IDE0047 and IDE0048)
dotnet_diagnostic.IDE0130.severity = none # Namespace does not match folder structure (IDE0130)
```
```conf Tue Apr 02 2024 20:34:52 GMT-0700 (Mountain Standard Time)
dotnet_diagnostic.IDE0051.severity = error # Private member '' is unused [, ]
```
```conf Sun Apr 28 2024 09:27:55 GMT-0700 (Mountain Standard Time)
dotnet_diagnostic.CA1001.severity = error # CA1001: Types that own disposable fields should be disposable
dotnet_diagnostic.CA1051.severity = error # CA1051: Do not declare visible instance fields
```
```conf Tue May 07 2024 09:27:28 GMT-0700 (Mountain Standard Time)
dotnet_diagnostic.CA1861.severity = none # CA1861: Prefer 'static readonly' fields over constant array arguments
```
```conf Sat May 11 2024 15:40:59 GMT-0700 (Mountain Standard Time)
dotnet_diagnostic.JSON002.severity = warning # JSON002: Probable JSON string detected
dotnet_diagnostic.IDE0230.severity = warning # IDE0230: Use UTF-8 string literal
```