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)
12211정성태4/27/202012584개발 환경 구성: 486. WSL에서 Makefile로 공개된 리눅스 환경의 C/C++ 소스 코드 빌드
12210정성태4/20/202013069.NET Framework: 903. .NET Framework의 Strong-named 어셈블리 바인딩 (1) - app.config을 이용한 바인딩 리디렉션 [1]파일 다운로드1
12209정성태4/13/202011105오류 유형: 614. 리눅스 환경에서 C/C++ 프로그램이 Segmentation fault 에러가 발생한 경우 (2)
12208정성태4/12/202010484Linux: 29. 리눅스 환경에서 C/C++ 프로그램이 Segmentation fault 에러가 발생한 경우
12207정성태4/2/20209535스크립트: 19. Windows PowerShell의 NonInteractive 모드
12206정성태4/2/202011960오류 유형: 613. 파일 잠금이 바로 안 풀린다면? - The process cannot access the file '...' because it is being used by another process.
12205정성태4/2/20209267스크립트: 18. Powershell에서는 cmd.exe의 명령어를 지원하진 않습니다.
12204정성태4/1/20208962스크립트: 17. Powershell 명령어에 ';' (semi-colon) 문자가 포함된 경우
12203정성태3/18/202011067오류 유형: 612. warning: 'C:\ProgramData/Git/config' has a dubious owner: '...'.
12202정성태3/18/202013723개발 환경 구성: 486. .NET Framework 프로젝트를 위한 GitLab CI/CD Runner 구성
12201정성태3/18/202011551오류 유형: 611. git-credential-manager.exe: Using credentials for username "Personal Access Token". [1]
12200정성태3/18/202011815VS.NET IDE: 145. NuGet + Github 라이브러리 디버깅 관련 옵션 3가지 - "Enable Just My Code" / "Enable Source Link support" / "Suppress JIT optimization on module load (Managed only)"
12199정성태3/17/20209724오류 유형: 610. C# - CodeDomProvider 사용 시 Unhandled Exception: System.IO.DirectoryNotFoundException: Could not find a part of the path '...\f2_6uod0.tmp'.
12198정성태3/17/202012637오류 유형: 609. SQL 서버 접속 시 "Cannot open user default database. Login failed."
12197정성태3/17/202011722VS.NET IDE: 144. .NET Core 콘솔 응용 프로그램을 배포(publish) 시 docker image 자동 생성 - 두 번째 이야기 [1]
12196정성태3/17/20209532오류 유형: 608. The ServicedComponent being invoked is not correctly configured (Use regsvcs to re-register).
12195정성태3/16/202011276.NET Framework: 902. C# - 프로세스의 모든 핸들을 열람 - 세 번째 이야기
12194정성태3/16/202013588오류 유형: 607. PostgreSQL - Npgsql.NpgsqlException: sorry, too many clients already
12193정성태3/16/202010262개발 환경 구성: 485. docker - SAP Adaptive Server Enterprise 컨테이너 실행 [1]
12192정성태3/14/202012741개발 환경 구성: 484. docker - Sybase Anywhere 16 컨테이너 실행
12191정성태3/14/202013174개발 환경 구성: 483. docker - OracleXE 컨테이너 실행 [1]
12190정성태3/14/20209090오류 유형: 606. Docker Desktop 업그레이드 시 "The process cannot access the file 'C:\Program Files\Docker\Docker\resources\dockerd.exe' because it is being used by another process."
12189정성태3/13/202014099개발 환경 구성: 482. Facebook OAuth 처리 시 상태 정보 전달 방법과 "유효한 OAuth 리디렉션 URI" 설정 규칙
12188정성태3/13/202016767Windows: 169. 부팅 시점에 실행되는 chkdsk 결과를 확인하는 방법
12187정성태3/12/20208887오류 유형: 605. NtpClient was unable to set a manual peer to use as a time source because of duplicate error on '...'.
12186정성태3/12/202010155오류 유형: 604. The SysVol Permissions for one or more GPOs on this domain controller and not in sync with the permissions for the GPOs on the Baseline domain controller.
... 46  47  48  49  50  51  52  53  54  55  56  57  [58]  59  60  ...