Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 
(연관된 글이 2개 있습니다.)

Visual Studio 2022 17.2 버전에서 C# 11 또는 .NET 7.0 preview 적용 방법

현재 공개되고 있는 .NET 7.0 preview 실습을 하려면 우선 SDK를 다운로드하고,

Download .NET 7.0
; https://dotnet.microsoft.com/en-us/download/dotnet/7.0

.NET 7용 TFM(Target Framework Moniker)만,

Targeting .NET 7
; https://devblogs.microsoft.com/dotnet/announcing-dotnet-7-preview-5/#readexactly-and-readatleast

csproj 프로젝트 파일에 적용하면 됩니다.

<TargetFramework>net7.0</TargetFramework>

예를 들어, .NET 6 콘솔 프로젝트에서,

internal class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine(Environment.Version); // 출력 결과: 6.0.6
    }
}

csproj 파일을 열어 TargetFramework만 net7.0으로 바꾼 후,

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net7.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

</Project>

소스 코드를 다시 실행하면 Environment.Version 값이 7.0.0으로 출력되는 것을 확인할 수 있습니다.




비주얼 스튜디오에서 위와 같이 TFM을 net7.0으로 적용 후 빌드하면 이런 오류가 발생하는 경우도 있을 것입니다.

NETSDK1045 The current .NET SDK does not support targeting .NET 7.0. Either target .NET 6.0 or lower, or use a version of the .NET SDK that supports .NET 7.0.


해결 방법은, "Tools" / "Options" 메뉴를 선택해 "Environment" / "Preview Features" 범주에서 "Use prviews of the .NET SDK (requires restart)" 옵션을 선택 후 비주얼 스튜디오를 재시작하면 됩니다.

또한, 해당 옵션이 꺼져 있다면 C# 프로젝트 선택 시에 "Framework" 단계에서 ".NET 7.0 (Preview)" 항목이,

net7_preview_1.png

아예 나오지 않습니다.




C# 11의 경우 아직 정식 릴리스는 안 되었지만 현재 Visual Studio 2022 17.x 버전에서 일부 문법들은 사용할 수 있습니다. 이를 위해 변경해야 할 것은, csproj 파일에 다음의 설정만 추가하면 됩니다.

<LangVersion>preview</LangVersion>

사실, 저 설정 없이 C# 11 문법을 사용하면 친절하게 오류 메시지를 통해 알려주긴 합니다. ^^

CS8652 The feature 'raw string literals' is currently in Preview and *unsupported*. To use Preview features, use the 'preview' language version.


참고로, C# 11 컴파일은 "Use prviews of the .NET SDK (requires restart)" 옵션을 설정하지 않아도 가능합니다.




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]

[연관 글]






[최초 등록일: ]
[최종 수정일: 6/17/2022]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 




... 46  47  48  49  50  51  52  53  54  55  56  57  58  59  [60]  ...
NoWriterDateCnt.TitleFile(s)
12161정성태2/26/202010259오류 유형: 597. manifest - The value "x64" of attribute "processorArchitecture" in element "assemblyIdentity" is invalid.
12160정성태2/26/202010924개발 환경 구성: 469. Reg-free COM 개체 사용을 위한 manifest 파일 생성 도구 - COMRegFreeManifest
12159정성태2/26/20208991오류 유형: 596. Visual Studio - The project needs to include ATL support
12158정성태2/25/202010990디버깅 기술: 165. C# - Marshal.GetIUnknownForObject/GetIDispatchForObject 사용 시 메모리 누수(Memory Leak) 발생파일 다운로드1
12157정성태2/25/202011001디버깅 기술: 164. C# - Marshal.GetNativeVariantForObject 사용 시 메모리 누수(Memory Leak) 발생 및 해결 방법파일 다운로드1
12156정성태2/25/202010245오류 유형: 595. LINK : warning LNK4098: defaultlib 'nafxcw.lib' conflicts with use of other libs; use /NODEFAULTLIB:library
12155정성태2/25/20209444오류 유형: 594. Warning NU1701 - This package may not be fully compatible with your project
12154정성태2/25/20209220오류 유형: 593. warning LNK4070: /OUT:... directive in .EXP differs from output filename
12153정성태2/23/202012080.NET Framework: 898. Trampoline을 이용한 후킹의 한계파일 다운로드1
12152정성태2/23/202011812.NET Framework: 897. 실행 시에 메서드 가로채기 - CLR Injection: Runtime Method Replacer 개선 - 세 번째 이야기(Trampoline 후킹)파일 다운로드1
12151정성태2/22/202012259.NET Framework: 896. C# - Win32 API를 Trampoline 기법을 이용해 C# 메서드로 가로채는 방법 - 두 번째 이야기 (원본 함수 호출)파일 다운로드1
12150정성태2/21/202012172.NET Framework: 895. C# - Win32 API를 Trampoline 기법을 이용해 C# 메서드로 가로채는 방법 [1]파일 다운로드1
12149정성태2/20/202011979.NET Framework: 894. eBEST C# XingAPI 래퍼 - 연속 조회 처리 방법 [1]
12148정성태2/19/202013227디버깅 기술: 163. x64 환경에서 구현하는 다양한 Trampoline 기법 [1]
12147정성태2/19/202011805디버깅 기술: 162. x86/x64의 기계어 코드 최대 길이
12146정성태2/18/202012130.NET Framework: 893. eBEST C# XingAPI 래퍼 - 로그인 처리파일 다운로드1
12145정성태2/18/202011247.NET Framework: 892. eBEST C# XingAPI 래퍼 - Sqlite 지원 추가파일 다운로드1
12144정성태2/13/202011326.NET Framework: 891. 실행 시에 메서드 가로채기 - CLR Injection: Runtime Method Replacer 개선 - 두 번째 이야기파일 다운로드1
12143정성태2/13/20209354.NET Framework: 890. 상황별 GetFunctionPointer 반환값 정리 - x64파일 다운로드1
12142정성태2/12/202011176.NET Framework: 889. C# 코드로 접근하는 MethodDesc, MethodTable파일 다운로드1
12141정성태2/10/202010641.NET Framework: 888. C# - ASP.NET Core 웹 응용 프로그램의 출력 가로채기 [2]파일 다운로드1
12140정성태2/10/202010602.NET Framework: 887. C# - ASP.NET 웹 응용 프로그램의 출력 가로채기파일 다운로드1
12139정성태2/9/202012037.NET Framework: 886. C# - Console 응용 프로그램에서 UI 스레드 구현 방법
12138정성태2/9/202014831.NET Framework: 885. C# - 닷넷 응용 프로그램에서 SQLite 사용 [6]파일 다운로드1
12137정성태2/9/20209763오류 유형: 592. [AhnLab] 경고 - 디버거 실행을 탐지했습니다.
12136정성태2/6/202010301Windows: 168. Windows + S(또는 Q)로 뜨는 작업 표시줄의 검색 바가 동작하지 않는 경우
... 46  47  48  49  50  51  52  53  54  55  56  57  58  59  [60]  ...