Roslyn from command line('cmd'), Windows 10 scenario example:
( Note: No need Visual Studio installed, but only the .NET core )
Open 'cmd' and create folder "dotnet-csharp-tools":
D:>mkdir "dotnet-csharp-tools"
Navigate to folder "dotnet-csharp-tools":
D:>cd "dotnet-csharp-tools"
In folder "dotnet-csharp-tools" download 'nuget.exe' latest version from:
https://www.nuget.org/downloads
Check name of the last version of 'Microsoft.CodeDom.Providers.DotNetCompilerPlatform' from:
https://www.nuget.org/packages/Microsoft.CodeDom.Providers.DotNetCompilerPlatform/
For example: 'Microsoft.CodeDom.Providers.DotNetCompilerPlatform -Version 3.6.0'
From 'cmd'(opened folder "dotnet-csharp-tools"), run command:
D:\dotnet-csharp-tools>nuget install Microsoft.CodeDom.Providers.DotNetCompilerPlatform -Version 3.6.0
From 'cmd' navigate to 'D:\dotnet-csharp-tools\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.3.6.0\tools\Roslyn472'(warning : folder name 'Roslyn472' may be different, if is other version)
D:\dotnet-csharp-tools>cd Microsoft.CodeDom.Providers.DotNetCompilerPlatform.3.6.0\tools\Roslyn472
From 'File explorer' find 'csc.exe'(in the current folder 'Roslyn472'). Make copy of 'csc.exe' with name 'csc-roslyn.exe'(name can be whatever).
For 'Windows 10', open:
'Edit system environment variables' -> 'System variables' -> 'path' -> 'Edit' -> 'New' -> D:\dotnet-csharp-tools\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.3.6.0\tools\Roslyn472
Close and open again 'cmd'(the command prompt). This 'cmd' restart needed, because 'system environment variables' are edited.
Check if 'csc-roslyn' is recognized by 'cmd' by run command:
csc-roslyn
Create folder 'D:\csharp-projects'(folder name can be whatever) and create in 'D:\csharp-projects' C# source files, for example:
Vehicle.cs
class Vehicle { private string name = "unknown"; private int producedYear = -1; public Vehicle(string name, int producedYear) { this.Name = name; this.ProducedYear = producedYear; } public string Name { get { return this.name; } set { this.name = value; } } public int ProducedYear { get { return this.producedYear; } set { this.producedYear = value; } } }
Car.cs
class Car : Vehicle { private string maker = "unknown"; public Car(string name, int age, string maker) : base(name, age) { this.Maker = maker; } public string Maker { get { return this.maker; } set { this.maker = value; } } public override string ToString() { return $"{this.Name}, {this.ProducedYear}, {this.Maker}"; } }
Autoservice.cs
using System; class Autoservice { public static void Main() { Car car1 = new Car("Ford Taunus", 1971, "Ford"); Car car2 = new Car("Opel Ascona", 1978, "Opel"); Car car3 = new Car("Saab 900", 1984, "Saab"); Console.WriteLine(car1); Console.WriteLine(car2); Console.WriteLine(car3); } }
Open 'D:\csharp-projects' from 'cmd'(the command prompt) and run command:
csc-roslyn /target:exe /out:Autoservice.exe Vehicle.cs Car.cs Autoservice.cs
Run from 'cmd':
Autoservice.exe
Result should be:
Ford Taunus, 1971, Ford
Opel Ascona, 1978, Opel
Saab 900, 1984, Saab
csc.exeare you running? What version number does it report? When I runcsc.exefrom the command line - with the developer command prompt for VS2015 - I see version 1.0.0.50618, and that's Roslyn.cscfrom "%Windir%\Microsoft.NET\Framework64\v4.0.30319". I'm not using batch file for developer command prompt, it's just a cmd without any special settings.cscfrom msbuild instead :) See my answer. If you want to run developer commands, using the developer command prompt feels like a wise choice...