generating .cs files with lower language version
Background
I'm developing an extension code for ancient dotnet system.
The system requires all .cs
files to be in C# 6.0 Language version. Said ancient system reads .cs
files at runtime. Therefore, the only thing I can do is to prepare 'raw' .cs
files as-is, not as compiled .dll
files.
Question
Is there a way to write .cs
in up-to-date version, and then simply 'translate' them into older version of them?
Note that TargetFramework
option does not work, as I'm not doing any compiling. I'm only trying to transform .cs
into another .cs
.
Example
namespace Test;
// code...
This file scoped na开发者_运维问答mespace works in modern C# 10.0, but it fails if I try to feed it into an older system. As this feature does not exist in C# 6.0.
So, It would be better if I could:
////////// source.cs
namespace Test;
public class Class {}
//////////
// some magic happens...
////////// dist.cs
namespace Test {
public class Class {}
}
//////////
Compile your code with the version of your choice, then decompile it with ILSpy while setting the version of language to C# 6.0.
精彩评论