I created the following program
public class Program
{
static void Main()
{
System.Console.WriteLine("Hello, World!");
}
}
When compiling the code in the command prompt (c:\Windows\Microsoft.NET\Framework\v4.0.30319\csc hello.cs) which returns
Microsoft (R) Visual C# Compiler version 4.7.3056.0
for C# 5
Copyright (C) Microsoft Corporation. All rights reserved.
This compiler is provided as part of the Microsoft (R) .NET Framework, but only supports language versions up to C# 5, which is no longer the latest version. For compilers that support newer versions of the C# programming language, see http://go.microsoft.com/fwlink/?LinkID=533240
The program still compiles so I thought no big deal. Based on other searches I've done I it seemed as if this message is only informational.
However, for the program
public class Program
{
static void Main()
{
System.Console.WriteLine(DateTime.Now.DayOfWeek);
}
}
the return is
Microsoft (R) Visual C# Compiler version 4.7.3056.0
for C# 5
Copyright (C) Microsoft Corporation. All rights reserved.
This compiler is provided as part of the Microsoft (R) .NET Framework, but only supports language versions up to C# 5, which is no longer the latest version. For compilers that support newer versions of the C# programming language, see http://go.microsoft.com/fwlink/?LinkID=533240
hello.cs(5,28): error CS0103: The name 'DateTime' does not exist in the current context
which should work fine according to the pluralsight videos I'm following along with. After some searches many of the answers refer to changing the version of C# being used in the project but can't seem to translate that to working in the command prompt. What needs to change?
Step 1 - CLR code: The first thing we need to do is to write the CLR code. This could be written in either C#.NET . In this example we are using C#.
Step 2 - Compile CLR Code In order to use this code, the code has to be compiled.
The following command is run from a command line to compile the CLR code using the csc.exe application So from a command line run the command as follows: cd C:\yourfolder C:\Windows\Microsoft.NET\Framework64\v4.0.30319\vbc /target:library SendEmail.cs After this you have this : The code should now be compiled in a file called: C:\yourfolder\SendEmail.dll
Check the revised code/comments:
There are several versions of C# compiler (csc.exe) available on the system. So you have
c:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\Roslyn\csc.exe
When you compiles with
You are using the C# compiler that shipped with .NET Framework, and this compiler only supports language features up to C# 5.0.
For example, it cannot compile the following program which uses the new C# 6.0 language feature
Await in catch/finally blocks
.So the warning message means,
the compiler you choose to use (the one shipped with .NET Framework) is not capable of compiling new features introduced after C# 5.0. The compilation may succeed if don't use any new feature, just like your example. But you have better use the newer compilers - Roslyn that shipped with Visual Studio - to take advantage of the full power of the compiler.
The solution
Use this in your command line (the path may differs based on your VS edition)
Reference
Stackoverflow user Lex Li gave an excellent explanation on the versioning history of the C# compilers in this post.