การ Build .NET Framework ด้วย .NET Core CLI บน macOS โดยไม่ต้องติดตั้ง Mono

wk
wk
Nov 1 · 1 min read
  1. สร้าง Project
$ dotnet new classlib \
--language c# \
--output src/MyLibrary
--target-framework-override net45

2. ลอง Build

$ dotnet build src/MyLibrary/MyLibrary.csproj
CSC : error CS0006: Metadata file '/mscorlib.dll' could not be found

จะ Build ไม่ผ่านเนื่องจากไม่มี Library mscorelib ที่มาพร้อมกับ Mono

3. ติดตั้ง Microsoft.NETFramework.ReferenceAssemblies เพื่อใช้แทน Mono

$ dotnet add src/MyLibrary/MyLibrary.csproj package \
Microsoft.NETFramework.ReferenceAssemblies \
--version 1.0.0-preview.2

4. ลอง Build อีกครั้ง

$ dotnet build src/MyApp/MyApp.csprojMicrosoft (R) Build Engine version 16.3.0+0f4c62fea for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
Build succeeded.
0 Warning(s)
0 Error(s)

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade