在.NET Core 1.1 CSPROJ中引用.NET 4.5 DLL? [英] Reference .NET 4.5 dll in .NET Core 1.1 csproj?

本文介绍了在.NET Core 1.1 CSPROJ中引用.NET 4.5 DLL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!


我正在运行VS 2017 RC4.

I'm running VS 2017 RC4.

我在.NET Core应用程序中向.NET 4.5 dll添加了引用,并且该引用可以编译.当在运行时调用引用dll的行时,我得到:

I add a reference in my .NET Core app to my .NET 4.5 dll and it compiles. When a line that references the dll is called at runtime, I get:

System.IO.FileNotFoundException: 'Could not load file or assembly 'System, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified.'

此图显示,要使用4.5引用,我需要使用netstandard 1.1. https://msdnshared.blob.core.windows.net/media/2016/07/172.png

This image shows that to use 4.5 references, I need to use netstandard 1.1. https://msdnshared.blob.core.windows.net/media/2016/07/172.png


Assuming that is what I need, how do I reference it in my .csproj? I can only find old documentation for when project.json was used instead.


I tried adding the below but it did not help:





Or I get FileNotFoundException: Could not load file or assembly. The system cannot find the file specified.



Here are the relevant parts of my .csproj:

    <Reference Include="My4.5dll">


您不能(安全地)将.NET Framework 4.5库加载到.NET Core中,因为它可能会使用.NET Core中不可用的API.

You can't (safely) load a .NET Framework 4.5 library into .NET Core, because it may use APIs which are unavailable in .NET Core.

仅当您的库针对portable-net45+win8(.NET Framework 4.5 和Windows 8可移植类配置文件或更高版本)时,它才可以与.NET Core一起使用.因为此特定的PCL配置文件限制了与.NET Core所基于的API(以前称为WinRT)System.Runtime兼容,所以.

Only if your library targets portable-net45+win8 (.NET Framework 4.5 and Windows 8 Portable Class Profile or higher) it can be used with .NET Core. Because this specific PCL Profile limits the API which is compatible to (what was formerly called WinRT) System.Runtime, which is what is .NET Core is based on.


For a list of compatible PCL profiles, see this list (PCL Compatibility at the bottom)

如果要引用的程序集不支持netstandard1.x或任何受支持的配置文件,则必须以.NET Framework 4.5而不是.NET Core为目标.

If the assembly you want to reference do not support netstandard1.x or any of the supported profiles, you have to target .NET Framework 4.5 instead of .NET Core.


    <PackageReference Include="Net45DependencyHere" Version="4.5.0" />


    <PackageReference Condition="'$(TargetFramework)' == 'net45' Include="Net45DependencyHere" Version="4.5.0" />
    <PackageReference Condition="'$(TargetFramework)' == 'netcoreapp1.1' Include="NetCoreReplacementLibrary" Version="1.1.0" />

您只是无法自动魔术地使用.NET Core项目中的任何.NET Framework 4.5库.只有PCL和netstandard1.x的.

You just can't auto-magically use any .NET Framework 4.5 library in your .NET Core project. Only PCL and netstandard1.x ones.



If you are certain that your class library/package targets a compatible PCL, you can make nuget restore this packages too, even if they don't target netstandard1.x.



从不,我重复一次,从不在此放置除兼容的PCL库以外的任何其他内容. 从不在此处放置net45.这只会强制NuGet下载并安装此软件包,但不会使其运行并在运行时崩溃,并出现类似上面的错误!

Word of warning

Never, I repeat, NEVER put anything else there except for compatible PCL Libraries. NEVER put net45 in here. This will just force NuGet to download and install this package, but it won't make it work and crash at runtime with similar error like you have above!

只有在这种情况下,强制nuget安装在过渡期内可以与.NET Core一起使用的软件包,直到大多数软件包都以netstandard1.x为目标!

It's only there to force nuget to install package which are know to work with .NET Core for the transition period until most packages target netstandard1.x!

这篇关于在.NET Core 1.1 CSPROJ中引用.NET 4.5 DLL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

登录 关闭
发送“验证码”获取 | 15天全站免登陆