CodeDom and Silverlight
Asked Answered
W

1

9

Can Silverlight apps (the .xap file, the testpage.html, content resources along side a ClientBin, out of browser settings, etc) be created using only System.CodeDom from a regular .NET app? Meaning I have a console or winforms app that creates Silverlight apps - is this possible with System.Codedom?

I have searched high and low and haven't found any information on this.

Woe answered 18/10, 2010 at 23:49 Comment(9)
Wow, that's a pretty interesting question. Have you tried anything yourself? I can't think of a reason why it wouldn't be possible, but I don't know for sure. I guess one important thing is to make sure that the generated assembly references the correct versions of the Silverlight platform assemblies (mscorlib, System.Windows, etc.) and not their desktop counterparts. A Silverlight application is nothing more than a collection of assemblies and an AppManifest.xaml file in a zip file with a .xap extension. I am curious as to what is the scenario that leads you to want to do this?Acrobat
Thanks Keith. I've been looking at MSBuild for the same option, but people seem to suggest that MSBuild is overkill and CodeDom.Compiler is enough for regular situations - I just don't know if that is the case for Silverlight. A scenario would be an eGreeting card creator where there is heavy customization (I know this could have a different approach, but for the sake of arguement, let's just say that this is the way it needs to be) - a core ASP.NET website that takes a bunch of different parameters from user input and the result is a compiled Silverlight app. Do this many times.Woe
For your scenario, I would suggest you take an alternative approach, e.g. a generic Silverlight app that downloads all the customization data dynamically at runtime. If you do decide to go the code generation route: I wish I could give you a better answer than "there is no obvious reason why it shouldn't work".Acrobat
Thanks Keith. I hear ya on the other approach, unfortunately it's not an option in this case.Woe
To get a little bit more context, could you explain why this is not an option in your case?Menedez
Hi there! Recently faced just the same task. Could you please tell me if you succeeded when using CodeDom? Or maybe you have created some custom builder?Busiek
@LexRema: Yes, I eventually worked it out. I used CodeDom to create all the codebehind and Linq-to-XML to create the XAML files. Most importantly I used Linq to create the .csproj/.vbproj file and then used MSBuild to complete the task. It took a while to figure it all out, but it was worth it.Woe
@Stan, thanks, but I'm going to accomplish that in a bit other way:Busiek
Use a sample project. Add placeholders to that project files. Process the placeholders with own macros replacement to get generated solution. But thank you very much for your quick and comprehensive answer!Busiek
M
4

Although this will be a challenge, it should probably be possible. If you look at what the framework itself does, there are a few options though.

  • For example, the Regex class uses System.Reflection.Emit to compile your regulare expressions;

  • XmlSerializer uses System.CodeDom to generate assemblies for serializing and deserializing XML;

  • ASP.Net calls the C# compiler (csc.exe) to compile ASPX pages (and all other parts of the ASP.Net application) into an assembly.

These are all options to create a valid assembly, ordered from very complex, to relatively doable.

And concerning your Silverlight part of the question. This should simply be a case of creating a valid project. Probably the easiest way to go is to create the simplest Silverlight project you can think of (so, without any content) and try to emulate that with one of the three options. If you've got that running, than gradually add parts until you've got what you need.

Menedez answered 30/10, 2010 at 6:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.