简体   繁体   中英

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. 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.

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.

You need to create a " Portable class Library " project and put your common code in there. it will create a 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. 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. - MSDN

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM