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

Visual Studio 없이 최신 C# (8.0) 컴파일러를 사용하는 방법

아래의 사이트에 방문하면,

dotnet/roslyn
; https://github.com/dotnet/roslyn

소스 코드와 함께 설치 방법이 나옵니다. 그렇다고 소스 코드를 직접 빌드할 필요가 없는데, 왜냐하면 빌드 버전을 이미 NuGet을 통해 공개하고 있기 때문입니다. 따라서 nuget을 이용해 현재의(2019-03-04 기준 C# 7.3) C# 컴파일러를 다음과 같이 다운로드할 수 있습니다.

# Install C# and VB compilers
c:\git_clone>nuget install Microsoft.Net.Compilers

그럼 하위에 "Microsoft.Net.Compilers.2.10.0" 폴더가 생기고 다음과 같이 C# 컴파일러가 지원하는 언어의 버전을 알아낼 수 있습니다.

c:\git_clone\Microsoft.Net.Compilers.2.10.0\tools>csc -langversion:?
Supported language versions:
default
1
2
3
4
5
6
7.0 (default)
7.1
7.2
7.3 (latest)
latest

물론 소스 코드 파일 기준으로 daily 빌드를 받는 것도 가능합니다. 이를 위해 우선 다음의 NuGet feed를 등록해야 합니다.

https://dotnet.myget.org/F/roslyn/api/v3/index.json

NuGet의 sources는 결국 "%AppData%\NuGet\NuGet.config" 파일에 있으므로 이것을 편집해도 되는데,

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <disabledPackageSources />
  <activePackageSource>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
  </activePackageSource>
  <packageRestore>
    <add key="enabled" value="True" />
    <add key="automatic" value="True" />
  </packageRestore>
  <bindingRedirects>
    <add key="skip" value="False" />
  </bindingRedirects>
  <packageSources>
    <!--add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" /-->
   <clear />
    <add key="AspNetVNext" value="https://dotnet.myget.org/F/aspnetcore-dev/api/v3/index.json" />
    <add key="NetCoreVNext" value="https://dotnet.myget.org/F/dotnet-core/api/v3/index.json" />
    <add key="NuGet.org" value="https://api.nuget.org/v3/index.json" />
  </packageSources>
  <packageManagement>
    <add key="format" value="1" />
    <add key="disabled" value="False" />
  </packageManagement>
  <apikeys>
    <add key="https://www.nuget.org/api/v2/package" value="AQAAANCMnd8BFdERjHoAwE/Cl+sBAAAAoNzryzUGzUiymbsVqn4hCgAAAAACAAAAAAAQZgAAAAEAACAAAACOH/8oz9g6rvJfQAWT4F2W69+d0WEjD7FpgJy3ufhYcQAAAAAOgAAAAAIAACAAAABNmEBkzKhr/aPwmx6Fjr6cxCd8u0R9+kOwv66Sp08eXjAAAACyyKE5II1du9lJ0MmVlVWWiCWYZR/bbS1qh9In3uL6Jct+2D8kTNibrGnANGVBurhAAAAAR+4oRfAdRIh3E7MOpIkZURR/UIsT6uis3kgksspnEAGXiz5BM6VNsmdWQAIaZXhE6WDOXn2xazvp3zWp1OKZsw==" />
  </apikeys>
</configuration>

따라서 다음과 같이 rosyln 항목을 NuGet.org보다 위에 넣어줍니다.

<packageSources>
	<!--add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" /-->
	<clear />
	<add key="AspNetVNext" value="https://dotnet.myget.org/F/aspnetcore-dev/api/v3/index.json" />
	<add key="NetCoreVNext" value="https://dotnet.myget.org/F/dotnet-core/api/v3/index.json" />
	<add key="RoslynNext" value="https://dotnet.myget.org/F/roslyn/api/v3/index.json" />
	<add key="NuGet.org" value="https://api.nuget.org/v3/index.json" />
</packageSources>

반영 여부를 확인해 주고,

E:\git_clone\cs8> nuget sources
Registered Sources:

  1.  AspNetVNext [Enabled]
      https://dotnet.myget.org/F/aspnetcore-dev/api/v3/index.json
  2.  NetCoreVNext [Enabled]
      https://dotnet.myget.org/F/dotnet-core/api/v3/index.json
  3.  RoslynNext [Enabled]
      https://dotnet.myget.org/F/roslyn/api/v3/index.json
  4.  NuGet.org [Enabled]
      https://api.nuget.org/v3/index.json

이제 다음과 같이 실행해 주면 됩니다.

c:\git_clone> nuget install Microsoft.Net.Compilers -Version 3.1.0-beta1-19153-01

위에 기재한 이상한 버전 번호는 다음의 갤러리로 들어가 구할 수 있습니다.

roslyn - Microsoft.Net.Compilers
; https://dotnet.myget.org/feed/roslyn/package/nuget/Microsoft.Net.Compilers

참고로, NuGet.config에 별도 소스를 등록하고 싶지 않다면 다음과 같이 nuget 명령에 -Source를 지정해도 됩니다.

c:\git_clone> nuget install Microsoft.Net.Compilers -Version 3.1.0-beta1-19153-01 -Source https://dotnet.myget.org/F/roslyn/api/v3/index.json




자, 그럼 설치 폴더의 하위인 tools 폴더로 들어가,

c:\git_clone> cd c:\git_clone\Microsoft.Net.Compilers.3.1.0-beta1-19153-01\tools

다음과 같이 지원되는 C# 언어 버전을 확인할 수 있습니다.

c:\git_clone\Microsoft.Net.Compilers.3.1.0-beta1-19153-01\tools> csc -langversion:?
Supported language versions:
default
1
2
3
4
5
6
7.0
7.1
7.2
7.3 (default)
8.0 *beta*
latestmajor
preview
latest

그리고 C# 8.0의 신규 문법으로 작성한 프로그램을 빌드한다면 다음과 같이 langversion 옵션을 지정합니다.

E:\git_clone\cs8\sample\ConsoleApp1\ConsoleApp1> csc Program.cs -langversion:8




혹시나, 그래도 roslyn을 빌드하고 싶다면 (약간 옛날 글이지만) 아래의 글을 참고해 직접 빌드해도 됩니다. ^^

C# 6.0 오픈 소스 컴파일러 Roslyn - 빌드 및 테스트 방법
; https://www.sysnet.pe.kr/2/0/10812




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

[연관 글]






[최초 등록일: ]
[최종 수정일: 3/5/2019]

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

비밀번호

댓글 작성자
 




1  2  3  4  5  [6]  7  8  9  10  11  12  13  14  15  ...
NoWriterDateCnt.TitleFile(s)
13483정성태12/14/20232313닷넷: 2184. C# - 하나의 resource 파일을 여러 프로그램에서 (AOT 시에도) 사용하는 방법파일 다운로드1
13482정성태12/13/20232903닷넷: 2183. C# - eFriend Expert OCX 예제를 .NET Core/5+ Console App에서 사용하는 방법 [2]파일 다운로드1
13481정성태12/13/20232285개발 환경 구성: 693. msbuild - .NET Core/5+ 프로젝트에서 resgen을 이용한 리소스 파일 생성 방법파일 다운로드1
13480정성태12/12/20232658개발 환경 구성: 692. Windows WSL 2 + Chrome 웹 브라우저 설치
13479정성태12/11/20232339개발 환경 구성: 691. WSL 2 (Ubuntu) + nginx 환경 설정
13477정성태12/8/20232530닷넷: 2182. C# - .NET 7부터 추가된 Int128, UInt128 [1]파일 다운로드1
13476정성태12/8/20232268닷넷: 2181. C# - .NET 8 JsonStringEnumConverter의 AOT를 위한 개선파일 다운로드1
13475정성태12/7/20232330닷넷: 2180. .NET 8 - 함수 포인터에 대한 Reflection 정보 조회파일 다운로드1
13474정성태12/6/20232177개발 환경 구성: 690. 닷넷 코어/5+ 버전의 ilasm/ildasm 실행 파일 구하는 방법 - 두 번째 이야기
13473정성태12/5/20232384닷넷: 2179. C# - 값 형식(Blittable)을 메모리 복사를 이용해 바이트 배열로 직렬화/역직렬화파일 다운로드1
13472정성태12/4/20232196C/C++: 164. Visual C++ - InterlockedCompareExchange128 사용 방법
13471정성태12/4/20232276Copilot - To enable GitHub Copilot, authorize this extension using GitHub's device flow
13470정성태12/2/20232567닷넷: 2178. C# - .NET 8부터 COM Interop에 대한 자동 소스 코드 생성 도입파일 다운로드1
13469정성태12/1/20232290닷넷: 2177. C# - (Interop DLL 없이) CoClass를 이용한 COM 개체 생성 방법파일 다운로드1
13468정성태12/1/20232232닷넷: 2176. C# - .NET Core/5+부터 달라진 RCW(Runtime Callable Wrapper) 대응 방식파일 다운로드1
13467정성태11/30/20232321오류 유형: 882. C# - Unhandled exception. System.Runtime.InteropServices.COMException (0x800080A5)파일 다운로드1
13466정성태11/29/20232492닷넷: 2175. C# - DllImport 메서드의 AOT 지원을 위한 LibraryImport 옵션
13465정성태11/28/20232241개발 환경 구성: 689. MSBuild - CopyToOutputDirectory가 "dotnet publish" 시에는 적용되지 않는 문제파일 다운로드1
13464정성태11/28/20232383닷넷: 2174. C# - .NET 7부터 UnmanagedCallersOnly 함수 export 기능을 AOT 빌드에 통합파일 다운로드1
13463정성태11/27/20232302오류 유형: 881. Visual Studio - NU1605: Warning As Error: Detected package downgrade
13462정성태11/27/20232343오류 유형: 880. Visual Studio - error CS0246: The type or namespace name '...' could not be found
13461정성태11/26/20232378닷넷: 2173. .NET Core 3/5+ 기반의 COM Server를 registry 등록 없이 사용하는 방법파일 다운로드1
13460정성태11/26/20232330닷넷: 2172. .NET 6+ 기반의 COM Server 내에 Type Library를 내장하는 방법파일 다운로드1
13459정성태11/26/20232306닷넷: 2171. .NET Core 3/5+ 기반의 COM Server를 기존의 regasm처럼 등록하는 방법파일 다운로드1
13458정성태11/26/20232317닷넷: 2170. .NET Core/5+ 기반의 COM Server를 tlb 파일을 생성하는 방법(tlbexp)
13457정성태11/25/20232258VS.NET IDE: 187. Visual Studio - 16.9 버전부터 추가된 "Display inline type hints" 옵션
1  2  3  4  5  [6]  7  8  9  10  11  12  13  14  15  ...