locked
How to share code between Server project and silverlight client. RRS feed

  • Question

  • When you use preview 2, there is no longer a common project which was used to share code between client and server. (it was basically a silverlight assembly).

    The UserCode folder in the server project contains now a shared sub directory. Apparently, when you add e.g. validation logic, the class is linked into the silverlight client folder \UserCode\Shared.

    I applied this approach in the SignalR example I provided on my blog: http://blog.pragmaswitch.com/?p=589.

    Just wondering if the product team has foreseen some magic to do this automatically (as it is done when for the classes manged by LightSwitch).


    paul van bladel

    Sunday, November 18, 2012 7:43 AM

Answers

  • Just wondering if the product team has foreseen some magic to do this automatically (as it is done when for the classes manged by LightSwitch).

    Not sure if there is much "magic" that could be done to do this. Developers could want to write code that is incorporated into both the server and Silverlight client assemblies, code only for the server assembly, or code for only the Silverlight client assembly. There is no way of determining what the intention of the use of the code file would be by LightSwitch without creating some new entry point for adding code files.

    What you'll have to do is add the code file to one of the projects and then link it into the other project.


    Justin Anderson, LightSwitch Development Team

    Monday, November 19, 2012 7:03 AM
    Moderator

All replies

  • Just wondering if the product team has foreseen some magic to do this automatically (as it is done when for the classes manged by LightSwitch).

    Not sure if there is much "magic" that could be done to do this. Developers could want to write code that is incorporated into both the server and Silverlight client assemblies, code only for the server assembly, or code for only the Silverlight client assembly. There is no way of determining what the intention of the use of the code file would be by LightSwitch without creating some new entry point for adding code files.

    What you'll have to do is add the code file to one of the projects and then link it into the other project.


    Justin Anderson, LightSwitch Development Team

    Monday, November 19, 2012 7:03 AM
    Moderator
  • Justin,

    Sure.

    But I remember there was in RIA services a mechanism that did this kind of copy based on a convention (I think it was when you ended the filename with .shared).

    I can live very much with how it works now :)


    paul van bladel

    Monday, November 19, 2012 9:01 AM
  • I'm back working on a big LS Silverlight client and have installed the HTML Preview 2 to make sure that I use the new LS project structure as I do a fair amount of non-standard LS stuff and don't want to find myself running into upgrade issues later on when version 3 actually ships.

    I think upgrading to the HTML preview 2 (and then upgrading your LS project) might be a good idea for anyone starting on a big Silverlight app as well?

    I must say I'm quite impressed with the new project structure and very glad I did the upgrade. My project upgraded mostly without any issues, but I did have to fix/add back in some of the custom classes I had in my previous Common project. I can see where the team is going with the new layout and it makes a lot of sense.

    Something to pay attention to when adding shared code into the server project and then link-sharing it with the client project and getting compile error, is to look closely at where you are getting the compile error: client or server. I mucked around for a good while with the server project, trying to get the compile error fixed, only to realise later that it was actually a client compile error and needed another reference added to the client project. Anyway, I won't be caught with that one again :D

    I also had some embedded image resources in the client project that were read as binary computed properties on one entity to display those images in a grid. This has stopped working now and I still need to figure out why that is not working any more. Not a big deal I would think though.

    Now that we can add the HTML client as well it would be great to be able to add multiple Silverlight clients and multiple HTML clients in the same LS project. This would be a step towards creating a number of UI modules.

    Overall I am quite excited about the new version and cannot wait to dig more into the HTML client.


    Xander

    • Edited by novascape Monday, November 19, 2012 9:49 PM
    Monday, November 19, 2012 9:48 PM