Does anyone know whether it is possible to specify the Framework-Version when Emitting assemblies using CSharpCompilation's extensionmethod Emit?
We need to target 4.5.1 apparently since otherwise we get a nasty runtime error:
MissingMethodException
Method not found: '!!0[] System.Array.Empty()'.
Or do we have to wait till clients are upgraded to Framework 4.6 before we can make use of Roslyn?
The compiler doesn't (and has never) had a concept of "framework version". All the compiler understands is what set of references are included. It sounds like you are creating your compilation with references to 4.6 versions of the framework (possibly because you are using running assembly locations, and are running on 4.6).
Instead, you'll need to ensure that you have the 4.5.1 targeting pack installed (VS install does this automatically, but other machines may not have it), and add its references to your compilation from out of C:\Program Files (x86)\Reference Assemblies
.
The compiler will emit references to Array.Empty
if it exists in the referenced assemblies, but has fallback logic if it doesn't.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With