Iva*_*ono 130 c# visual-studio-2015
我已经将我的项目复制到一台干净的Windows 10机器上,只安装了Visual Studio 2015社区和SQL Server 2016 Express.除了与Windows 10和VS2015或SQL Server一起安装的版本之外,没有安装任何其他框架版本.
当我尝试启动WebApi项目时,我收到消息:
无法加载文件或程序集"System.Net.Http,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a"或其依赖项之一.该系统找不到指定的文件.
该项目的包包括:
<package id="Microsoft.AspNet.WebApi" version="5.2.3" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.Core" version="5.2.3" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.Tracing" version="5.2.3" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.WebHost" version="5.2.3" targetFramework="net45" />
Run Code Online (Sandbox Code Playgroud)
使用.NET Framework 4.6.1构建项目后,System.Net.Http在该bin文件夹中找不到该文件.
该文件的路径指向:
C:\ Program Files(x86)\ Reference Assemblies\Microsoft\Framework.NETFramework\v4.6.1\System.Net.Http.dll
该文件的路径System.Net.Http.Formatting指向:
C:\开发\ MyApp的\包\ Microsoft.AspNet.WebApi.Client.5.2.3\LIB \net45\System.Net.Http.Formatting.dll
整个项目是否应该以4.5.1为目标,还是有另一种方式来引用正确的组件?
tri*_*d99 223
更改我的web.config(或app.config)中的绑定信息 - 在我的视图中"hack",允许您在NuGet包更新破坏您的应用程序后向前推进您的项目,并为您提供System.Net.Http错误.
设置newVersion ="4.0.0.0"
<dependentAssembly>
<assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.1.1.0" newVersion="4.0.0.0" />
</dependentAssembly>
Run Code Online (Sandbox Code Playgroud)
Saj*_*ran 66
请按照以下步骤操作
web.config将其添加到.csproj文件中:
<PropertyGroup>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup>
Run Code Online (Sandbox Code Playgroud)bin文件夹中应该有一个(WebAppName).dll.config文件web.config.csproj文件中删除上面的剪辑它应该工作
Ram*_*Ram 29
在我的一个项目中,有一个带有更高版本System.Net.Http的nuget软件包.在我的启动项目中引用System.Net.Http v 4.0.0,我刚刚在我的启动项目中安装了System.Net.Http nuget包,问题解决了
Muh*_*qas 12
更改以下内容:
<bindingRedirect oldVersion="0.0.0.0-4.1.1.2" newVersion="4.1.1.2" />
Run Code Online (Sandbox Code Playgroud)
具有以下内容:
<bindingRedirect oldVersion="0.0.0.0-4.1.1.2" newVersion="4.0.0.0" />
Run Code Online (Sandbox Code Playgroud)
在web.config中
如果您的解决方案中有多个项目,请右键单击Visual Studio中的解决方案图标,然后选择"管理解决方案的NuGet包",然后单击第四个选项卡"合并"以将所有项目合并到相同版本的DLL文件.这将为您提供要合并的引用程序集列表.单击列表中的每个项目,然后在右侧显示的选项卡中单击"安装".
这将在 .NET 4.7.2 和 Visual Studio 2017 (15.9.4) 中工作:
上面的bind-redirect对我不起作用,因此我注释了对System.Net.Httpin 的引用web.config。没有它,一切似乎都可以正常工作。
<system.web>
<compilation debug="true" targetFramework="4.7.2">
<assemblies>
<!--<add assembly="System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />-->
<add assembly="System.ComponentModel.Composition, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
</assemblies>
</compilation>
<customErrors mode="Off" />
<httpRuntime targetFramework="4.7.2" />
</system.web>
Run Code Online (Sandbox Code Playgroud)
打开 Web.config 并删除 <runtime>包括其中的所有内容
<**运行时>< assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> </运行时>
保存并关闭 Web.config
打开包管理器控制台并运行命令
添加绑定重定向
当我的团队成员从 .NET Framework 4.6.1 升级到 .NET Framework 4.8 以及 VS 2017 升级到 VS 2022 时,这解决了我的问题
您可以通过将项目升级到.NET Framework 4.7.2来解决此问题。Alex Ghiondea-MSFT回答了这个问题。请投票支持他,因为他确实应得的!
在.NET Framework 4.7.1中,这被记录为已知问题。
解决方法是将这些目标添加到项目中。他们将从传递给SGEN的引用列表中删除DesignFacadesToFilter(并在完成SGEN后将其重新添加)
Run Code Online (Sandbox Code Playgroud)<Target Name="RemoveDesignTimeFacadesBeforeSGen" BeforeTargets="GenerateSerializationAssemblies"> <ItemGroup> <DesignFacadesToFilter Include="System.IO.Compression.ZipFile" /> <_FilterOutFromReferencePath Include="@(_DesignTimeFacadeAssemblies_Names->'%(OriginalIdentity)')" Condition="'@(DesignFacadesToFilter)' == '@(_DesignTimeFacadeAssemblies_Names)' and '%(Identity)' != ''" /> <ReferencePath Remove="@(_FilterOutFromReferencePath)" /> </ItemGroup> <Message Importance="normal" Text="Removing DesignTimeFacades from ReferencePath before running SGen." /> </Target> <Target Name="ReAddDesignTimeFacadesBeforeSGen" AfterTargets="GenerateSerializationAssemblies"> <ItemGroup> <ReferencePath Include="@(_FilterOutFromReferencePath)" /> </ItemGroup> <Message Importance="normal" Text="Adding back DesignTimeFacades from ReferencePath now that SGen has ran." /> </Target>另一个选择(机器范围)是将以下绑定重定向添加到sgen.exe.config:
Run Code Online (Sandbox Code Playgroud)<runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="System.IO.Compression.ZipFile" publicKeyToken="b77a5c561934e089" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.0.0.0" /> </dependentAssembly> </assemblyBinding> </runtime> This will only work on machines with .NET Framework 4.7.1. installed. Once .NET Framework 4.7.2 is installed on that machine, this workaround should be removed.
VS2017 中的 4.6.1-2 用户可能会遇到他们的 System.Net.Http 版本被 VS2017 或 Msbuild 15 想要使用的一个不必要的替换。
我们在这里删除了这个版本:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Microsoft\Microsoft.NET.Build.Extensions\net461\lib\System.Net.Http.dll
和这里:
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\Microsoft\Microsoft.NET.Build.Extensions\net461\lib\System.Net.Http.dll
然后使用我们通过 NuGet 引用的版本构建项目。
| 归档时间: |
|
| 查看次数: |
90529 次 |
| 最近记录: |