[英]How to share code between projects of different types in visual studio?
I know there is someone who has post some questions like this. 我知道有人发布过这样的问题。 But my problem is a little different.
但我的问题有点不同。
My program has two versions, one is for PC and the other one is for Windows Phone. 我的程序有两个版本,一个用于PC,另一个用于Windows Phone。 In my case, they both use a same algorithm.
在我的例子中,他们都使用相同的算法。 I want to share the codes between two projects.
我想在两个项目之间共享代码。
First, I tried to create a project containing these codes, then add them to my projects as a reference. 首先,我尝试创建一个包含这些代码的项目,然后将它们作为参考添加到我的项目中。 But here is the problem, if i create a Windows Form Application project, I can't reference it in a WP project, and vice versa.
但问题是,如果我创建一个Windows窗体应用程序项目,我不能在WP项目中引用它,反之亦然。
Second, I tried to add these codes to my projects as a link. 其次,我尝试将这些代码作为链接添加到我的项目中。 But I have lots of files to share, I don't want add them one by one.
但我有很多文件要分享,我不想一个一个地添加它们。 And these shared files will mass my project directory.
这些共享文件将成为我的项目目录。
What should I do? 我该怎么办?
sounds to me like you need to make a Class Library project. 听起来像你需要制作一个类库项目。 Create that and you can put in whatever code you want, then compile it to a dll, and reference it in any of your other projects.
创建它,您可以输入您想要的任何代码,然后将其编译为dll,并在任何其他项目中引用它。
You need to create a " Portable class Library " project and put your common code in there. 您需要创建一个“ 可移植类库 ”项目并将您的公共代码放在那里。 it will create a dll.
它会创建一个DLL。 Reference it in other projects and it will work fine.
在其他项目中引用它,它将正常工作。
Using the Portable Class Library project, you can build portable assemblies that work without modification on the .NET Framework, Silverlight, Windows Phone 7, or Xbox 360 platforms.
使用可移植类库项目,您可以构建可在.NET Framework,Silverlight,Windows Phone 7或Xbox 360平台上无需修改的便携式程序集。 Without the Portable Class Library project, you must target a single platform and then manually rework the class library for other platforms.
如果没有可移植类库项目,则必须以单个平台为目标,然后手动为其他平台重做类库。 The Portable Class Library project supports a subset of assemblies from these platforms, and provides a Visual Studio template that makes it possible to build assemblies that run without modification on these platforms.
可移植类库项目支持来自这些平台的程序集子集,并提供了一个Visual Studio模板,可以构建在这些平台上无需修改即可运行的程序集。 - MSDN
- MSDN
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.