Search code examples
.netsilverlightvisual-studio-2010compilation

Cross compile for .NET 4 and Silverlight 4 in VS2010 without duplicating files


We have a large number of projects within a solution mostly simple class libraries (which are later loaded through MEF) targetting .NET 4.0.

We would like to compile a large number of these for both .NET 4.0 and the Silverlight runtime without duplicating files.

Is there a way to create a new Silverlight class library and link the source files from the other projects so both the .NET 4.0 library and the Silverlight 4.0 library will be compiled?

I'm aware .NET 4.0 can load silverlight 4 assemblies, but I would like to compile both versions anyway instead of compiling everything for Silverlight.

Update: I saw a solution once where some of the projects contained links to other files in other projects, so when you changed a file in one project it would be updated in the other one as well. This is what I mean.

alt text

A screenshot of the solution, the Vialis.Led.Interfaces project contains the original files, in the silverlight project I want to create links to these files.


Solution

  • Just setup a second project for Silverlight, and then use Project->Add Existing Files... to add each of the project files into the Silverlight project.

    You can also use partial classes to separate out Silverlight-specific or .NET framework specific functionality. (This is the approach used by Prism, btw.)