Jul 9, 2017 08:01 AM
(This post was last modified: Jul 9, 2017 08:16 AM by severos.)
I want to compile C# files at run time, however those files contain C#7 features -currently ValueTuples, no idea what for future-, now I thought normal code compilation works fine... however it doesn't seem so.
Current code:
As you can see, I've already added the ValueTuple dll file since it's a nuget package.
However, when I try to run the code, it can't compile at runtime, giving me error complaining about syntax, when I check the res.Output, it looks like the code is using C#5 compiler...
Now, I've left automation for a bit and tried to manually compile using csc.exe (found in ProgramFiles MSBuild) and it gives error as well complaining about the syntax.
However, when I try to compile the file normally using VisualStudio, it just compiles and run without errors/warnings (ReSharper still complains though).
Any idea how to fix that???
Update:
As I said, compiling using csc.exe doesn't work, same goes for compiling outside VisualStudio using MSBuild.exe
However, if I use VisualStudio developer prompt I can compile using MSBuild.exe but not using csc.exe ....
Current code:
PHP Code
<?php
namespace TestCSharp7Feature
{
class Program
{
static void Main(string[] args)
{
var provider = new CSharpCodeProvider(new Dictionary<string, string> {{"CompilerVersion", "v4.0"}});
var options = new CompilerParameters(new[] {"System.dll", "System.Core.dll"}, "test.dll", true);
options.GenerateInMemory = false;
options.ReferencedAssemblies.Add(Environment.CurrentDirectory + "\\System.ValueTuple.dll");
var res = provider.CompileAssemblyFromFile(options, "./CSharp7Feature.cs");
}
}
}
However, when I try to run the code, it can't compile at runtime, giving me error complaining about syntax, when I check the res.Output, it looks like the code is using C#5 compiler...
Now, I've left automation for a bit and tried to manually compile using csc.exe (found in ProgramFiles MSBuild) and it gives error as well complaining about the syntax.
However, when I try to compile the file normally using VisualStudio, it just compiles and run without errors/warnings (ReSharper still complains though).
Any idea how to fix that???
Update:
As I said, compiling using csc.exe doesn't work, same goes for compiling outside VisualStudio using MSBuild.exe
However, if I use VisualStudio developer prompt I can compile using MSBuild.exe but not using csc.exe ....
Have a cool signature? hit me up and I might use it.



