12

假设我已经有一个构建 .NET 3.5 程序集的项目。现在我想为 Silverlight 构建这个程序集,此外,以最小的努力维护其 Silverlight 版本。

什么是不可接受的:

  • 为 Silverlight 构建创建单独的项目

什么是可以接受的:

  • 添加自定义指令允许我根据 MSBuild 属性来定位 Silverlight 或 .NET。
  • 为 Silverlight 添加特殊构建配置
  • 将#ifdef Silverlight / #endif 部分添加到源代码中。
  • 通常对 .csproj / .cs 进行任何其他修改。

所以基本上,我想维护一个项目,但针对两个框架。我不想维护两个单独的项目,因为这可能会导致错误,例如忘记包含新文件。如果有很多项目和大团队,排除此类错误非常重要。

如果这完全不可能,那么任何提供类似好处的解决方案都是可以接受的。

4

5 回答 5

8

您是否还排除了从 Silverlight 项目链接到项目中的文件的可能性?这是在 Silverlight 和完整 CLR 之间共享实现的一种相当常见的方法。在 .NET 和 Silverlight 平台之间共享代码

此外,根据 Justin Angel 的说法,您可以参考和使用完整 CLR 中的 Silverlight 类库。我自己没有尝试过,它留下了一些未解决的问题,但它确实使场景变得简单:http ://silverlight.net/blogs/justinangel/archive/2008/12/29/using-silverlight-dlls-on -the-desktop.aspx

于 2009-07-03T18:45:24.850 回答
1

我同意斯科特的观点。为自己省去很多痛苦。共享相同代码库的两个项目是要走的路。你需要它在两种环境中使用 VStudio,使用不同的库,包含/排除文件,做很多事情......轻松!

拥有两个项目的原因远远超过拥有一个项目的借口。

于 2009-07-03T18:40:56.617 回答
1

The MSDN contains detailed information about platform Multi-targeting: Multi-targeting on MSDN

于 2010-06-16T15:44:51.013 回答
0

您必须有两个项目,因为这两个平台的 mscorlib 引用不同。

看看这个问题:http ://www.google.ca/search?hl=en&q=targetting+silverlight+and+wpf&meta=&aq=f&oq=

如果您只想拥有一个在两者之间共享的常规旧 .NET 库,那么我建议创建两个项目(一个用于 Silverlight,一个用于常规)并在两个项目中包含相同的文件。这对于其他开发人员来说更容易理解。

于 2009-07-03T18:22:38.373 回答
0

I think what you need to do is tier this out properly. Your Silverlight code should be only for the UI and the communication with backend WCF services. Those services would run your .NET 3.5 code (the code that you want to share). That way you have sharing and n-tier as well.

If you're doing heavy calculation on the client-side in your Silverlight code and then submitting that to the server (and probably the db) then I think you're opening up a security hole.

You haven't given a compelling reason why a separate project would need to access code in the Silverlight project.

于 2009-07-03T19:35:52.297 回答