5

I am compiling a basic console app using :

C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\csc.exe /t:exe /out:myapp.exe Program.cs

Which first prints :

Microsoft (R) Visual C# Compiler version 4.6.1038.0
for C# 5
Copyright (C) Microsoft Corporation. All rights reserved.

Then fails because I am using string interpolation like $"{x}". The error is:

error CS1056: Unexpected character '$'

I assume this is because the csc.exe does not understand C# 6. How do I make this compiler C# 6 aware?

sepp2k
  • 363,768
  • 54
  • 674
  • 675
sprocket12
  • 5,368
  • 18
  • 64
  • 133

2 Answers2

7

You are using an old version of the compiler. From this MSDN forum post, the C# compiler is no longer part of the .NET Framework. You have to download it yourself.

You can do that from this NuGet statement:

nuget install Microsoft.Net.Compilers
Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325
1

I got the same problem here;

I fixed using the Roslyn compiler inside de Visual Studio 2019 instalation folder , setting up the environment variable of csc to it.

Changed

C:\Windows\Microsoft.NET\Framework64\v4.0.30319

To

C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Roslyn

In the system environment variables and worked here

Renan Duarte
  • 138
  • 1
  • 10