Last active
August 28, 2024 09:30
-
-
Save hochun836/0322ec7e69c2afe6ec46fe008c03032c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # base | |
| .csproj means a project | |
| .sln means a solution | |
| one solution can contain multi projects | |
| Properties/launchSettings.json can contain multi profiles | |
| # common | |
| dotnet -h | |
| dotnet --info // detail information | |
| dotnet --version | |
| dotnet --list-runtimes | |
| dotnet --list-sdks | |
| dotnet new // show info. | |
| dotnet new -h | |
| dotnet new -l // -l <=> --list | |
| dotnet new -l --columns-all | |
| dotnet new <template> | |
| dotnet new <template> -n <name> // the name for the output being created. if no name is specified, the name of the current directory is used | |
| dotnet new <template> -o <path> // location to place the generated output | |
| dotnet new --update-check // check the currently installed template packs for updates | |
| dotnet new --update-apply // check the currently installed template packs for update, and install the updates | |
| dotnet new globaljson --help | |
| dotnet new globaljson // create global.json | |
| dotnet new globaljson --sdk-version <sdk-version> | |
| dotnet new -i <path_to_local_template_folder> // -i <=> --install, the path of the '.template.config' folder | |
| dotnet new -i <path_to_local_nuget_file> // to install a template package from a local nupkg file | |
| dotnet new -i <nuget_package_id> // to install a template package from a nupkg package stored at nuget.org | |
| dotnet new -u // -u <=> --uninstall, list all installed template packages and included templates | |
| dotnet new -u <by-prompt> | |
| dotnet build -h | |
| dotnet build // in the current path, must exist a .csproj file | |
| dotnet build <path.csproj> | |
| dotnet build -v <level> // level: q[uiet], m[inimal], n[ormal], d[etailed], diag[nostic] (-v <=> --verbosity) | |
| dotnet build -c <configuration> // configuration: Debug (default), Relase | |
| dotnet publish -h | |
| dotnet publish | |
| dotnet publish -c <configuration> | |
| dotnet publish -c Release /p:DebugType=None // don't generate the pdb file (.pdb) | |
| dotnet run -h | |
| dotnet run // in the current path, must exist a .csproj file | |
| dotnet run --project <path.csproj> | |
| dotnet run -p <property> // -p <=> --property, pass to msbuild | |
| dotnet run -v <level> // level: q[uiet], m[inimal], n[ormal], d[etailed], diag[nostic] (-v <=> --verbosity) | |
| dotnet run -c <configuration> // configuration: Debug (default), Relase | |
| dotnet run --launch-profile <profile-name> // profile name is a section name in Properties/launchSettings.json | |
| dotnet run --no-launch-profile // not load Properties/launchSettings.json | |
| dotnet run -- <key>=<value> [<key>=<value> ...] // pass to configuration | |
| dotnet run --no-restore // no restore: don't create the obj folder (alternatively, dotnet restore manually) | |
| dotnet run --no-build // no build: don't create the bin folder (alternatively, dotnet build manually) | |
| dotnet run --no-restore --no-build | |
| dotnet run --no-restore --no-build -v m --urls=http://localhost:5100;https://localhost:5101 | |
| dotnet watch --version // Microsoft DotNet File Watcher | |
| dotnet watch --list // list all discovered files without starting the watcher | |
| dotnet watch run | |
| dotnet watch test | |
| dotnet clean -h | |
| dotnet clean // only clean files, not include directories | |
| dotnet clean -c Release | |
| dotnet add -h | |
| dotnet add package <package-name> | |
| dotnet add package <package-name> -v <version> | |
| dotnet add reference <reference-path> | |
| dotnet remove -h | |
| dotnet remove package <package-name> | |
| dotnet remove reference <reference-path> | |
| dotnet list -h | |
| dotnet list package -h | |
| dotnet list package | |
| dotnet list reference -h | |
| dotnet list reference | |
| dotnet sln -h | |
| dotnet sln add <path.csproj> // in the current path, must exist a .sln file | |
| dotnet sln list // list projects in this sln | |
| dotnet sln remove <path.csproj> | |
| dotnet msbuild -h | |
| dotnet msbuild -version | |
| dotnet dev-certs -h | |
| dotnet dev-certs https -h | |
| dotnet dev-certs https // generate the certificate if it isn't present | |
| dotnet dev-certs https -t // -t <=> --trust, generate the certificate and trust it (all browsers need to be closed and reopened to ensure that browser.exe reloads the certificate settings) | |
| dotnet dev-certs https -c // -c <=> --check, check the certificate is valid | |
| dotnet dev-certs https -c -t // check the certificate is valid and is trusted | |
| dotnet dev-certs https -v -ep <path> // -v <=> --verbose, -ep <=> --export-path | |
| dotnet dev-certs https --clean // clean all https development certificates | |
| dotnet nuget list source | |
| dotnet nuget list client-cert | |
| dotnet nuget locals <all | http-cache | global-packages | temp | plugins-cache> [--clear | -c | --list | -l] | |
| dotnet nuget locals all -l | |
| dotnet tool -h | |
| dotnet tool install <tool> // tool install 'in local' depend on => dotnet new tool-manifest // this will create .config/dotnet-tools.json | |
| dotnet tool install <tool> --version <version> | |
| dotnet tool install -g <tool> // -g <=> --global | |
| dotnet tool uninstall [-g] <tool> | |
| dotnet tool update [-g] <tool> | |
| dotnet tool list -h | |
| dotnet tool list [-g] | |
| dotnet tool restore -h | |
| dotnet tool restore // restore all of the tools listed in the manifest file | |
| dotnet ignore -h // depend on => dotnet tool install -g dotnet-ignore | |
| dotnet ignore list -h | |
| dotnet ignore list | |
| dotnet ignore list -s // -s <=> --short, list name without .gitignore | |
| dotnet ignore get -h | |
| dotnet ignore get -n <name> // -n <=> --name, accept short and full version of the name | |
| dotnet ignore get -n VisualStudio | |
| dotnet ef -h // depend on => dotnet tool install -g dotnet-ef | |
| dotnet ef dbcontext -h | |
| dotnet ef dbcontext list | |
| dotnet ef dbcontext info -c <dbcontext> | |
| dotnet ef dbcontext scaffold -h | |
| dotnet ef dbcontext scaffold <connection> <provider> | |
| dotnet ef dbcontext scaffold "Server=xxx;Database=xxx;User ID=xxx;Password=xxx;Trusted_Connection=True;Integrated Security=False;" Microsoft.EntityFrameworkCore.SqlServer | |
| dotnet ef dbcontext scaffold <connection> <provider> -o Models -c MyContext --context-dir Contexts -t TB_USER -t TB_ROLE -d -f // d: data annotations, f: force | |
| - check: dotnet list package | |
| - install: dotnet add package Microsoft.EntityFrameworkCore.SqlServer | |
| dotnet ef migrations -h | |
| dotnet ef migrations list -c <dbcontext> | |
| dotnet ef migrations add <name> -c <dbcontext> | |
| dotnet ef migrations remove -c <dbcontext> | |
| dotnet ef database -h | |
| dotnet ef database update -c <dbcontext> | |
| dotnet ef database drop -c <dbcontext> | |
| dotnet-aspnet-codegenerator -h // depend on => dotnet tool install -g dotnet-aspnet-codegenerator | |
| dotnet-project-licenses --help // depend on => dotnet tool install -g dotnet-project-licenses | |
| dotnet-project-licenses -i <.sln> // -i <=> --input | |
| dotnet-project-licenses -i <.csproj> | |
| dotnet-project-licenses -i <.csproj> -p false // -p <=> --print, is to print licenses (default: true) | |
| dotnet-project-licenses -i <.csproj> -o // -o <=> --output, enable to save as a text file (licenses.txt) | |
| dotnet-project-licenses -i <.csproj> -o --outfile <file.txt> | |
| dotnet-project-licenses -i <.csproj> -o --include-project-file | |
| dotnet-project-licenses -i <.csproj> -j // -j <=> --json, enable to save as a markdown file (licenses.json) | |
| dotnet-project-licenses -i <.csproj> -j --outfile <file.json> | |
| dotnet-project-licenses -i <.csproj> -j --include-project-file | |
| dotnet-project-licenses -i <.csproj> -m // -m <=> --md, enable to save as a markdown file (licenses.md) | |
| dotnet-project-licenses -i <.csproj> -m --outfile <file.md> | |
| dotnet-project-licenses -i <.csproj> -m --include-project-file | |
| dotnet <path.dll> // execute some dll | |
| # [note] create an example (for angular) | |
| dotnet new sln -o my-sln | |
| cd my-sln | |
| dotnet new angualr -o my-angular | |
| dotnet sln add my-angular/my-angular.csproj | |
| dotnet sln list | |
| cd my-angular | |
| dotnet run // it takes 3~5 mins for download node_modules in ClientApp | |
| # [note] create an example (for console) | |
| mkdir my-console | |
| cd my-console | |
| dotnet new globaljson | |
| dotnet new sln | |
| dotnet new console | |
| dotnet sln add my-console.csproj | |
| dotnet sln list | |
| dotnet run | |
| // add package | |
| dotnet nuget list source | |
| dotnet add [my-console.csproj] package Microsoft.Extensions.DependencyInjection -v 3.1.24 // -v <=> --version | |
| dotnet list package | |
| observe: | |
| 1. my-console.csproj file | |
| 2. C:\Users\<user>\.nuget | |
| // remove package | |
| dotnet remove [my-console.csproj] package Microsoft.Extensions.DependencyInjection | |
| dotnet list package | |
| observe: | |
| 1. my-console.csproj file | |
| 2. C:\Users\<user>\.nuget | |
| # [note] create a custom template | |
| a template is composed of the following parts: | |
| 1. source files and folders | |
| 2. a configuration file (.template.config\template.json) | |
| => ref: https://docs.microsoft.com/en-us/dotnet/core/tools/custom-templates | |
| => ref: https://blog.miniasp.com/post/2020/01/19/dotnet-new-template-how-to | |
| NOTE: packing a template into a nuget package (nupkg file) | |
| => ref: https://docs.microsoft.com/en-us/dotnet/core/tools/custom-templates#packing-a-template-into-a-nuget-package-nupkg-file | |
| # [note] bin vs. obj folder | |
| the compilation process goes through two steps: compiling and linking | |
| - compiling: every code file is compiled into individual compiled units (placed in obj folder) | |
| - linking: all these compiled code files are linked and compiled into a single unit assembly which can be a DLL or EXE (placed in bin folder) | |
| => ref: https://www.codeproject.com/Articles/1247885/Csharp-bin-vs-obj-Folder | |
| # [note] which server is running when dotnet run | |
| server: kestrel | |
| => ref: https://iter01.com/429364.html | |
| # [note] change dotnet version | |
| dotnet new globaljson | |
| edit global.json | |
| => ref: https://blog.miniasp.com/post/2018/04/19/How-to-switch-between-DotNet-SDK-versions | |
| # [note] spa independently | |
| spa.UseProxyToSpaDevelopmentServer("http://localhost:4200"); | |
| => ref: https://docs.microsoft.com/zh-tw/aspnet/core/client-side/spa/angular?view=aspnetcore-5.0&tabs=netcore-cli#run-ng-serve-independently | |
| # [note] detect source code change | |
| dotnet watch run | |
| dotnet watch test | |
| => ref: https://stackoverflow.com/questions/40468641/how-to-run-asp-net-core-app-automatically-after-changes-in-c-sharp-files | |
| => ref: https://docs.microsoft.com/zh-tw/aspnet/core/tutorials/dotnet-watch?view=aspnetcore-5.0 | |
| # [note] debug by attaching the process when dotnet run | |
| 'dotnet run' will create two processes | |
| dotnet.exe | |
| <project-name>.exe // attach this process | |
| => ref: https://github.com/aspnet/Hosting/issues/747#issuecomment-330456390 | |
| => ref: https://stackoverflow.com/questions/66165766/how-to-get-the-current-process-id-of-a-dotnet-core-application-while-it-is-runni | |
| # [note] don't generate the pdb file | |
| - by command | |
| dotnet build /p:DebugType=None | |
| dotnet publish /p:DebugType=None | |
| - by .csproj | |
| <PropertyGroup> | |
| <DebugType>None</DebugType> | |
| </PropertyGroup> | |
| => ref: https://github.com/dotnet/sdk/issues/5575#issuecomment-271062056 | |
| => ref: https://blog.csdn.net/xhl_james/article/details/117264458 | |
| # [note] dotnet build vs. dotnet publish | |
| build default path: bin/Debug/netcoreapp3.1/ | |
| publish default path: bin/Debug/netcoreapp3.1/publish/ | |
| 'web.config' is only outputed by 'dotnet publish' | |
| # [note] web.config keypoints | |
| - modules="AspNetCoreModuleV2" | |
| - hostingModel="inprocess" | |
| <configuration> | |
| <location path="." inheritInChildApplications="false"> | |
| <system.webServer> | |
| <handlers> | |
| <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" /> | |
| </handlers> | |
| <aspNetCore processPath="dotnet" arguments=".\xxx.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" /> | |
| </system.webServer> | |
| </location> | |
| </configuration> | |
| # [note] deploy asp.net core on iis | |
| install module 'AspNetCoreModuleV2' | |
| dotnet publish [-c Release] | |
| => ref: https://dotnet.microsoft.com/download/dotnet/3.1 | |
| => ref: https://www.bilibili.com/video/BV1Ng411G7Z5?p=5 | |
| # [note] AspNetCoreModuleV2 - Hosting models | |
| - inprocess | |
| taskmgr -> w3wp.exe | |
| response header -> Server: Microsoft-IIS/10.0 | |
| host address -> http://*:5999 (here, address follows iis setting) | |
| - OutOfProcess | |
| taskmgr -> w3wp.exe, dotnet.exe, conhost.exe | |
| response header -> Server: Kestrel | |
| host address -> http://127.0.0.1:43356 (here, port is random) | |
| => ref: https://docs.microsoft.com/zh-tw/aspnet/core/host-and-deploy/aspnet-core-module?view=aspnetcore-3.1 | |
| => ref: https://docs.microsoft.com/zh-tw/aspnet/core/host-and-deploy/iis/?view=aspnetcore-3.1 | |
| # [note] which dotnet (core) version is iis using ? | |
| window (right click) | Run | regedit | |
| HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Updates\.NET | |
| -> Microsoft .NET 5.0.8 - Windows Server Hosting (x86) | |
| HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Updates\.NET Core | |
| -> Microsoft .NET Core 3.1.18 - Windows Server Hosting (x86) | |
| => ref: https://blog.poychang.net/how-to-check-dotnet-core-iis-hosting-bundle-version/ | |
| # [note] which need to be installed ? | |
| in development | |
| dotnet (core) | |
| Build apps - SDK | |
| crystal report | |
| SAP Crystal Reports runtime engine for .NET Framework (64-bit) | |
| SAP Crystal Reports, version for Microsoft Visual Studio | |
| in production | |
| dotnet (core) | |
| Run apps - Runtime (On Windows, we recommend installing the Hosting Bundle, which includes the .NET Runtime and IIS support) | |
| crystal report | |
| SAP Crystal Reports runtime engine for .NET Framework (64-bit) | |
| => ref: https://dotnet.microsoft.com/download/dotnet/3.1 | |
| => ref: https://www.tektutorialshub.com/crystal-reports/how-to-download-and-install-crystal-report-runtime/ | |
| # [note] get kestrel host address | |
| var server = appBuilder.ApplicationServices.GetRequiredService<IServer>(); | |
| var addressFeature = server.Features.Get<IServerAddressesFeature>(); | |
| foreach(var address in addressFeature.Addresses) | |
| { | |
| _log.LogInformation("Listing on address: " + address); | |
| } | |
| => ref: https://andrewlock.net/how-to-automatically-choose-a-free-port-in-asp-net-core/ | |
| # [note] observe: dotnet run -v normal | |
| NuGet.Config | |
| Properties/launchSettings.json // the profile which is the project name is used by default when launching the app with 'dotnet run' | |
| => ref: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/environments?view=aspnetcore-5.0 | |
| # [note] ef core (entity framework core) | |
| => ref: https://docs.microsoft.com/zh-tw/ef/core/get-started/overview/first-app?tabs=netcore-cli | |
| => ref: https://docs.microsoft.com/zh-tw/ef/core/providers/?tabs=dotnet-core-cli | |
| => ref: https://docs.microsoft.com/zh-tw/ef/core/managing-schemas/scaffolding?tabs=dotnet-core-cli | |
| => ref: https://blog.darkthread.net/blog/efcore-notes-1/ | |
| # [note] what is scaffold | |
| => ref: https://dotblogs.com.tw/stanley14/2016/07/02/193832 | |
| => ref: https://kevintsengtw.blogspot.com/2015/04/aspnet-mvc-scaffold-crud.html | |
| => ref: https://mileslin.github.io/2019/04/%E5%9C%A8-ASP-NET-Core-MVC-%E4%BD%BF%E7%94%A8-EF-Core/ | |
| # [note] what is t4 (text template transformation toolkit) | |
| => ref: https://www.dotnettricks.com/learn/entityframework/using-t4-templates-in-entity-framework | |
| => ref: https://www.bricelam.net/2020/02/03/t4-and-efcore.html | |
| # [note] what is dotnet-aspnet-codegenerator | |
| => ref: https://blog.miniasp.com/post/2020/09/09/Create-Controller-and-Views-with-dotnet-aspnet-codegenerator | |
| # [note] learn | |
| => ref: https://ithelp.ithome.com.tw/users/20107875/ironman/2001 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment