问题描述
我可以将.net core与旧版.net框架dll一起使用吗?答案似乎不是……但是我只能找到引用 project.json的资源,该资源不再存在。
Can I use .net core with legacy .net framework dlls? The answer seems to be no... but I can only find resources referring to project.json, which doesn't exist anymore.
我创建了一个新的.net核心库,并尝试引用旧版.net框架DLL。当我尝试调用DLL时,vs2017抱怨我没有在寻找Stream对象。
I created a new .net core library and tried to reference a legacy .net framework DLL. When I tried to call into the DLL, vs2017 complained that I didn't have the Stream object is was looking for.
它建议我引用mscorlib.dll或installa Nuget程序包。
It suggested I reference either mscorlib.dll or installa Nuget package.
快速帮助未能引用mscorlib.dll。如果手动引用它,则会出现以下错误:
The quick help failed to reference mscorlib.dll. If I manually referenced it, I get the following error:
NuGet软件包是Microsoft.NETFx2 .0。快速帮助无法安装。如果我从命令行运行它:
The NuGet package is Microsoft.NETFx2.0. The quick help fails to install it. If I run it from the command line:
> PM> install-package microsoft.netfx20 GET
> https://api.nuget.org/v3/registration2-gz/microsoft.netfx20/index.json
> OK
> https://api.nuget.org/v3/registration2-gz/microsoft.netfx20/index.json
> 46ms Restoring packages for ... Install-Package : Package
> Microsoft.NetFX20 1.0.3 is not compatible with netcoreapp1.1
> (.NETCoreApp,Version=v1.1). Package Microsoft.NetFX20 1.0.3 supports:
> net20 (.NETFramework,Version=v2.0)At line:1 char:1
> + install-package microsoft.netfx20
> + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> + CategoryInfo : NotSpecified: (:) [Install-Package], Exception
> + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand
> Install-Package : One or more packages are incompatible with
> .NETCoreApp,Version=v1.1.At line:1 char:1
> + install-package microsoft.netfx20
> + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> + CategoryInfo : NotSpecified: (:) [Install-Package], Exception
> + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand
> Install-Package : Package restore failed. Rolling back package changes
> for .At line:1 char:1
> + install-package microsoft.netfx20
> + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> + CategoryInfo : NotSpecified: (:) [Install-Package], Exception
> + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand
> Time Elapsed: 00:00:00.8035644
推荐答案
困难的话题。通常,.NET Framework和.NET Core不兼容。它们针对不同的程序集集(mscorlib与System.Runtime),这会导致不兼容,因为所有类型的用法都以该类型的程序集作为前缀。
Difficult topic. Generally .NET Framework and .NET Core are incompatible. They target a different set of assemblies (mscorlib vs. System.Runtime) which causes incompatibilities since all usages of types are prefixed with the assembly the type is from.
开头.NET Core 2(当前处于预览状态),您可以通过不可见的兼容性填充程序来引用.NET Framework程序集。这样一来,您就可以引用程序集并成功进行编译。
Starting with .NET Core 2 (currently in preview), you can reference .NET Framework assemblies through an invisible compatibility shim. This allows you to reference the assembly and compile successfully.
它不能保证应用程序将成功运行,因为.NET Core不提供所有API。从.NET Framework。在这种情况下,您将在运行时获得 PlatformNotSupportedException
或 MissingTypeException
和朋友。
It doesn't guarantee though that the application will run successfully, since .NET Core doesn't provide all the APIs from .NET Framework. You'll get PlatformNotSupportedException
or MissingTypeException
and friends at runtime if thats the case.
这篇关于将.net核心与旧版.net框架dll一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!