2018年9月10日 星期一

在 docker 的 ubuntu 安裝 dotnet 不能執行的問題解決方法

在 docker 的 ubuntu
安裝 dotnet 2.1 後
執行
root@1473781a7c69:/# dotnet --version
出現錯誤
FailFast:
Couldn't find a valid ICU package installed on the system. Set the configuration flag System.Globalization.Invariant to true if you want to run with no globalization support.

安裝 ICU
apt-get install ICU
出現錯誤
E: Unable to locate package ICU

改成安裝 libicu-dev
apt-get install libicu-dev
就能正常安裝 ICU 與執行 dotnet

執行 dotnet 程式輸入
root@1473781a7c69:/home/linux-x64# dotnet Server.dll
出現錯誤
No usable version of the libssl was found
Aborted

再安裝 libssl
apt-get install libssl-dev

再把 openssl 1.1 降版本到 1.0 版
apt-get install -y --allow-downgrades openssl1.0
因為 dotnet 2.1 只支援 openssl  1.0
openssl  降版本後 dotnet 2.1 就能正常執行了


記得指令輸入前先執行 apt-get update

docker 的一些基礎操作

docker cp

複製本地檔案到 docker container
docker cp foo.txt container_id:/foo.txt
範例
docker cp foo1.txt 8b44799aacc4:/foo1.txt

複製本地目錄到 docker container
docker cp src/. container_id:/target
範例
docker cp cp_test/. 8b44799aacc4:/cp_test

複製 docker container 檔案到本地
docker cp container_id:/foo.txt foo.txt
範例
docker cp 8b44799aacc4:/foo1.txt foo.txt

複製 docker container 目錄到本地
docker cp container_id:/src/. src
範例
docker cp 8b44799aacc4:/cp_test/. cp_test1

docker save

匯出 docker 的 image 到 tar 檔案
docker save image_id > ubuntu.tar

docker export

匯出 docker container 到 tar 檔案
docker export container_id > ubuntu.tar
範例
docker export 90c79973be12 > ubuntu.tar

docker load

載入存成 tar 的 image 檔案到 docker image
docker load < ubuntu.tar

載入存成 tar 的 container 檔案到 docker image
docker import ubuntu.tar

docker ps

顯示執行中的 docker container
docker ps

顯示所有的 docker container
docker ps -a

docker stop

關閉執行中的 docker container
docker stop container_id
範例
docker stop 8b44799aacc4

docker rm

刪除 docker container(必須是關閉狀態的 container)
docker rm container_id

docker images

顯示所有 image
docker images

docker image rm

刪除 image
docker image rm image_id
範例
docker image rm 47b19964fb50

docker run

docker 用終端機模式執行未存在的 image 成為 container
docker run -it image_id
範例
docker run -it 47b19964fb50
發生錯誤訊息
docker: Error response from daemon: No command specified.
請改用
docker run -t -i 47b19964fb50 /bin/bash

docker exec

docker 用終端機模式執行已存在的 container
docker exec -it container_id
範例
docker exec 47b19964fb50

docker run -it image_id 發生錯誤的解決方法

執行 docker run -it image_id
發生了錯誤訊息
docker: Error response from daemon: No command specified.
改用
docker run -t -i image_id /bin/bash 就正常了

2018年8月27日 星期一

C# 利用變數接函式副本

變數 Action function 可以接 void Function() 的副本
例如: Action function = void Function();

變數 Action function 可以接 void Function(T) 的副本
例如: Action function = void Function(int);

變數 Func function 可以接 T3 Function(T1, T2) 的副本(PS.最後一個T3是回傳值)
例如: Func function = string Function(int, byte);

變數 Func function 可以接 T Function() 的副本
例如:Func function =  int Function();

2018年8月13日 星期一

Visual Studio 2017 / 2019 Lua 語法標示的比較

Visual Studio 2017 NPL_LuaLanguageService

Visual Studio 2019 Syntax Highlighting Pack



















目前使用的 Lua 語法標示
Visual Studio 2019 目前沒的選,只能用 Syntax Highlighting Pack
Visual Studio 2017 目前有3種選擇,我先選了 NPL_LuaLanguageService
大家可以參考一下。

C# 上引用 Script Language 效能比較

使用了 nuget 的
MoonSharp(LUA)
CS-Script.Core(CS)

速度 func 最快
func > lua > cs

下面順序都是 func、lua、cs

執行總時間比(func = 0.0022)
1 : 87.2 : 1369.7
結論:
#不意外,cs 最慢。

初始化時間比(func = 0.0014)
1 : 132.1 : 2134
結論:
#cs 初始化超級慢,拖累執行效率。

執行時間比(func = 0.0008)
1 : 6.8 : 1.9
結論:
#意外的是,lua 竟然比 cs 慢,推測是 lua 反射查詢的機制比較複雜,拖累 lua 執行效率。

2018年8月7日 星期二

Visual Studio 2017 好看的程式碼的字型

工具 -> 選項 -> 環境 -> 字型與色彩






















選擇字型 Consolas 大小選 14
這樣就可以看到清晰與放大的程式碼了!

Visual Studio 2017 / 2019 擴充功能與更新 Viasfora 工具介紹

工具 → 擴充功能與更新































選擇「線上」搜尋「Viasfora」並安裝
























原本「程式碼」如下:

安裝後,「程式碼」如下:






















「程式碼」視窗從此不再是單調了!

Visual Studio 2019 擴充功能與更新 VSColorOutput 工具 && Visual Studio 2017 擴充功能與更新 Output enhancer 工具介紹

工具 -> 擴充功能與更新































選擇「線上」搜尋「VSColorOutput」並安裝

原本「輸出」如下:

安裝後,「輸出」如下:













這下可以讓單調的「輸出」視窗製造一些彩色了!

「輸出」視窗最下面的訊息可以關掉

工具 -> 選項 -> VSColorOutput 改 Yes, I Donated! 為 True






















就能關閉「輸出」視窗的廣告訊息了

目前 VSColorOutput 在 Visual Studio 2017 已經停止更新了

現在正在試用 Output enhancer 中
下面是 Output enhancer 的使用畫面截圖




































2018年7月21日 星期六

依據組態 Debug 或 Release 設定 App.config

 安裝「擴充功能與更新」的 「 Configuration Transform」
























在 「App.config」 按下右鍵,選取「Add Config Transforms」




































會依據組態產生 App.config







App.config 新增一組 appSettings
<appSettings>
      <add key="VER" value=""/>
</appSettings>

App.Debug.config 新增一組 appSettings

<appSettings>
      <add key="VER" value="DEBUG" xdt:Locator="Match(key)" xdt:Transform="Replace" />
</appSettings>

App.Release.config 新增一組 appSettings

<appSettings>
      <add key="VER" value="RELEASE" xdt:Locator="Match(key)" xdt:Transform="Replace" />
</appSettings>

VER 就會依據對應的組態設定 value 的值

PS.後面加了兩個設定:

Locator 限制條件,透過設定 Match(key) 來要求置換目標的 key 值必須相同才會執行轉換
Transform 轉換方法,透過設定 Replace 來將置換目標的 value 值換成來源值

Visual Studio 2017/2019 推薦的擴充功能與更新

參考文章: 覺得 Google 的 Blogger 不太順手?透過 HTML 的 iframe 移花接木 HackMD