[英]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.