我是否必须为每个版本的 .net 构建单独的类库版本?
我很确定答案是肯定的,但我还没有找到直接提出这个问题的问题。
我的产品是一组.NET 类库。使用它们的应用程序及其配置文件完全不受我的控制。我曾经(我认为是错误的)认为如果这些库是针对 .NET 2.0 构建的,那么它们可以用于更高版本。在最近的用户问题之后,我更详细地研究了这种情况,如果我理解正确的话,兼容性只是编译时而不是运行时(除非在应用程序配置中指定)。
那么我是否必须针对每个框架构建它用户想要定位的版本,或者有没有办法生成与版本无关的类库?
I'm pretty sure the answer is yes, but I haven't found a question that asks this outright.
My product is a set of .NET class libraries. The applications that use them and their config files are entirely out of my control. I had (mistakenly, I believe) thought that if the libraries were built against .NET 2.0, they could be used with later versions. After a recent user problem, I have dug into the situation in more detail, and if I understand correctly, compatibility is only compile-time and not runtime (unless specified in the app config.)
So do I have to build it against each framework version users want to target, or is there a way to produce a class library that is version-independent?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
除非您的类库是混合模式,否则您应该能够毫无问题地从 .NET 4 应用程序使用 .NET 2.0 类库。 (我假设您已经构建了“任何 CPU”程序集。)我已经在很多情况下这样做了。
您应该没问题,但如果您遇到特定错误,我建议您编写一个简短但完整的程序来演示问题,并将其包含在您的问题中。
Unless your class library is mixed mode, you should be able to use a .NET 2.0 class library from a .NET 4 application with no problems. (I assume you've built "Any CPU" assemblies.) I've done this on many occasions.
You should be okay, but if you have a specific error I suggest you put together a short but complete program which demonstrates the problem, and include that in your question.
如果您打算将应用程序定位为使用与构建应用程序所用的运行时不同的运行时 (.Net Framework),则需要重新构建。
If you intend to target your application to use a runtime (.Net Framework) that is different from the one that was used to build your application, you will need to rebuild.
我相信您可以在 app.config 文件中指定目标框架,如下所示:
I believe you can specify the target framework in teh app.config file, like this: