本文介绍了在一个项目中编译 Silverlight 和 WPF 的最佳实践是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚完成了一个 Silverlight 项目,是时候进行一些清理工作了.我想将我的核心文件放入一个单独的项目中,我将从我的主要 Silverlight 应用程序中引用该项目.其中一些类与 WPF 兼容,我非常希望能够在一个项目中包含所有 Silverlight/WPF 代码.我的理想解决方案是允许多个配置的单个项目.所以,

I've just completed a Silverlight project and it's time to have a little clean up. I'd like to take my core files and put them into a separate project which I will reference from my main Silverlight app.Some of these classes are compatible with WPF and I would quite like to be able to have Silverlight / WPF code all in one project. My ideal solution would be a single project that allows multiple configurations. So,

配置:Silverlight 将生成:Company.Controls.Silverlight.dll

Configuration: Silverlight would generate:Company.Controls.Silverlight.dll

配置:WPF 将生成:Company.Controls.Wpf.dll

Configuration: WPF would generate:Company.Controls.Wpf.dll

是否可以在同一个文件中使用相同的源代码,只是通过定义分开?

Is it possible to have the same source in the same file just seperated via defines?

以前有人这样做过吗?

我为每个项目创建了一个解决方案,例如 MyCompany.Windows.Controls,然后包含 2 个项目,MyCompany.Windows.Controls &MyCompany.Windows.Controls.Silverlight.除了这两个文件夹,我还有一个共享"文件夹,其中包含两个项目使用的文件.到目前为止效果很好:)

I've created a solution per project, like MyCompany.Windows.Controls, which then contains 2 projects, MyCompany.Windows.Controls & MyCompany.Windows.Controls.Silverlight. Alongside those 2 folders I have a "Shared" folder, which contains files used by both projects. It works well so far :)

推荐答案

我自己还没试过(还在找时间玩Silverlight),但是你不能有两个项目的一个解决方案,一个以 Silverlight 为目标,另一个以 .NET 3.5 为目标,并将公共类文件作为链接添加到每个项目中(右键单击项目,添加现有项目...,添加为链接)?

I haven't tried it myself (still trying to find the time to play with Silverlight), but couldn't you have one solution with two projects, one targetting Silverlight and the other targetting .NET 3.5, and add the common class files to each project as Links (right-click the project, Add Existing Item..., Add as Link)?

** 更新:请参阅下面关于项目链接器的 Mark 回答.我一直在使用 PRISM 2.0 CAL 在我的多目标复合应用程序中使用它,这是一件美妙的事情.我不认为这在 PRISM 1.0 中存在?

** Update: See Mark's answer below regarding the Project Linker. I've been using this in my multi-targetted composite application with the PRISM 2.0 CAL and it's a beautiful thing. I don't think this existed in PRISM 1.0?

这篇关于在一个项目中编译 Silverlight 和 WPF 的最佳实践是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 16:05