/dotnet_2025

Experiments with .NET 2025

Primary LanguageC#

dotnet_2025

Set Up and Use

Docker Compose:

docker compose up

Warning: the default configuration is configured for local non-containerized use.

  1. Tweak the SSL settings in appsettings.json if required. (https -> http)
    • Adding RUN dotnet dev-certs https here will automatically generate and associate a Dev SSL cert usable from within the Container.
  2. Comment out Line 14 in - .NET Console input within a Docker Container will error out.
    • It can be run by Exec'ing into the Docker Container thereafter (and uncommenting out that line).

Visual Studio Code:

  1. Install the C# Dev Kit
  2. Install .NET 9.0 SDK

https://code.visualstudio.com/docs/csharp/get-started

Topics

.NET CLI

dotnet new mvc --language "C#"
dotnet run

C#

  1. Autogenerate most boiler-plate using dotnet new console --language "C#".
  2. C# 13+ examples.

ASP.NET

Refresh for ASP.NET 9.0.3

Much easier now to launch a basic app!

  1. Autogenerate most boiler-plate using dotnet new mvc --language "C#".
  2. Port binding can be set in appsettings.json Urls.
    • "Urls": "https://0.0.0.0:5177"
    • Should bind to localhost.
    • Can view at: https://localhost:5177
    • SSL can be set there too using: dotnet dev-certs https within the same Docker Image.
  3. Controllers automatically append their Handler names as subpaths (quite handy).
  4. Controllers using IActionResult and the relevant helper method (Ok(), NotFound(), etc.) will automatically serialize data into JSON.
  5. https://medium.com/@nwonahr/working-with-json-data-in-asp-net-core-web-api-fbc4f0ee39c4

Views and Endpoints:

Entity Framework

  1. Changes to Connection String require TrustServerCertificate=True or Encrypt=False for basic Docker dev testing.

MSSQL

Exercise in PowerShell and MSSQL admin.

  1. To execute commands within the Container appears to require using Windows PowerShell: docker exec -u root -it <MY_CONTAINER_ID> "bash"
    • If you Exec in through Docker Desktop the default user is set to mssql not root and you won't have permission to execute: /opt/mssql-tools18/bin/sqlcmd
    • If you attempt to Exec in through Bash (in a new Terminal aside from Docker Desktop), the following error will appear: the input device is not a TTY. If you are using mintty, try prefixing the command with 'winpty' from using Bash on a Windows machine (apparently).
    • Run the following command from a new Windows PowerShell Terminal instead: /opt/mssql-tools18/bin/sqlcmd -U sa -P FD83wr9DF_*9pke89 -S localhost -No as described here. (The -No flag bypasses local HTTPS auth.)
  2. docker-entrypoint-initdb.d isn't supported within the Docker Container but I've kept the convention for familiarity's sake.
    • Execute: /opt/mssql-tools18/bin/sqlcmd -U sa -P FD83wr9DF_*9pke89 -S localhost -No -i docker-entrypoint-initdb.d/init_sql.sql to run the initial scripts.
    • Since initialization doesn't happen immediately, I've added sleep 120 to the Bash script.

https://learn.microsoft.com/en-us/sql/sql-server/?view=sql-server-ver16

Resources and Links

  1. https://code.visualstudio.com/docs/csharp/get-started
  2. https://hub.docker.com/r/microsoft/dotnet
  3. https://hub.docker.com/r/microsoft/mssql-server
  4. https://medium.com/@dilanlakshitha194/understanding-iactionresult-in-net-core-simplifying-http-response-handling-1e406e22dbcc
  5. https://learn.microsoft.com/en-us/aspnet/core/web-api/advanced/formatting?view=aspnetcore-9.0
  6. https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-new
  7. https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/statements-expressions-operators/equality-comparisons
  8. https://learn.microsoft.com/en-us/dotnet/standard/exceptions/exception-class-and-properties
  9. https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/events/
  10. https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/properties
  11. https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/delegates/
  12. https://dev.to/waelhabbal/the-right-way-to-check-for-null-in-c-6gf
  13. https://github.com/ggagnaux/CSharp-Publisher-Subscriber-Demo/blob/master/PublisherSubscriberDemo/Publisher.cs
  14. https://learn.microsoft.com/en-us/sql/sql-server/?view=sql-server-ver16
  15. https://learn.microsoft.com/en-us/ef/core/
  16. https://github.com/grpm98/pisofinderapi/blob/f114d5860c60267a05ccfd8ed41c162ce8e51224/Data/PisoFinderContext.cs
  17. https://github.com/adamajammary/simple-web-app-mvc-dotnet/blob/master/SimpleWebAppMVC/Controllers/TasksApiController.cs
  18. https://learn.microsoft.com/en-us/ef/core/what-is-new/ef-core-7.0/breaking-changes?tabs=v7

Some prior examples of mine:

  1. https://www.thoughtscript.io/blog/000000000005
  2. Azure-Samples/Azure-Time-Series-Insights#12
  3. Azure-Samples/digital-twins-samples-csharp#67
  4. https://github.com/Thoughtscript/more_sql_notes/blob/main/3%20-%20mssql/queries.sql
  5. https://github.com/Thoughtscript/jupyter_notebook