If you start with silverlight, I bet with you that you’ll get that anoying message in any case. But it has a reason why Microsoft doesn’t allow that.
It’s because Silverlight owns a very tiny implementation of the .NET framework in order to reduce the download size for the user. So it’s very likely that your project uses a method which is not supported by the .NET silverlight framework. But how can we get arround this irritating message? The question is easy, but although I’m working day by day with Visual Studio, I did not recognize the functionality until Davit Betz showed me that egg of Columbus.
First of all you have to create a silverlight project. In my case I named it like the project I wanted to use and added a “.Silverlight” at the end of the project name. (e.g. Utils.Silverlight). After that you create the folders as in your original project.
And now the magic: Add the files by clicking to “Add existing item” and use “Add Link” (instead of simply Add).

As a result the files will only be referenced by the new project, but not copied into the folder physically. With that feature, you can build your silverlight assembly without duplicating the sources. And I think you’ll wonder how many changes you need …
So remember, with every change here – you’ll probably break your original assembly there. In order to prevent breaking the code, you can use the precompiler. In every Silverlight Assembly the SILVERLIGHT Symbol is predefined.
So use, #if SILVERLIGHT … #endif to encapsulate the code that is only interessting for your silverlight application.
May the code be with you
- Gerhard
August 31, 2009 at 7:44 am
Hi Gerhard,
I tried your trick, now i dont get the annoying message but when i try to build the solution i am getting error for importing System.Data;
Microsoft.Practices.EnterpriseLibrary.Data;
and so on.
Regards
Subramanyam
August 31, 2009 at 9:08 am
Sure – that the result if you are using Features that are not available within a Silverlight application. What you can do is wrapping the code parts that aren’t useable in Silverlight with a #if !SILVERLIGHT … #endif statement.
Cheers
- Gerhard
September 1, 2009 at 6:21 pm
Thanks, Gerhard! That’s awesome and so simple!