你能拆分一个视觉工作室项目(c#)并参考它吗?

时间:2023-01-16 15:48:25

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.

我有两个引用SQLite的项目。 1表示Windows,1表示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.

现在我需要为每个平台创建一个类库,并为每个平台引用正确的SQLite项目。理想情况下,我想在一个地方创建我的代码,然后在每个项目中引用它。问题是我的代码使用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.

我只想到我可能,因为如果我使用cordova创建一个Windows应用程序,它会以某种方式创建3个项目,1个用于Windows,1个用于电话,另一个用于共享资源。

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

这是我想要的东西

SQLite - Windows SQLite - Phone

SQLite - Windows SQLite - 电话

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

库 - Windows(引用SQLite Windows)库 - 电话(引用SQLite电话)库 - 共享(两个库项目都可以使用的共享代码)

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

Cordova - Windows(参考图书馆Windows)Cordova - 电话(参考图书馆电话)Cordova - 共享(两个cordova项目可以使用的共享资源)

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

这都是因为SQLite无法在WIndows和Phone上运行,因此每个都需要一个单独的项目

3 个解决方案

#1


2  

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

这是一个旧的Silverlight技巧,可以在两个项目或两个不同版本的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:

在项目1中创建代码。然后对于项目2,通过从项目1链接它们来添加文件。要执行这种类型的添加链接,这是一个过程:

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. 在第二个项目中右键单击并选择Add then Existing Item ...或shift alt A.
  3. Browse to the location of the file(s) found in the first project and select the file(s).
  4. 浏览到第一个项目中找到的文件的位置,然后选择文件。
  5. Once the file(s) have been selected, then on the Add button select the drop down arrow.
  6. 选择文件后,在“添加”按钮上选择下拉箭头。
  7. Select Add as link to add the common files(s) as a link into the project.

    选择添加为链接以将公共文件添加为项目的链接。

    你能拆分一个视觉工作室项目(c#)并参考它吗?

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

这将提供对文件的访问,就好像文件实际上在项目中,但文件实际驻留在其他地方。

#2


2  

If you put the code you want shared into its own project, you can then reference that in your other two projects (Windows and Cordova).

如果将要共享的代码放入其自己的项目中,则可以在其他两个项目(Windows和Cordova)中引用该代码。

This will allow you to only write the code that they share once, while keeping the platform specific code separate.

这将允许您只编写一次共享的代码,同时保持平台特定的代码分开。

You can put them all in one solution in Visual Studio, to help keep everything together. This also lets you easily reference the shared project.

您可以将它们全部放在Visual Studio中的一个解决方案中,以帮助将所有内容保持在一起。这也可以让您轻松引用共享项目。

#3


0  

You can: 1. create a base shared library referenced by the two projects (Windows and Windows Phone). 2. create two other libraries (that extends the base library) compiled for the specific platform. 3. on runtime you can load by reflection the right library you need on each project

您可以:1。创建由两个项目(Windows和Windows Phone)引用的基本共享库。 2.创建为特定平台编译的另外两个库(扩展基础库)。 3.在运行时,您可以通过反射加载每个项目所需的正确库

#1


2  

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

这是一个旧的Silverlight技巧,可以在两个项目或两个不同版本的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:

在项目1中创建代码。然后对于项目2,通过从项目1链接它们来添加文件。要执行这种类型的添加链接,这是一个过程:

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. 在第二个项目中右键单击并选择Add then Existing Item ...或shift alt A.
  3. Browse to the location of the file(s) found in the first project and select the file(s).
  4. 浏览到第一个项目中找到的文件的位置,然后选择文件。
  5. Once the file(s) have been selected, then on the Add button select the drop down arrow.
  6. 选择文件后,在“添加”按钮上选择下拉箭头。
  7. Select Add as link to add the common files(s) as a link into the project.

    选择添加为链接以将公共文件添加为项目的链接。

    你能拆分一个视觉工作室项目(c#)并参考它吗?

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

这将提供对文件的访问,就好像文件实际上在项目中,但文件实际驻留在其他地方。

#2


2  

If you put the code you want shared into its own project, you can then reference that in your other two projects (Windows and Cordova).

如果将要共享的代码放入其自己的项目中,则可以在其他两个项目(Windows和Cordova)中引用该代码。

This will allow you to only write the code that they share once, while keeping the platform specific code separate.

这将允许您只编写一次共享的代码,同时保持平台特定的代码分开。

You can put them all in one solution in Visual Studio, to help keep everything together. This also lets you easily reference the shared project.

您可以将它们全部放在Visual Studio中的一个解决方案中,以帮助将所有内容保持在一起。这也可以让您轻松引用共享项目。

#3


0  

You can: 1. create a base shared library referenced by the two projects (Windows and Windows Phone). 2. create two other libraries (that extends the base library) compiled for the specific platform. 3. on runtime you can load by reflection the right library you need on each project

您可以:1。创建由两个项目(Windows和Windows Phone)引用的基本共享库。 2.创建为特定平台编译的另外两个库(扩展基础库)。 3.在运行时,您可以通过反射加载每个项目所需的正确库