I am using CSharpCompilation.Create
to create assembly from scratch. The thing I got to know is this always creates a new assembly. Is there anyway to add/modify the existing DLL in Roslyn? This is because I am building a tool where a user can type C# code in richtextbox and compile it to add it to the existing assembly. Is it possible, if not what I am doing wrong and what is the right way?
P.S.,
I have also tried CSharpCodeProvider
as well to compile the code, but it is also Generating assembly with only the code I typed in richtextbox. The output assembly did not have other classes in that.
Yes as mentioned in comment by Klauss Gutter, you have to build the assembly individually and merge it later using ILMerge. I know ILMerge is out of support and is deprecated. You can use ILRepack to do this. It provides the same functionality as ILMerge.
You can use NuGet Package to install ILRepack first and then add reference to the ILRepack.exe to your project to use its methods to pack multiple assemblies in to one.
Roslyn or CSharpProvider wont help you to merge your assemblies. The main motto of these are to compile and create an assembly not merge.