Answer the question
In order to leave comments, you need to log in
Can't find compiler executable csc.exe?
Visual Studio 2019 development environment, C# language, .NET Framework v4.7.2. I'm trying to compile some simple code that should compile a new file as the program runs. The code is taken from here - https://habr.com/ru/post/67431/ . An exception occurs while compiling
Cannot find compiler executable csc.exein line
CompilerResults results = provider.CompileAssemblyFromSource(compilerParams, source);
There are solutions to this problem on the net, but for other situations, but for me the error occurs in a simple code example. using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Reflection;
using Microsoft.CSharp;
namespace ConsoleCompile
{
class Program
{
static void Main(string[] args)
{
// Source code для компиляции
string source =
@"
using System.Collections.Generic;
using System.Linq;
namespace Foo
{
public class Bar
{
public static void SayHello()
{
System.Console.WriteLine(""Hello World"");
System.Console.WriteLine( string.Join("","", Enumerable.Range(0,10).Select(n=>n.ToString()).ToArray() ) );
}
}
}
";
// Настройки компиляции
Dictionary<string, string> providerOptions = new Dictionary<string, string>
{
{"CompilerVersion", "v4.7.2"}
};
CSharpCodeProvider provider = new CSharpCodeProvider(providerOptions);
CompilerParameters compilerParams = new CompilerParameters
{ OutputAssembly = "D:\\Foo.EXE", GenerateExecutable = true };
// Компиляция
CompilerResults results = provider.CompileAssemblyFromSource(compilerParams, source);
// Выводим информацию об ошибках
Console.WriteLine("Number of Errors: {0}", results.Errors.Count);
foreach (CompilerError err in results.Errors)
{
Console.WriteLine("ERROR {0}", err.ErrorText);
}
Console.ReadKey();
}
}
}
Answer the question
In order to leave comments, you need to log in
Just now in MVS Community 2017 your code was built without errors, didn't change or tweak anything.
Try to reinstall the .net framework, or rather update to the latest one, or specify repair in the installer
You don't have csc in PATH. It must lie somewhere in the bowels of visual studio, emnip.
In general, there is no point in compiling code via csc now, when you can immediately access the api roslin.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question