简体   繁体   English

将 Silverlight 类库更改为 wpf 类库

[英]changing silverlight class library to wpf class library

I currently have a library which was created in a silverlight application for its use.我目前有一个在 Silverlight 应用程序中创建的库以供使用。 But Now we are switching over to WPF.但是现在我们正在切换到 WPF。 So i don't know how would i convert the library to a wpf library.所以我不知道如何将库转换为 wpf 库。 Would i just have to copy all the file in a new project(wpf class library)我是否只需要复制新项目中的所有文件(wpf 类库)

在此处输入图片说明

As you can see when i reference this silver light library in my wpf project.正如你在我的 wpf 项目中引用这个银光库时所看到的。 It gives me a warning.它给了我一个警告。

As the message says, you can't use a project compiled to target Silverlight as a reference for a project targeting some other .NET framework family.正如消息所说,您不能将编译为以 Silverlight 为目标的项目用作以其他 .NET 框架系列为目标的项目的参考。 You will need to compile a separate assembly compatible with the .NET framework family you're using (ie a desktop version).您将需要编译与您正在使用的 .NET 框架系列(即桌面版本)兼容的单独程序集。 This will require the creation of a whole new project (I'm not aware of a practical way to have a single project target both Silverlight and desktop .NET).这将需要创建一个全新的项目(我不知道让单个项目同时面向 Silverlight 和桌面 .NET 的实用方法)。

Note that the new project can use the same source files as the original Silverlight one.请注意,新项目可以使用与原始 Silverlight 相同的源文件。 After creating the project (which you should create as an "Empty Project"), you can add the source files from the Silverlight project, by using the "Add Existing..."/"As Link" option for adding items to the project.创建项目(您应该将其创建为“空项目”)后,您可以添加来自 Silverlight 项目的源文件,方法是使用“添加现有...”/“作为链接”选项向项目添加项目. Adding the source code as links will cause the new project to reference the original .cs files in their current location rather than creating a new copy of them for the new project.添加源代码作为链接将导致新项目引用其当前位置的原始 .cs 文件,而不是为新项目创建它们的新副本。

Note also that your Silverlight code may or may not be 100% compatible with the WPF API.另请注意,您的 Silverlight 代码可能与 WPF API 100% 兼容,也可能不兼容。 You may have to introduce conditional compilation (ie use #if , and declare appropriate conditional compilation symbols, in the projects' settings "Build" tab) so that you can provide correct code for each platform in each .cs file.您可能必须引入条件编译(即使用#if并在项目的设置“构建”选项卡中声明适当的条件编译符号),以便您可以为每个 .cs 文件中的每个平台提供正确的代码。


Related topics (there a lot of duplicate questions involving adding existing items as links…though many of these involve multiple solutions, not just adding items to a new project):相关主题(有很多重复的问题涉及将现有项目添加为链接……尽管其中许多涉及多个解决方案,而不仅仅是将项目添加到新项目):

Share c# class source code between several projects在多个项目之间共享 c# 类源代码
How do I keep common code shared between projects in c#?如何在 C# 中的项目之间共享公共代码?
Adding Existing Files To Different Visual Studio 2010 Project将现有文件添加到不同的 Visual Studio 2010 项目
Is it possible to statically share code between projects in C#?是否可以在 C# 中的项目之间静态共享代码?
Updating classes used in multiple projects?更新在多个项目中使用的类?
Make reference to C# code from multiple projects从多个项目中引用 C# 代码
Share .cs file among VS 2010 C# projects在 VS 2010 C# 项目之间共享 .cs 文件
How to include source files of one project in another project?如何在另一个项目中包含一个项目的源文件?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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