मेरे पास CSharpCodeProvider
के आसपास एक रैपर के रूप में निम्न मानक, काफी मानक कोड है। यह वर्ग बहुत अच्छी तरह से काम करता है, और ठीक काम करता है, इत्यादि। लेकिन, इस तथ्य के बावजूद कि मेरा आवेदन .NET 3.5 के खिलाफ बनाया गया है और इस संकलन के दौरान v3.5 असेंबली का संदर्भ दे रहा है, मुझे अभी भी किसी भी तक पहुंच नहीं है लैम्ब्डा या ऑटो-गुणों जैसे अतिरिक्त अच्छे सी # 3.5 वाक्यविन्यास का। क्या यह काम करने के लिए कोई रास्ता है?CSharpCodeProvider .NET 2.0 पर फंस गया प्रतीत होता है, मुझे नई सुविधाएं कैसे मिलेंगी?
मैं इस धारणा के तहत था कि यह वर्ग सिर्फ csc.exe
के आसपास लपेट गया है, एक ऐसा विचार जो मेरी फ़ायरवॉल द्वारा पुष्टि की जाएगी (मेरा एप्लिकेशन csc.exe
तक पहुंचने का प्रयास करता है)। शायद मुझे कुछ options.CompilerOptions
सेट करने की आवश्यकता है?
protected virtual void Compile()
{
Microsoft.CSharp.CSharpCodeProvider csProvider = new Microsoft.CSharp.CSharpCodeProvider();
CompilerParameters options = new CompilerParameters();
options.GenerateExecutable = false;
options.GenerateInMemory = true;
options.IncludeDebugInformation = true;
foreach (string s in this.ReferencedAssemblies)
{
options.ReferencedAssemblies.Add(s);
}
CompilerResults result;
string source = this.CodeTemplate;
// [snip] Do some manipulation to fill in the template with values.
result = csProvider.CompileAssemblyFromSource(options, source);
this.HasErrors = result.Errors.HasErrors;
this.Errors = new CompilerError[result.Errors.Count];
result.Errors.CopyTo(Errors, 0);
if (HasErrors && ThrowOnErrors)
throw new InvalidProgramException("The code currently stored in the " + this.GetType() + " cannot be compiled.");
else if (HasErrors)
return;
this.CompiledAssembly = result.CompiledAssembly;
}
संपादित करें:
मैं mscorlib
, System.Core
, System.Text
और इस समय अपने ही विधानसभाओं में से एक के लिए संदर्भ की है।
3.5 2.0 फ्रेमवर्क पर बनाया गया है। –