views:

158

answers:

1

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?

+1  A: 

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 :)

slugster
Won't that completly fail if I do a "clean" or "rebuild" step?
cyberzed
Besides that I assume it won't handle debug/release building very well either.
cyberzed
I haven't tried this but it sounds like it would work. ClientBin gets the XAP regardless of whether a debug or release build is being done so that should eliminate that worry. A build after a clean (or a rebuild) should work as long as the XAP appears before the class library in the build order.
AnthonyWJones
Well I don't really have a ClientBin since it's being included into a Class Library ;)
cyberzed
Yes, you would have to ensure that the build order of your projects was correct, but that is a consideration no matter what method you try. Your other option is to go back to using post build events, which is what i would have used to begin with (they are only as dodgy as you make them). As you said, you have an unusual setup, so the steps you take to accomplish it may be slightly unusual as well - nothing wrong with that as long as it is solid.
slugster
It's just the way it is...I'll take a look at the setup and flip the ideas with the other developers here :) It's our first Silverlight "component" so I was curious how others are doing it...guess I might go for the post-build action for less fuzz when we build a release version.
cyberzed
Instead of browsing to the ClientBin folder browse to the bin\debug och the silverlight project. That and remove the silverlight app from the website properties and your good to go
Marcus