R – Embedding a XAP file into a class library

class-librarysilverlightvisual studio

This might be a bit tricky setup but…

I have this Silverlight project that builds into a XAP, which is all fine.

Next we have this set of class libraries we add to an existing application which then unfolds into small "applications" inside the existing one.

The problem here is…

I want my XAP to be embedded into the class library as an embedded resource, but I'm looking for a solution how to do this without some half-dodgy post-build event if possible. It would be fantastic to be able to link the output of my Silverlight project to the class library and get it embedded…I guess I'm starting to ramble a bit now 😉

Short version: link Silverlight project to a Class library project as an embedded resource…is it possible, if so how?

Best Answer

In the required spot in the solution explorer of your class library, right click, "Add-> Existing Item", then in the file browser that pops up change the file filter to "All", browse to the ClientBin folder of your web project (or the Bin folder of your Silverlight project), select the xap file, but don't just click 'Add', instead click on the down arrow on the button and click 'Add as link'. Then go to the properties of the newly added xap file, and change its Build Action to Embedded Resource.

No dodgy post build events required :)

Related Topic