简体   繁体   English

引用Silverlight类库

[英]Reference to a Silverlight Class Library

i'm building a Service-Client application using Silverlight and WCF, i have a Model project (which contains POCOs) on the Server side, and i wanted to share those same entities to the Silverlight-Client Application, and i thought, hey! 我正在使用Silverlight和WCF构建服务客户端应用程序,我在服务器端有一个Model项目(其中包含POCO),我想将这些实体共享给Silverlight-Client应用程序,我想,嘿! I can change the Model project to be a Silverlight class library, and it should work just fine. 我可以将Model项目更改为Silverlight类库,并且应该可以正常工作。

I did the change and now, i'm able to add the references however it is getting the exclamation mark like when the reference is not resolved... and if you take a look at the properties the value of "Resolved" is set to "False", this is causing the following Code Analysis Errors: 我进行了更改,现在,我可以添加引用,但是它却获得了感叹号,就像未解析引用时一样...并且如果您查看属性,则将“已解决”的值设置为“ False”,这导致以下代码分析错误:

CA0058 [CA0001][2] CA0058 [CA0001] [2]

Please note: this is not the typical question about referencing a Typical Class Library from a Silverlight project (i Know that can't be done), but the other way arround. 请注意:这不是关于从Silverlight项目中引用典型类库的典型问题(我知道这无法完成),而是相反的方法。

It should work fine (unlike what Wayne says, you can actually reference Silverlight assemblies from projects that target the full .NET Framework). 它应该可以正常工作(与Wayne所说的不同,您实际上可以从面向整个.NET Framework的项目中引用Silverlight程序集)。 However, you may have references in this project that the full .NET Framework can't load (you generally need to keep your references to the most base types). 但是,您可能在此项目中具有无法加载完整.NET Framework的引用(通常需要保留对大多数基本类型的引用)。 You've got two alternative options. 您有两种选择。

  1. Create two class library projects (one targeting Silverlight, the other the .NET Framework), and share the files between them, as I discuss in this article: http://www.silverlightshow.net/items/Building-a-Silverlight-Line-Of-Business-Application-Part-3.aspx 创建两个类库项目(一个针对Silverlight,另一个针对.NET Framework),并在它们之间共享文件,正如我在本文中所讨论的: http : //www.silverlightshow.net/items/Building-a-Silverlight-业务线应用程序部分-3.aspx

  2. Try out the Portable Library Tools (currently in beta): http://blogs.msdn.com/b/sburke/archive/2011/01/23/3-screen-coding-is-here-portable-library-tools-allow-you-to-target-multiple-net-platforms-with-one-binary.aspx 试用可移植库工具(当前处于测试版): http : //blogs.msdn.com/b/sburke/archive/2011/01/23/3-screen-coding-is-here-portable-library-tools-允许您使用一个binary.aspx来定位多个网络平台

Hope this helps... 希望这可以帮助...

Chris Anderson 克里斯·安德森

出于相同的原因,您不能引用Silverlight项目中的CLR程序集,也不能引用CLR项目中的Silverlight程序集-它们是不同的运行时。

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

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