简体   繁体   English

如何在.net 2.0项目中使用.net 3.0类?

[英]How can I use .net 3.0 class in .net 2.0 project?

I have a project in .NET 2.0 (let's call it Project A). 我在.NET 2.0中有一个项目(我们称其为Project A)。 I wanted to use WCF , so I created another project (in .NET 3.0, let's call it Project B) where I put all WCF logic, so all I do in my Project A is calling some method from class from Project B. When I add reference to Project B, Project A does not see it and I get warnings: 我想使用WCF ,所以我创建了另一个项目(在.NET 3.0中,我们称其为Project B),在其中放置了所有WCF逻辑,因此我在Project A中所做的所有工作都是从Project B中的类调用某个方法。添加对项目B的引用,项目A看不到它,并且我得到警告:

The primary reference "Project B/Some.dll" could not be resolved because it has an indirect dependency on the framework assembly "System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=XXX" which could not be resolved in the currently targeted framework. 无法解析主引用“ Project B / Some.dll”,因为它与框架程序集“ System.ServiceModel,Version = 3.0.0.0,Culture = neutral,PublicKeyToken = XXX”存在间接依赖关系,当前目标框架。 ".NETFramework,Version=v2.0". “ .NETFramework,版本= v2.0”。

How can I make this work? 我该如何进行这项工作?

To use WCF (at runtime) .NET 3 (or better 3.5) will need to be installed anyway. 要使用WCF(在运行时),无论如何都需要安装.NET 3(或更高版本的3.5)。 Therefore change ProjectA to target 3 (or 3.5). 因此,将ProjectA更改为目标3(或3.5)。

You can not do this directly, your projects target different versions of .NET. 您不能直接执行此操作,因为您的项目针对的是.NET的不同版本。

What you can do is communicate between two processes. 您可以做的是在两个进程之间进行通信。

Make your 3.0 project an executable, and allow it to accept a commandline argument that invokes the method you want to use. 使3.0项目成为可执行文件,并允许其接受调用您要使用的方法的命令行参数。

In your 2.0 project, spawn your 3.0 project as a new Process with the proper commandline arguments. 在您的2.0项目中,将3.0项目作为带有适当命令行参数的新Process生成。 If necessary, write to your 3.0 project's StandardOutput and read it from your 2.0 project. 如有必要,写入3.0项目的StandardOutput并从2.0项目中读取。

Yes, this is perfectly possible. 是的,这完全有可能。 You just expose the components written in 3.0 as COM objects. 您只需将用3.0编写的组件公开为COM对象。 The 2.0 hosting application just uses them as COM objects and has no idea whether they are native, 2.0, 3.0 or whatever. 2.0托管应用程序仅将它们用作COM对象,却不知道它们是本机,2.0、3.0还是其他类型。 COM is the common interface that both runtime versions have to implement identically. COM是两个运行时版本必须完全实现的通用接口。

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

相关问题 我可以在.NET 2.0或3.0中使用扩展方法和LINQ吗? - Can I use extension methods and LINQ in .NET 2.0 or 3.0? 如何在第三个项目中引用和使用 .NET Core 3.0 和 .NET EF 4.7 项目,并使用它们的数据库连接? - How can I reference and use .NET Core 3.0 and .NET EF 4.7 projects, in a third project, and use their database connections? 我可以在我的 ApplicationLogic 项目(net standard 2.1)中的 MVC(.net core 3.0)项目中使用视图模型吗? - Can I use viewmodels in my MVC(.net core 3.0) project in my ApplicationLogic project (net standard 2.1) 如何将 C# .net 框架项目更改为 .net 核心 3.0 项目? [等候接听] - How can I change a C# .net framework project to a .net core 3.0 project? [on hold] 如何在.NET Standard 2.0项目上实现Dotfuscator? - How can I implement Dotfuscator on a .NET Standard 2.0 project? 如何在 Google Cloud 中使用 .Net Core 3.0 映像? - How can I use .Net Core 3.0 image in Google Cloud? 我可以在.NET 3.0中使用异步CTP吗? - Can I use Async CTP with .NET 3.0? .NET 4.7.1项目不能使用.NET Core 2.0库 - .NET 4.7.1 project can't use .NET Core 2.0 library 尽管我具有.NET core 2.2,但如何打开.NET core 2.0 mvc项目? - How can I open a .NET core 2.0 mvc project despite that I have .NET core 2.2? 如何在 .NET 2 项目中使用 .NET 4.7 程序集? - How can I use .NET 4.7 assembly in .NET 2 project?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM