# .NET Core 筆記 ## 使用 vscode - dotnet 指令 - 產生sln檔案 ```dos mkdir project cd project dotnet new sln ``` - 建立類別函式庫專案 ```dos dotnet new classlib -o [classlib name] dotnet new classlib -o Utils ``` - 建立app專案 ```dos dotnet new console -o [app name] dotnet new console -o testApp ``` - 新增專案到sln檔中 ```dos dotnet sln add Utils/Utils.csproj dotnet sln add testApp/testApp.csproj ``` - 新增專案參考 ```dos dotnet add testApp/testApp.csproj reference Utils/Utils.csproj ``` - nuget 相關 - 建立 nuget.config ``` dotnet new nugetconfig ``` - 查詢目前本機端的 source ``` dotnet nuget locals all --list ``` - 調整預設的global source 到指定位置. .net6之後, package不會預設出現在專案下, 預設會出現在下列位置 ``` global-packages: C:\Users\ivan\.nuget\packages\ ``` 其目的是為了避免多專案都使用到相同的package而造成空間的浪費. 可透過調整nuget.config改存放到指定位置. ```xml <config> <add key="globalPackagesFolder" value="./packages" /> <add key="repositoryPath" value="./packages" /> </config> <packageRestore> <add key="enabled" value="false" /> <add key="automatic" value="false" /> </packageRestore> ``` - 如何使用單一檔案部署 - 調整 csproj 檔案 加上下列幾行 ```xml <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>net6.0</TargetFramework> <ImplicitUsings>enable</ImplicitUsings> <Nullable>enable</Nullable> <PublishSingleFile>true</PublishSingleFile> <SelfContained>true</SelfContained> <RuntimeIdentifier>win-x64</RuntimeIdentifier> <PublishReadyToRun>true</PublishReadyToRun> </PropertyGroup> ``` - SelfContained : publish 時是否使用單一檔案部署. - RuntimeIdentifier : 執行平台, 也可於publish時使用 -r 來表示. - 調整exe運作環境 - 修改 RuntimeIdentifier - 使用指令發佈成linux-x64平台 ```dos dotnet publish -r linux-x64 ``` - [發佈平台參考](https://learn.microsoft.com/zh-tw/dotnet/core/rid-catalog) - 參考網頁 [微軟教學網頁](https://learn.microsoft.com/zh-tw/dotnet/core/tutorials/library-with-visual-studio-code?pivots=dotnet-6-0) [.net 6 console template 變動](https://learn.microsoft.com/en-us/dotnet/core/tutorials/top-level-templates) [單一檔案部屬](https://learn.microsoft.com/zh-tw/dotnet/core/deploying/single-file/overview?tabs=cli) ## 如何讀取設定檔 - 參考 : [使用 appSetting](https://blog.darkthread.net/blog/aspnet-core-practice-appsetting/)
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up