Questions tagged [csharpcodeprovider]

.NET class that provides access to the C# compiler for compiling code.

CSharpCodeProvider can be used by applications to compile C# source code from in-memory strings or from files on disk, producing in-memory compiled assemblies or DLL files on disk.

153 questions
3
votes
1 answer

compile code at run-time and use assemblies loaded on memory

I need to compile C# code at run-time. I'm using the code like this: CSharpCodeProvider provider = new CSharpCodeProvider(); CompilerParameters parameters = new CompilerParameters(); parameters.ReferencedAssemblies.Add("MyLibrary.dll"); // File…
Ali Sepehri.Kh
  • 2,468
  • 2
  • 18
  • 27
3
votes
1 answer

Is there any code provider for C++ in Visual Studio 2012

I used below codes as code provider for C# and VB.net var codeProvider = new VBCodeProvider(); var codeProvider = new CSharpCodeProvider(); Like that, Is there any code provider available for C++ in visual studio 2012
Balaji Kondalrayal
  • 1,743
  • 3
  • 19
  • 38
3
votes
1 answer

Resx files and embedding into assembly

I have a T4 template which generates a DbContext and a migration configuration. During runtime, I use that template to create an assembly, then use that assembly to generate a migration. However, when I want to do an update database, still…
3
votes
1 answer

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

Typical code samples using CSharpCodeProvider pass CompilerVersion parameter. Code from here: var codeProvider = new CSharpCodeProvider( new Dictionary { { "CompilerVersion", "v3.5" } }); I've tried to pass an empty…
sharptooth
  • 167,383
  • 100
  • 513
  • 979
3
votes
1 answer

Outputting C# aliases (int, etc) instead of CLR types (Int32, etc) using CodeDom / CSharpCodeProvider

When generating C# code using CodeDom / CSharpCodeProvider, is it possible to force the output to use C# aliases instead of CLR types where possible? I am currently parsing the resulting C# code and replacing CLR types with their aliases, but I…
Marc Newlin
  • 63
  • 1
  • 3
3
votes
2 answers

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

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…
Rafik Bari
  • 4,867
  • 18
  • 73
  • 123
2
votes
2 answers

Can an application compile and create another application?

Possible Duplicate: How to programatically build and compile another c# project from the current project Lets say we have an application named Program1.exe so when i click that exe that program has to create another exe lets say Program2.exe…
Mustafa Ekici
  • 7,263
  • 9
  • 55
  • 75
2
votes
1 answer

LanguageVersion does not contain a definition for C# 9 after clearing NuGet caches

Creating ASP.NET Core 6 MVC application with EF Core and Npgsql in Visual Studio 2022. After clicking "Clear All NuGet Cache(s)" button in Visual Studio > Tools Options > NuGet Package Manager > General property…
Andrus
  • 26,339
  • 60
  • 204
  • 378
2
votes
1 answer

Choose references dynamically in .net core for Roslyn

TL;DR How do I let the runtime choose the right assemblies in .NET Core 5 for C# plugins compiled at runtime that involve .NET 4.7.2 code? Context I have a .NET 4.7.2 app on which certain modules behave differently based on some configurable…
PedroC88
  • 3,708
  • 7
  • 43
  • 77
2
votes
1 answer

Can't include Newtonsoft JSON in CSharpCodeProvider script

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…
runfastman
  • 927
  • 2
  • 11
  • 31
2
votes
0 answers

Compiling C# Code in UWP

I have using the built in CSharpCodeProvider class in previous C# .NET projects and it has worked great. I see this has been removed in UWP. I've been banging my head against the wall trying to figure out if there is a way. I can't seem to find any…
Kyle
  • 2,339
  • 10
  • 33
  • 67
2
votes
1 answer

C# Code compiled .exe doesn't run

I am using the CSharpCodeProvider in order to compile an .exe myself with variable parameters. Compiling works fine (doesn't return errors) and succeeds but when running it starts and instantly quits w/o any error or output. When changing the "Main"…
ThexBasic
  • 715
  • 1
  • 6
  • 24
2
votes
4 answers

C# Library Management console program

In this code when I add 2 books and try to delete 1st and 2nd book, 1st gets deleted and 2nd one didn't. In next case when I add 3 books and delete one by one 1 gets deleted and 2 not and 3rd one becomes missing when I delete 2. When I add 4 books 2…
2
votes
0 answers

Redistribution of Reference Assemblies

We have an application that generates and compiles code on the fly using CSharpCodeProvider. The code that gets compiled uses Entityframework, so we pass a reference to Entityframework.dll to the compiler. The Entityframework.dll, which we…
2
votes
1 answer

Create property in runtime and pass value

I found example with runtime function creating. public static MethodInfo CreateFunction(string function) { string code = @" using System; namespace UserFunctions { public class…
A191919
  • 3,422
  • 7
  • 49
  • 93
1
2
3
10 11