Search code examples
c#.netvisual-studiovisual-studio-2013

Can you split a visual studio project (c#) and reference it?


Not sure how to explain it but here goes.

I have 2 projects that reference SQLite. 1 is for Windows and 1 is for Windows Phone.

Now i need to create a class library for each platform, and reference the correct SQLite project for each. Ideally i would like to create my code in one place and then reference it in each project. Problem is my code uses SQLite.

I do not really want to have a separate copy in each project for each platform.

Can i do what i want, or not possible?

I only thought i maybe able to because if i create a windows application using cordova, it somehow creates 3 projects, 1 for windows, 1 for phone and the other has its shared resources in.

Here is a the sort of thing of what i would like

SQLite - Windows SQLite - Phone

Library - Windows (references SQLite Windows) Library - Phone (references SQLite Phone) Library - Shared (shared code that both library projects can use)

Cordova - Windows (references Library Windows) Cordova - Phone (references Library Phone) Cordova - Shared (shared resources that both cordova projects can use)

This is all because the SQLite cannot run on both WIndows and Phone, so need a separate project for each


Solution

  • Use file linking in the project.


    This is an old Silverlight trick to share one set of code between two projects or two different versions of the CLR.

    Create the code in project 1. Then for project 2, add the files by linking them from project 1. To do that type of add link this is the process:

    The trick is to include as a link into the project. Here is how

    1. In the second project right click and select Add then Existing Item... or shift alt A.
    2. Browse to the location of the file(s) found in the first project and select the file(s).
    3. Once the file(s) have been selected, then on the Add button select the drop down arrow.
    4. Select Add as link to add the common files(s) as a link into the project.

      enter image description here

    That will give access to the file as if the file was actually within the project, but the file physically resides elsewhere.