我已经将目前针对VS2010中的.NET 4.0的解决方案迁移到VS2012,现在我想将其重新定位到.Net 4.5
我不确定的是NuGet包.例如,我在VS2010中从EF4更新的EF5实际上是EF 4.4,如下所示:
<Reference Include="EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\EntityFramework.5.0.0\lib\net40\EntityFramework.dll</HintPath>
</Reference>
Run Code Online (Sandbox Code Playgroud)
我还可以在packages.config中看到以下项目:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="EntityFramework" version="5.0.0" targetFramework="net40" />
</packages>
Run Code Online (Sandbox Code Playgroud)
所以我的问题是:
将目前设置为.NET 4.0的所有NuGet包重新定位到目标.NET 4.5的最佳做法是什么?
每当我尝试运行具有应用程序洞察力和实体框架的webjob项目时,我都会收到此错误.
System.IO.FileLoadException:'无法加载文件或程序集'System.Runtime.InteropServices.RuntimeInformation,Version = 0.0.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a'或其依赖项之一.定位的程序集的清单定义与程序集引用不匹配.(HRESULT异常:0x80131040)'
我安装了以下nuget包
Microsoft.Azure.WebJobs.Logging.ApplicationInsights版本2.1.0-beta4
Microsoft.Extensions.Logging版本2.0.0
Microsoft.Extensions.Logging.Console版本2.0.0.
这一切都适用于一个新的Visual Studio 2017 webjob项目,当我尝试包含现有的代码库时,主要使用实体框架,我得到了这个错误.当我查看工作中的引用时,我没有System.Runtime.InteropServices.RuntimeInformation,但它已经添加到具有实体框架的项目中.它似乎是.net标准的一部分,但为什么我的新控制台应用程序不需要.net标准!
我不确定它为什么寻找版本0.0.0.0,因为我的版本是4.0.2.0
我也尝试将其添加到项目文件中,但这不起作用.
<PropertyGroup>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup>
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激
非常感谢
我们与MongoDB一起使用的每个项目都会在没有加载的System.Runtime.InteropServices库中出现问题.
这次错误很有趣:
外部异常找不到lib的4.3.0.0版本.但是内部异常找不到版本4.0.0.0
有没有人对此有所了解?
有关此问题的更多信息:
所以,NuGet已经安装了4.3.0.0
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="System.Runtime" version="4.3.0" targetFramework="net462" />
<package id="System.Runtime.InteropServices.RuntimeInformation" version="4.3.0" targetFramework="net462" />
</packages>
Run Code Online (Sandbox Code Playgroud)
packages.config确认我已经安装了4.3.0.0,
然而,app.config似乎总是与现实不同步:
<dependentAssembly>
<assemblyIdentity name="System.Runtime.InteropServices.RuntimeInformation" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
</dependentAssembly>
Run Code Online (Sandbox Code Playgroud)
添加了关于版本4.0.1.0的一行
在同一行.. csproj是胡说八道:
<Reference Include="System.Runtime.InteropServices.RuntimeInformation, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>x:\Packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll</HintPath>
</Reference>
Run Code Online (Sandbox Code Playgroud)
因为它声称引用4.0.1.0的路径为4.3.0.0
有一些东西被破坏了,它总是发生在那个完全相同的lib上; 不仅仅是这个项目:在我包含MongoDB的任何地方,这个lib都是一个依赖项,每次都有一些随机问题.
当我尝试手动加载时:
var Name = new AssemblyName("System.Runtime.InteropServices.RuntimeInformation, Version=4.3.0.0");
var Asm = Assembly.Load(Name);
Run Code Online (Sandbox Code Playgroud)
它也失败了.
我发现System.Runtime.InteropServices.RuntimeInformation.dll不会被复制到build文件夹,即使它包含在项目中.
我找到了一个讨厌的解决方法:如果我在主exe中包含MongoDB,即使我不使用它,它依赖于Interop lib,这迫使lib被复制到build文件夹,然后后续调用工作.