Yearly Archive 2023-12-02

Byphunsanit

C#: Feature ‘using declarations’ is not available in C# 7.3. Please use language version

เรื่องของเรื่องคือ ไปใช้ NuGet package แปลก ๆ ที่ใช้ .NET version 7.3 แต่ตอนนี้เจอแต่หน้าให้โหลด .NET 7.0 แล้วเวลา run project จะขึ้นมาว่า Feature ‘using declarations’ is not available in C# 7.3. Please use language version … แล้วจะเอา SDK 7.3 มาจากไหน ? จะใช้ .NET 4.6 เหรอ แล้ว package อื่นละ

  1. ปิด Visual Studio หรือ Visual Studio Code
  2. ไปที่ .csproj ของ project เช่น Pitt.csproj
  3. ค้นหา <PropertyGroup> แล้วเพิ่ม
    <LangVersion>latest</LangVersion>
    <Nullable>enable</Nullable>
    <NullableContextOptions>enable</NullableContextOptions>

    เปลี่ยน TargetFrameworkVersion จาก
    <TargetFrameworkVersion>v2.x</TargetFrameworkVersion>
    เป็น version ที่สามารถใช้ได้ เช่น
    <TargetFrameworkVersion>v4.8.1</TargetFrameworkVersion>
  4. เปิด Visual Studio หรือ Visual Studio Code
  5. ฺupdate NuGet
  6. Rebuild Solution

อ่านเพิ่มเติม