views:

15

answers:

1

Hello all,

My web application (ASP.NET v3.5 / C#) dynamically creates other asp.net applications (creates aspx, aspx.cs, classes, web.config, project.csproj file etc.).

The thing is even after I configure the 'new' application folder as APPLICATION in the IIS, When I try to browse it, I get the following parser error: Could not load type 'Template48.Template48' (where Template48 is my application).

When I manually browse to the new application folder, and re-build it, all works perfect.

How can I re-compile this WHOLE application, but in it's folder ?

Thanks in advance,

Gal.

+1  A: 

A web application needs to be compiled before it works; this is different from a web site.

Just providing the sources isn't enough; in fact, ASP.NET doesn't need the sources (aspx.cs) to run the application, just the .aspx, web.config, and .dll files ("assemblies" in .NET lingo). It is even considered good practice to remove the sources from the production system to avoid accidentally leaking the sources and giving attackers information about the site's inner workings.

To make this work, you need to somehow invoke the command-line C# compiler to build the project on the fly; this will generate the needed .dll files.

A different, but much harder, route would be to use .NETs ability to emit IL at runtime; using this facility, you could produce assemblies directly without going through the compiler. This is pretty difficult though, and you need thorough understanding of the IL to pull this off.

tdammers
Thanks for the comment!In other code in my application, I do create assemblies by dynamic compilation, But the difference in this case, is that here I need to compile a WHOLE project. Is it possible? or should I iterate through all .cs files? Thanks.
Gal V
A quick google gives me a forum post as the first result, which leads to this intersting reading from Microsoft: http://msdn.microsoft.com/en-us/library/168k2ah5%28vs.71%29.aspx
tdammers