codedom

How can I get the current CodeDomProvider in an MSBuild Task

北城余情 提交于 2019-12-11 14:29:31
问题 I have a task and I want to generate some code using the CodeDom. How can I get either the current "language" or the CodeDomProvider for the current project calling my task? 回答1: Ok I managed to figure it out eventually: Geting a CodeDomProvider in an MSBuild Task 来源: https://stackoverflow.com/questions/395313/how-can-i-get-the-current-codedomprovider-in-an-msbuild-task

evaluate code inline (or using reflection)

流过昼夜 提交于 2019-12-11 13:58:08
问题 I've simplified this a lot to get to the core of the issue: I have a control that needs properties populated. Unfortunately the values are all sitting in CodeDom.CodeStatements. So I literally have to fish for the values by using code like this : static string GenerateCode(CodeStatementCollection statements, Control control) { var writer = new StringWriter(); var compiler = new CSharpCodeProvider(); foreach (CodeStatement statement in statements) { var codeAssignStatement = statement as

Hiding Command Prompt with CodeDomProvider

空扰寡人 提交于 2019-12-11 09:53:16
问题 I've just got my own little custom c# compiler made, using the article from MSDN. But, when I create a new Windows Forms application using my sample compiler, the MSDOS window also appears, and if I close the DOS window, my WinForms app closes too. How can I tell the Compiler? not to show the MSDOS window at all? Thank you :) Here's my code: using System; namespace JTS { public class CSCompiler { protected string ot, rt, ss, es; protected bool rg, cg; public string Compile(String se, String

CompileAssemblyFromFile

风流意气都作罢 提交于 2019-12-11 08:31:45
问题 Why I get the error when trying to do this function: let compile_file path use_asms output = use pro = new FSharpCodeProvider() let opt = CompilerParameters(use_asms, output) let res = pro.CompileAssemblyFromFile(opt, path) // <-- Error if res.Errors.Count = 0 then Some(FileInfo(res.PathToAssembly)) else None Error-code: -2147467259 Error: cant find the file specified Now I'm trying two broken implementations: type System.CodeDom.Compiler.ICodeCompiler with member this.CompileAssemblyFromFile

Analyze CodeCompileUnit for used types / classes

一曲冷凌霜 提交于 2019-12-11 07:45:25
问题 I am building a Razor template-parser using something like the following: RazorEngineHost host = new RazorEngineHost(new CSharpRazorCodeLanguage()); RazorTemplateEngine engine = new RazorTemplateEngine(host); CodeDomProvider provider = new CSharpCodeProvider(); GeneratorResults razorTemplate = engine.GenerateCode(new StringReader(template)); var cParams = new CompilerParameters(); // set params.... var result = provider.CompileAssemblyFromDom(cParams, razorTemplate.GeneratedCode); Now I would

compiling assembly from the other just compiled assembly

青春壹個敷衍的年華 提交于 2019-12-11 04:30:03
问题 I need to compile assembly in memory, that can compile another one. There is a form with one button. Here is a code of the form Imports System Imports System.Threading Imports System.CodeDom Imports System.CodeDom.Compiler Imports System.Collections Imports System.ComponentModel Imports System.Diagnostics Imports System.Drawing Imports System.IO Imports System.Windows.Forms Imports Microsoft.VisualBasic Public Class testtwo Shared str_tb As String Private Sub Button1_Click(ByVal sender As

CodeDom Reference VB6 dll

我是研究僧i 提交于 2019-12-11 02:38:36
问题 I have had no problems adding .dll files (generated from Visual Studio) to a CodeDom generated executable file. To do so, I have been using the following code: Code: string[] referenceAssemblies = { "System.dll", "System.Windows.Forms.dll", "System.Drawing.dll", "System.Data.dll", "System.Xml.dll" }; // Add the referenced assemblies to the compiler parameteres CompilerParameters cp = new CompilerParameters(referenceAssemblies, exeFile, false); However, I would now like to add a Visual Basic 6

Workaround for VB.NET partial method using CodeDom?

蓝咒 提交于 2019-12-11 01:26:24
问题 I know CodeDom doesn't support partial methods, but is there a workaround? I found a workaround for C#, but I need one for VB.NET. Thanks. 回答1: It is a horrible hack, as wicked as the C# one, but it does work: Imports System.CodeDom Imports System.CodeDom.Compiler Imports System.IO Module Module1 Sub Main() Dim unit As New CodeCompileUnit Dim nspace As New CodeNamespace("SomeNamespace") Dim vbclass As New CodeTypeDeclaration("SomeClass") vbclass.IsClass = True Dim snippet As New

“CompileAssemblyFromSource” in f# powerPack codeDom

大兔子大兔子 提交于 2019-12-10 14:43:40
问题 I am trying to get going a basic program to dynamically compile and run f# code. I am trying to run the following code: open System open System.CodeDom.Compiler open Microsoft.FSharp.Compiler.CodeDom // Our (very simple) code string consisting of just one function: unit -> string let codeString = "module Synthetic.Code\n let syntheticFunction() = \"I've been compiled on the fly!\"" // Assembly path to keep compiled code let synthAssemblyPath = "synthetic.dll" let CompileFSharpCode(codeString,

How do I select the target framework of a CodeDom compiler using C#?

痴心易碎 提交于 2019-12-10 03:14:18
问题 So I have a CodeDOM compiler written in C# that's supposed to compile another application based on one of its resources. How would I change the target .NET framework of the resource (or of the outputted executable of the compiler)? 回答1: You could pass options to the compiler using the following constructor: var providerOptions = new Dictionary<string, string>(); providerOptions.Add("CompilerVersion", "v3.5"); var compiler = new CSharpCodeProvider(providerOptions); ... 回答2: You would need to