简体   繁体   English

当项目升级到 .Net Framework 4.7.2 时,从面向项目的 .Net Framework 4.6 引用的 DLL 不再出现在 bin 中

[英]Referenced DLL From Project Targeting .Net Framework 4.6 is no longer appearing in bin When Project Upgraded to .Net Framework 4.7.2

I have two projects, [Service] and [Web].我有两个项目,[Service] 和 [Web]。 Both were originally built targeting .Net Framework 4.6.两者最初都是针对 .Net Framework 4.6 构建的。 [Web] references [Service], and uses some of the DLLs (specially, System.Runtime.InteropServices.RuntimeInformation.dll and System.Net.Http.dll ) that [Service] has installed via NuGet packages. [Web] 引用 [Service],并使用 [Service] 通过 NuGet 包安装的一些 DLL(特别是System.Runtime.InteropServices.RuntimeInformation.dllSystem.Net.Http.dll )。

[Web] needs to upgrade to target .Net Framework 4.7.2. [Web] 需要升级到目标 .Net Framework 4.7.2。 This has been done, however, those two DLLs from [Service] no longer appear in the bin/ directory of [Web].这已经完成了,但是,[Service] 中的那两个 DLL 不再出现在 [Web] 的bin/目录中。

I am using Visual Studio 2017 Enterprise.我正在使用 Visual Studio 2017 企业版。

  • I have confirmed that if I downgrade [Web] to .Net Framework 4.6, the DLLs reappear.我已经确认,如果我将 [Web] 降级到 .Net Framework 4.6,DLL 会重新出现。 However, [Web] needs to be on 4.7.2 for other DLLs, and [Service] needs to remain on 4.6.但是,对于其他 DLL,[Web] 需要在 4.7.2 上,而 [Service] 需要保持在 4.6 上。
  • System.Runtime.InteropServices.RuntimeInformation.dll comes from Microsoft.AspNetCore.Mvc System.Runtime.InteropServices.RuntimeInformation.dll来自Microsoft.AspNetCore.Mvc
  • System.Net.Http comes from its own Nuget package System.Net.Http来自它自己的 Nuget 包

EDIT:编辑:

I have since found this buried deep into the detailed log of the build:从那以后,我发现这深深地隐藏在构建的详细日志中:

Unified Dependency "System.Runtime.InteropServices.RuntimeInformation, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
29>        Using this version instead of original version "4.0.1.0" in "C:\Users\baker\.nuget\packages\microsoft.aspnetcore.hosting\1.1.2\lib\net451\Microsoft.AspNetCore.Hosting.dll" because AutoUnify is 'true'.
29>        Using this version instead of original version "4.0.1.0" in "C:\Users\baker\.nuget\packages\microsoft.aspnetcore.server.kestrel\1.1.2\lib\net451\Microsoft.AspNetCore.Server.Kestrel.dll" because AutoUnify is 'true'.
29>        Using this version instead of original version "4.0.1.0" in "C:\Users\baker\.nuget\packages\microsoft.extensions.logging.console\1.1.2\lib\net451\Microsoft.Extensions.Logging.Console.dll" because AutoUnify is 'true'.
29>        Resolved file path is "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.2\Facades\System.Runtime.InteropServices.RuntimeInformation.dll".
29>        Reference found at search path location "{TargetFrameworkDirectory}".
29>            For SearchPath "C:\Users\baker\.nuget\packages\microsoft.aspnetcore.hosting\1.1.2\lib\net451".
29>            Considered "C:\Users\baker\.nuget\packages\microsoft.aspnetcore.hosting\1.1.2\lib\net451\System.Runtime.InteropServices.RuntimeInformation.winmd", but it didn't exist.
29>            Considered "C:\Users\baker\.nuget\packages\microsoft.aspnetcore.hosting\1.1.2\lib\net451\System.Runtime.InteropServices.RuntimeInformation.dll", but it didn't exist.
29>            Considered "C:\Users\baker\.nuget\packages\microsoft.aspnetcore.hosting\1.1.2\lib\net451\System.Runtime.InteropServices.RuntimeInformation.exe", but it didn't exist.
29>            For SearchPath "{CandidateAssemblyFiles}".
29>            Considered "net472Dlls\System.Net.Http.dll",
29>             but its name "System.Net.Http"
29>             didn't match the expected name "System.Runtime.InteropServices.RuntimeInformation, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
29>            Considered "net472Dlls\System.Runtime.InteropServices.RuntimeInformation.dll",
29>             but its name "System.Runtime.InteropServices.RuntimeInformation, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
29>             didn't match the expected name "System.Runtime.InteropServices.RuntimeInformation, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
29>            For SearchPath "{TargetFrameworkDirectory}".
29>            Considered "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.2\System.Runtime.InteropServices.RuntimeInformation.winmd", but it didn't exist.
29>            Considered "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.2\System.Runtime.InteropServices.RuntimeInformation.dll", but it didn't exist.
29>            Considered "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.2\System.Runtime.InteropServices.RuntimeInformation.exe", but it didn't exist.
29>            Considered "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.2\Facades\System.Runtime.InteropServices.RuntimeInformation.winmd", but it didn't exist.
29>        Required by "C:\Users\baker\.nuget\packages\microsoft.aspnetcore.hosting\1.1.2\lib\net451\Microsoft.AspNetCore.Hosting.dll".
29>        Required by "C:\Users\baker\.nuget\packages\microsoft.aspnetcore.server.kestrel\1.1.2\lib\net451\Microsoft.AspNetCore.Server.Kestrel.dll".
29>        Required by "C:\Users\baker\.nuget\packages\microsoft.aspnetcore.server.kestrel.https\1.1.2\lib\net451\Microsoft.AspNetCore.Server.Kestrel.Https.dll".
29>        Required by "C:\Users\baker\.nuget\packages\microsoft.extensions.logging.console\1.1.2\lib\net451\Microsoft.Extensions.Logging.Console.dll".
29>        This reference is not "CopyLocal" because it conflicted with another reference with the same name and lost the conflict.
29>        The ImageRuntimeVersion for this reference is "v4.0.30319".

Sounds like this issue .听起来像这个问题

From the link:从链接:

The workaround is to add an extra package reference to your project file and exclude all of its assets in order to make sure that the package implementation is never preferred.解决方法是向您的项目文件添加一个额外的包引用并排除其所有资产,以确保永远不会首选包实现。 This ensures that the platform version wins and is not removed by the NuGet targets.这可确保平台版本获胜并且不会被 NuGet 目标删除。 Here is an example of how to do this for the System.Net.Http.dll case:以下是如何针对 System.Net.Http.dll 情况执行此操作的示例:

<ItemGroup>
    <PackageReference Include="System.Net.Http" Version="4.3.3">
         <ExcludeAssets>All</ExcludeAssets> 
    </PackageReference>
</ItemGroup>

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

相关问题 在Framework 4.6项目中使用.net核心DLL - Use .net core DLL in Framework 4.6 project 在 .Net Core 项目中使用 .Net Framework dll (v4.7.2) - Use .Net Framework dll (v4.7.2) in .Net Core project 面向 .NET Standard 时,我到底可以在我的项目中使用 .NET Core 和 .NET Framework 中的哪些内容? - When targeting .NET Standard, what exactly can I use from .NET Core and .NET Framework in my project? .NET 框架 4.7.2 Class 库和 .NET 6.0 Razor 项目 - .NET Framework 4.7.2 Class Library and .NET 6.0 Razor project .Net Framework 4.7.2 引用.Net Standard 2.0 项目 - .Net Framework 4.7.2 Referencing .Net Standard 2.0 project EntityFramwork 与 .net 框架 4.7.2 项目和 .net 标准 2.0 项目的兼容性 - EntityFramwork compatibility with .net framework 4.7.2 projects and .net standard 2.0 project 在 Xamarin 项目中面向 .NET Framework 4.6.1 - Targeting .NET Framework 4.6.1 in Xamarin project UWP-使用面向.NET Framework 4.6的程序集 - UWP - Use assembly targeting .NET Framework 4.6 .NET Framework 4.7.2升级-无法加载项目文件 - .NET Framework 4.7.2 Upgrade - The project file could not be loaded 无法在.NET Framework 4.7.2项目中安装Nuget软件包 - Unable to install a Nuget Package in a .NET Framework 4.7.2 project
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM