You can only add project references to other Silverlight projects in the solution.

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

kick it on

4 Responses to “You can only add project references to other Silverlight projects in the solution.”

  1. Subramanyam Says:

    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;
    and so on.


    • Gerhard Says:

      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.

      – Gerhard

  2. Amy Grossman Says:

    Thanks, Gerhard! That’s awesome and so simple! :)

  3. lnardozi Says:

    Works awesome!

    Just used it. Remember, the functionality you’re getting ready to comment out might exist in a using clause with a different name!
    Also, the using might be unnecessary in BOTH projects!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Get every new post delivered to your Inbox.

Join 108 other followers

%d bloggers like this: