简体   繁体   English

如何在visual studio中的不同类型的项目之间共享代码?

[英]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.

相关问题 如何在Visual Studio中的项目之间共享资源文件? - How can I share a resource file between projects in Visual Studio? .NET(Visual Studio)在项目之间共享资产 - .NET (Visual Studio) Share assets between projects 如何在多个Visual Studio项目之间共享属性? (特别是C#项目) - How to share properties between multiple Visual Studio projects? (especially C# projects) Visual Studio:如何管理项目之间共享的代码 - Visual Studio : How to manage code shared between projects 使用Visual Studio 2010和Subversion共享包含2个不同项目的CS文件 - Share a CS file with 2 different projects using Visual Studio 2010 and Subversion 如何在项目之间共享代码和资源 - How to share code and resources between projects 如何在Visual Studio 2012中跨多个项目共享CSS文件? - How to share CSS file across multiple projects in Visual Studio 2012? 如何在不同的解决方案之间共享相同的 Visual Studio 项目? 不同的 app.config 和 settings.settings - How to share same Visual Studio project between different solutions? Different app.config and setttings.settings 如何在不同项目之间共享 wsdl 和 xsd 文件? - How to share wsdl and xsd files between different projects? Visual Studio:在ASP和C#项目之间共享代码 - Visual Studio: Share Code between ASP and C# project
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM