1

I am using Asp.Net 5 CTP6. I need to execute some c# code at runtime. I know there is some solution and I used some of them but I want to know how can I do this by Roslyn because of platform independency? By the old solution that I found may be exists some problems about multi platform independency. In fact I want to run the web app on windows and Ubuntu. Thanks

agua from mars
  • 16,428
  • 4
  • 61
  • 70
Mohsen Mirshahreza
  • 155
  • 1
  • 1
  • 10

2 Answers2

0

Please see the following code :

 string s = @"
using .....
string a=""this is a test :)""

";

SomeMethodToRunTheCode(s); In asp.net webform I can attach the code to an .ascx (at runtime I create a file with .ascx extension and I append the code to the file ) file then with LoadControl method I will be able to run the codes at runtime. but in the asp.net 5 ( vNext ) I do not know how can I do this.

Mohsen Mirshahreza
  • 155
  • 1
  • 1
  • 10
  • Do not aswer to your question, edit your question instead. Thus, if you do that, you application pool will be recycled each time you create a new .ascx file – agua from mars Mar 17 '15 at 10:48
  • Ok. I will edit my question at the next case. And about the application pool you are right, Yes I know !!! but I need a good solution in asp.net 5. Do you have a suggestion. – Mohsen Mirshahreza Mar 17 '15 at 11:00
  • You can create a .cs file, it will be compile at runtime by roslyn but that will going to recycle your application pool too. – agua from mars Mar 17 '15 at 13:09
0

Take a look at how razor does it https://github.com/aspnet/Mvc/blob/dev/src/Microsoft.AspNet.Mvc.Razor/Compilation/RoslynCompilationService.cs

davidfowl
  • 37,120
  • 7
  • 93
  • 103