如何将特定版本的 System.XML (2.0.5.0) 添加到我的 .Net 4 项目中
我正在标准 .Net 4 WinForms 项目中为我的 Windows 7 手机游戏制作地图编辑器。
我已经编写了 XmlSerialise/Desearilise 方法 - 它们位于电话项目中 EntityCollection 类的 Load 和 Save 方法中。
Windows 7 Phone 使用2.0.5.0 版本的System.Xml、System.Xml.Linq 和System.Xml.Serialization。
我将这些 dll 复制到 libs 目录并尝试从我的 .Net 4 项目中引用它们 - System.Xml.Serialzation 如我所料引用 2.0.5.0,但需要 System.Xml dll - 当我从 Libs 目录引用它时它只是忽略了我对 .Net 4 的引用。
无论如何,我可以强制它引用 2.0.5.0 吗?
谢谢,
安迪
I'm making a map editor for my Windows 7 phone game just in a standard .Net 4 WinForms project.
I've already written the XmlSerialise/Desearilise methods - they live in Load and Save methods on an EntityCollection class within the phone project.
The Windows 7 Phone uses 2.0.5.0 version of System.Xml, System.Xml.Linq and System.Xml.Serialization.
I copied these dlls to a libs directory and tried to reference them from my .Net 4 project - the System.Xml.Serialzation references the 2.0.5.0 as I expected but demands the System.Xml dll - when I reference this from my Libs directory it just ignores me a references the .Net 4 one.
Is there anyway I can force it to reference the 2.0.5.0 one?
Thanks,
Andy
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
也许这里的选项是仅在两个项目(win forms 和 WP7)之间共享文件,只要编译器不抱怨
Maybe the option here would be to share only the file between two project (win forms and WP7) as long as the compiler doesn't complain
我知道如何引用特定二进制文件而不是让项目转到 GAC 获取 DLL 的唯一方法是在 .csproj 文件中提供 HintPath 以供参考。它看起来像这样:
您可能想要完全限定 System.Xml 的版本并将 SpecificVersion 设置为 True。您可以通过查看 Visual Studio 中“引用”文件夹中 System.Xml 引用的“属性”窗口中的“路径”值来验证是否正在引用 lib 文件夹中的特定 DLL。
The only way I know how to reference a specific binary instead of having the project go to the GAC for the DLL is to provide a HintPath in the .csproj file for the reference. It would look something like this:
You may want to fully qualify the version of System.Xml and set the SpecificVersion to True. You can verify that the specific DLL in your lib folder is being referenced by viewing the Path value in the Properties window of the System.Xml reference in the References folder in Visual Studio.
要引用程序集的这些特定版本,请转至每个引用的属性窗口,并将别名从全局更改为Silverlight强>。在引用这些程序集的类文件中,您可以添加每个类型的别名或别名 using 语句,如下所示:
这意味着任何时候您使用非限定类型
XDocument
(或任何其他类型别名)以同样的方式),它将使用具有匹配别名的程序集中的一个(即您的 WP7 特定的别名)。您还可以通过相应地限定类型来在代码中内联执行此操作,而无需添加 using 语句。例如
,根据您的情况,我认为别名命名空间 using 语句可能是您最好的选择。
To reference these specific versions of the assemblies go to the Properties window for each reference and change the Aliases from global to Silverlight. In your class files that reference these assemblies, you can then add per-type aliases or aliased using statements like the following:
This will mean that any time you use the unqualified type
XDocument
(or any other type aliased in the same way), it will use the one from the assembly with the matching alias (i.e. your WP7-specific one).You can also do this inline in your code without adding using statements by qualifying the type accordingly. E.g.
Under your circumstances, I think aliased namespace using statements are probably your best bet.