如何写一个类库,将在.NET 3.5中紧凑的框架和规则的框架?框架、将在、紧凑、类库

2023-09-04 02:09:01 作者:不如归去

我怎样写一个.NET类库,我可以重新编译无论是常规的.NET 3.5框架,或.NET 3.5框架精简?

How do I write a .NET class library that I can recompile for either the regular .NET 3.5 Framework, or the .NET 3.5 Compact Framework?

推荐答案

这两个框架是不是二进制兼容的*,很不幸,但不要让这些阻止你。

The two frameworks aren't binary compatible*, unfortunately, but don't let that stop you.

在解决方案中创建两个项目(一个正常的类库项目,和一个精简框架类库项目),并从一个项目添加的所有文件复制到其他的的链接的通过点击添加|现有文件,然后选中文件对话框上添加为链接复选框。

Create two projects in your solution (one normal Class Library project, and one Compact Framework Class Library project), and add all the files from one project to the other as links by clicking "Add|Existing File" and then checking the "add as link" checkbox on the file dialog.

现在你只有一套源$ C ​​$ C来维持,但你的解决方案将在同一时间建立两个DLL文件。

Now you only have one set of source code to maintain, but your solution will build both DLLs at the same time.

如果你有一个文件,该文件是针对台式机的框架,不会对紧凑的框架内工作的任何code,你可以在编译器指令(至少在C#),这样的包装它:

If you have any code inside a file that's specific to the desktop framework and won't work on the compact framework, you can wrap it in a compiler directive (at least in C#) like this:

#if PocketPC
    // mobile-specific stuff here
#else
    // desktop-specific stuff here
#endif

需要注意的是,虽然你不能在移动平台上使用台式机的架构的二进制文件,相反的是不正确的。紧凑型框架的可执行文件可以在桌面上运行。我相当肯定,但是,一个桌面应用程序不能引用一个紧凑的框架组件(虽然我从来没有尝试过)。

 
精彩推荐
图片推荐