0%

Migrate ASP.NET Core Razor Project

In this paragraph, we will update the ASP.NET Core project from 3.1 to 6.

The following table shows that current LTS version status:

LTS Version Release Date EOS
.NET Core 2.1 2018-05-30 2021-08-21
.NET Core 3.1 2019-12-03 2020-12-13
.NET 6 2021-11-08 2024-11-12
.NET 8 2023-11 (projected) 2026-12 (projected)

Modify .csproj

The main topics in this step are:

  1. Change the target framework from .NET Core 3.1 to .NET 6.0.
  2. Update the NuGet packages (Microsoft.AspNetCore.*, Microsoft.EntityFrameworkCore.*, Microsoft.Extensions.*, and System.Net.Http.Json).
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<PropertyGroup>
- <TargetFramework>netcoreapp3.1</TargetFramework>
+ <TargetFramework>net6.0</TargetFramework>
+ <Nullable>enable</Nullable>
+ <ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
- <PackageReference Include="Microsoft.AspNetCore.JsonPatch" Version="3.1.6" />
- <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.6" />
- <PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="3.1.6" />
- <PackageReference Include="System.Net.Http.Json" Version="3.2.1" />
+ <PackageReference Include="Microsoft.AspNetCore.JsonPatch" Version="6.0.0" />
+ <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.0" />
+ <PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="6.0.0" />
+ <PackageReference Include="System.Net.Http.Json" Version="6.0.0" />
</ItemGroup>

Modify Program.cs

In this step, we need to merge Startup.cs into Program.cs, the common rules as following table:

.NET Core 3.1 .NET 6
configuration builder.Configuration
services builder.Services
env app.Environment

A basic example of Program.cs:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
var builder = WebApplication.CreateBuilder(args);

builder.Services.AddRouting(options => options.LowercaseUrls = true);
builder.Services.AddRazorPages()
.AddRazorRuntimeCompilation();

builder.WebHost.ConfigureKestrel(options =>
{
// To listen for incoming http connection on port 5000
options.ListenAnyIP(5000);
// To listen for incoming https connection on port 5001
//options.ListenAnyIP(5001, configure => configure.UseHttps());
});


var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}

app.UseStaticFiles();
app.UseRouting();
app.UseEndpoints(endpoints => endpoints.MapRazorPages());

app.Run();

/* Global Variable if needed */
#pragma warning disable IDE0040
partial class Program
{
public static List<string> GlobalStrings = new List<string>();
}
#pragma warning restore IDE0040

After merged, we can remove the Startup.cs from current project.

Migrate Ubuntu Runtime

Steps

Check the dotnet runtime

1
2
3
4
5
# If is SDK
$ dotnet --list-sdk

# If is runtime
$ dotnet --list-runtimes

(Optional) Remove .NET Core Previous Versions

  • Remove all version

    1
    2
    $ sudo apt -y remove dotnet-host
    $ sudo apt -y autoremove
  • Remove specific SDK version

    1
    $ sudo apt -y remove dotnet-sdk-3.1
  • Remove specific runtime version

    1
    2
    $ sudo apt -y remove dotnet-runtime-3.1
    $ sudo apt -y remove aspnetcore-runtime-3.1

Install .NET 6

  • The .NET SDK allows you to develop apps with .NET. If you install the .NET SDK, you don’t need to install the corresponding runtime.

    1
    2
    $ sudo apt update
    $ sudo apt -y install dotnet6
  • The ASP.NET Core Runtime allows you to run apps that were made with .NET that didn’t provide the runtime.

    1
    2
    $ sudo apt update
    $ sudo apt -y install aspnetcore-runtime-6.0
  • As an alternative to the ASP.NET Core Runtime, you can install the .NET Runtime, which doesn’t include ASP.NET Core support.

    1
    2
    $ sudo apt update
    $ sudo apt -y install dotnet-runtime-6.0

References

Introduction

雖然在 Python 中可以通過 openpyxl 套件來很好的操作 Excel 讀寫,但當想要在檔案中插入 VBA macro 時便沒有辦法依靠 openpyxl。不過我們仍然可以透過 pywin32 套件來操作 Windows API,達到在 Excel 檔案中插入 VBA macro 的需求。

在本篇文章中將會提到:

  1. 透過 pywin32 對 XLSM 檔案插入 VBA macro。
  2. 解決在過程中會出現的「檔案信任」的問題。
  3. 將程式碼包裝為類(class)以方便使用,以及其使用範例。
  4. 如何透過 openpyxl 建立可插入 VBA macro 的 XLSM 檔案。
Read more »

Introduction

日前在偶然地瀏覽自己網站找資源的時候,發現 Cloudflare 顯示 Error 526 Invalid SSL certificate(如下圖所示),當下的第一反應是憑證過期,但在開始查找後發現案情並不單純。

error-526-invalid-ssl-certificate

Read more »

Introducion

目前存在許多密碼管理器,較為知名的包括 1Password、Bitwarden、LastPass 等。原先 LastPass 免費版支援跨平台與裝置使用,然而 LastPass 官方於 2021-20-16 變更免費版政策,自 2021-03-16 後,免費版用戶將只能選擇於單一類型的裝置使用:桌面裝置或行動裝置,此外,免費版將不提供電子郵件支援。

LastPass 此舉目的在於鼓勵免費版用戶升級至 Premium,目前訂閱價格為每月 $3,在限時內從免費版升級至 Premium 官方提供每月 $2.25 的優惠價格。

Read more »

Introduction

由於更換了硬碟,因此重新安裝了英文美國(en-US)的 Windows 10。原本預想一切順利,但在進入硬碟查看部分以中文命名的資料夾時,發現顯示的中文會有不統一、忽大忽小的情況。

然而這樣的情況將不會發生在先安裝繁體中文(zh-TW)的 Windows 10 後再將顯示語系切換為英文美國,加上非繁體中文使用者所預設使用的 Windows 10 鮮少會有繁體中文資料夾的情況,這導致了在網路上相關問題的資源並不多,因此本篇文章將記錄如何解決這樣的問題。

Read more »

youtube-dl is an open-source software project that downloads video and audio primarily from YouTube, but also supports other websites. It uses the Unlicense software license.
As of October 2020 the project was one of the most starred projects on GitHub, with over 72,000 stars. The project also had 84 dependent packages and 1.43k dependent repositories according to libraries.io.

Wikipedia ── youtube-dl

Introduction

在七月份的時候,我們介紹了一款開源與命令行介面的程式碼專案 youtube-dl,但就在 2020 年 10 月 23 日,這項開源程式碼專案被 RIAA 根據 DMCI 請求 GitHub 下架,其中包括 youtube-dl 以及其分支,在請求書中,RIAA 引用了 DMCA-1201,聲稱用戶會使用該儲存庫來下載對社會不公平的影片,並侵犯了版權。

Read more »

Introduction

Flask 是一個使用 Python 編寫的輕量級 Web 應用框架,由於其輕量特性,也被稱為 micro-framework。雖然我們在完成一個 Flask 應用程式後可以通過 python3 api.py 來啟動伺服器,但這只適合用於測試環境中,正式發佈的服務需要一個穩定而持續的伺服器,例如 Apache、Nginx 等。其中 Nginx 是一款面向效能設計的 HTTP 伺服器,相較於 Apache、lighttpd 具有占有記憶體少,穩定性高等優勢,此外,Nginx 的優點還包括:高度模組化的設計,模組編寫簡單,以及設定檔簡潔。

因此在本篇文章,我們將結合先前的 PyTorch 實戰 - 高鐵驗證碼辨識,實作一個辨識驗證碼的 Flask API──通過傳入圖片在辨識完成後回傳驗證碼──,並部署於 CentOS 7 上,

architecture

Read more »

Types of Keyboard

鍵盤依結構主要可分為五種,而市面上主要以薄膜鍵盤(Membrane Keyboard)、機械鍵盤(Mechanical Keyboard)最為常見,其它還包括靜電容式鍵盤、光學鍵盤、霍爾效應鍵盤等。

Read more »

Introduction

An uninterruptible power supply or uninterruptible power source (UPS) is an electrical apparatus that provides emergency power to a load when the input power source or mains power fails. A UPS differs from an auxiliary or emergency power system or standby generator in that it will provide near-instantaneous protection from input power interruptions, by supplying energy stored in batteries, supercapacitors, or flywheels. The on-battery run-time of most uninterruptible power sources is relatively short (only a few minutes) but sufficient to start a standby power source or properly shut down the protected equipment. It is a type of continual power system.

Wikipedia ── Uninterruptible power supply

meme-no-ups

Reason for Purchase

原本在 2017 年時購入了 UPS CP1000AVRLCD,結果這兩天搬家,插頭重新插上後 Overloads 警告作響,參考了官方與其他文章的解決辦法依然無解,只好正式宣告他壽終正寢。但已經習慣有 UPS 的我,沒了這個總是心慌慌,尤其在最近又買了新螢幕(AOC CU32V3)、新鍵盤(Leopold FC900R PD Sky)、新滑鼠(Logitech G304)、新音響(Edifier),總覺得該善待一下他們,於是又再買了台 UPS。

Read more »