2025年6月12日 星期四

取得測試專案路徑

場景:

被測試專案組件有以下敘述:

Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) ?? throw new NullReferenceException(), fileName)

專案本身啟動能正常執行,但因為測試專案無法取得被測試專案的Assembly.GetEntryAssembly().Location(組件路徑,通常是被測試專案的bin目錄)而拋出NullReferenceException。


解法:

改寫為以下敘述取得測試專案路徑即可正常測試。

Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), fileName)

測試專案顯示組件相依性問題

被測試專案組件如下

Serilog, Version=4.3.0.0

Serilog.Sinks.Async, Version=2.1.0.0

專案本身啟動能正常執行,

因為被測試專案csproj檔本身已有AutoGenerateBindingRedirects屬性,且內容為true;

但在引用該專案進行單元測試時,會拋出例外,FusionLog內容如下:


=== 繫結前狀態資訊 ===

...

正在呼叫組件 : Serilog.Sinks.Async, Version=2.1.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10。

===

...

記錄: 原則後參考: Serilog, Version=4.1.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10

...

警告: 比較組件名稱發現不符項目: 次要版本

錯誤: 無法完成組件的安裝 (hr = 0x80131040)。已終止探查。


此時要在測試專案csproj檔的第一個組態屬性群組新增GenerateBindingRedirectsOutputType屬性,且內容為true:


<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
    <PropertyGroup>
        ... <!--↓↓↓在此插入↓↓↓-->         <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType> </PropertyGroup>

並重載測試專案即可正常測試。

2025年4月25日 星期五

Windows 11修改Notepad++檔案圖示

 想用Notepad++開啟文字檔,卻想保留Windows文字檔案的圖示

1.執行regedit.exe

2.路徑指向HKEY_CLASSES_ROOT\Notepad++_file\DefaultIcon

3.修改(預設值)數值資料為:%SystemRoot%\System32\Shell32.dll,70

4.在文字檔按右鍵,開啟檔案(H)>選擇其他應用程式(C)>Notepad++>一律

5.修改完成


參考來源:How can I change the icon for Notepad++

2025年4月16日 星期三

VSCode在Linux同步異常

出現錯誤訊息Failed to execute default Web Browser.















解法:
1. 在Settings→Workbench: External Browser輸入已安裝的瀏覽器如firefox。















2. 會跳出Firefox並執行同步登入作業,如果出現以下錯誤
Error while turning on Settings Sync. Cancelled
則改執行後來跳出的對話框
Would you like to try a different way?(local server)。


















3. 設定同步作業成功。








 

RDP視窗自動縮放

1.連線時在視窗邊緣按右鍵->選擇"智慧縮放(A)"











2.在連線設定檔(.rdp)新增或修改屬性 smart sizing:i:1










參考來源:Smart Resizing of Remote Desktop Windows

2025年4月7日 星期一

Linux安裝X11VNC並設為服務

sudo apt update
#更新APT套件清單

sudo apt install -y x11vnc
#安裝X11VNC

sudo vncpasswd
#建立VNC密碼檔(最多8個字元,可包含數字/特殊符號)

sudo nano /etc/systemd/system/graphical.target
#新增graphical.target 是一個 systemd 目標單元,負責啟動系統的圖形介面,並確保相關的服務(如顯示管理器和 VNC 服務)在適當的順序下啟動

graphical.target內容如下:

[Unit]
Description=Graphical Interface
Documentation=man:systemd.special(7)
Requires=multi-user.target
After=multi-user.target
Conflicts=rescue.target
Wants=display-manager.service
Wants=x11vnc.service
AllowIsolate=yes

[Install]
Alias=default.target


sudo nano /etc/systemd/system/x11vnc.service
#新增X11VNC服務

x11vnc.service內容如下:

[Unit]
Description=X11VNC service
Requires=display-manager.service
After=display-manager.service

[Service]
Type=forking
ExecStart=/usr/bin/x11vnc \
-display :0 \
-rfbport 5900 \
#-localhost \
-rfbauth [VNC密碼檔路徑] \
#-shared \
-bg \
-xkb \
-ncache \
-ncache_cr \
-forever \
-repeat \
-auth guess

[Install]
WantedBy=display-manager.service


sudo systemctl daemon-reload
#重新讀取已新增的服務設定檔

sudo systemctl start graphical.target
#啟動graphical.target服務

sudo systemctl status graphical.target
#查看graphical.target服務狀態

sudo systemctl start x11vnc.service
#啟動X11VNC服務

sudo systemctl status x11vnc.service
#查看X11VNC服務狀態

sudo systemctl enable graphical.target
#將graphical.target服務設為開機啟動

sudo systemctl enable x11vnc.service
#將X11VNC服務設為開機啟動


(在樹莓派5實測還是xrdp效能較佳)


參考來源:launch x11vnc on bootup

2025年4月3日 星期四

Windows無法用ssh-copy-id複製公鑰的替代方法

在命令提示字元視窗執行

type %USERPROFILE%\.ssh\[SSH公鑰檔名] | ssh [Linux使用者]@[Linux主機] "cat >> .ssh/authorized_keys"


參考來源:Alternative to ssh-copy-id on windows