csharpcodeprovider

Can't include Newtonsoft JSON in CSharpCodeProvider script

谁说我不能喝 提交于 2021-01-27 21:20:58
问题 I am trying to use JSON in a dynamically compiled script. However, when I include the library and add a JObject, I get errors like: "The type 'System.Dynamic.IDynamicMetaObjectProvider' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'." I included MathNet.Numerics just fine. Here is my setup. Console application .NET Framework 4 (so it matches the runtime compile) Nuget

Compile Func<T1, TResult> from string on the fly

天涯浪子 提交于 2020-01-04 16:24:51
问题 I have a string string input; with some code (all below is in that string) var x = s.IndexOf("a"); return String.Format(s, x); Now, I would like to achieve following scenario: Func<string, string> f = Compile(input); var test = "dcba - {0}"; var result = f(test); // result = "dcba - 3"; I assume, that the actual T1, TResult are known (here: string, string), and that input is named "s". I can achieve it this way: var input = "var x = s.IndexOf(\"a\"); return String.Format(s, x);"; var

How can we add embedded resources to a file which is compiled from a source file at run-time

左心房为你撑大大i 提交于 2019-12-28 16:12:54
问题 I'm writing a small application which works at compiling a file from a source (.cs) code file using a function: public static bool CompileExecutable(String sourceName) { //Source file that you are compliling FileInfo sourceFile = new FileInfo(sourceName); //Create a C# code provider CodeDomProvider provider = CodeDomProvider.CreateProvider("CSharp"); //Create a bool variable for to to use after the complie proccess to see if there are any erros bool compileOk = false; //Make a name for the

How to improve compile time using CSharpCodeProvider

旧时模样 提交于 2019-12-23 02:19:12
问题 I have an application where user can create its own formula it works fine for all case but when i have DateTime Fields in my formula the compilation part of the code take around 132 ms for one formula where at the same time i have 31 formula each with different value. using Microsoft.CSharp; using System; using System.CodeDom.Compiler; namespace abc { public class Abc { static void Main() { var code = @" using System; namespace First { public class program { public static int Main() { if

What happens if I don't specify CompilerVersion with CSharpCodeProvider and why do most samples specify it?

微笑、不失礼 提交于 2019-12-13 14:35:15
问题 Typical code samples using CSharpCodeProvider pass CompilerVersion parameter. Code from here: var codeProvider = new CSharpCodeProvider( new Dictionary<String, String> { { "CompilerVersion", "v3.5" } }); I've tried to pass an empty dictionary and also tried to call the parameterless constructor of CSharpCodeProvider and the result is the same. So what happens internally if I don't specify `CompilerVersion? Why do most samples specify it at all times? 回答1: The documentation states that it gets

Loading assembly dynamically from a Typeprovider

倖福魔咒の 提交于 2019-12-11 20:29:21
问题 I'm trying to add a feature to a type provider I'm working on to allow the user to specify a type. with Since type providers cannot provide generic methods, it seems the only way to do it is to reference the assembly that has the type. I've tried to make a proof of concept for this using a type from the Owin library, but I'm running into an issue when trying to use the provided type: It says it cannot find the file, even though it obviously exists, or else the CSharpCodeProvider that I'm

Change icon of generated exe

我的未来我决定 提交于 2019-12-11 09:45:07
问题 I'm generating an executable file with VB.NET using CodeDomProvider. Is there a way to change the icon before the compiler creates the exe file? 回答1: You can set the icon of the generated exe by specifying it in the CompilerParameters that you pass to the code provider, using the CompilerOptions property. Dim parameters As New CompilerParameters() parameters.CompilerOptions = "/win32icon:C:\full\path\to\icon.ico" You then pass these parameters to the CompileAssemblyFromSource method. The

Create an .EXE from an .EXE

若如初见. 提交于 2019-12-08 18:54:31
So what I want to do is create an executable in a program in vb. What I mean by this is that there is a program that can output a .EXE. What I try to do is to create a program that can output a smaller program that runs predefined commands. All I know is that it is somehow possible with a STUB. That you open the STUB and add extra code to it and save it again as an .EXE. You can use compiler services to create EXE at run time. CSharpCodeProvider : Provides access to instances of the C# code generator and code compiler. Dynamic Creation of Assemblies/Apps System.CodeDom.Compiler 来源: https:/

Create an .EXE from an .EXE

落花浮王杯 提交于 2019-12-08 06:24:32
问题 So what I want to do is create an executable in a program in vb. What I mean by this is that there is a program that can output a .EXE. What I try to do is to create a program that can output a smaller program that runs predefined commands. All I know is that it is somehow possible with a STUB. That you open the STUB and add extra code to it and save it again as an .EXE. 回答1: You can use compiler services to create EXE at run time. CSharpCodeProvider : Provides access to instances of the C#

How to assign a custom icon for an application which is compiled from source file?

你离开我真会死。 提交于 2019-12-07 18:18:13
问题 In my program, I am using the CSharpCodeProvider in order to compile another application from a source file, the code i'am using is the below : public static bool CompileExecutable(String sourceName) { FileInfo sourceFile = new FileInfo(sourceName); CodeDomProvider provider = null; bool compileOk = false; // Select the code provider based on the input file extension. if (sourceFile.Extension.ToUpper(CultureInfo.InvariantCulture) == ".CS") provider = CodeDomProvider.CreateProvider("CSharp");