ASP核心错误的程序集重定向在发布 [英] Asp core wrong assembly redirect on publish
问题描述
使用Visual Studio发布我的asp核心项目时,会在我的可执行文件旁边创建一个.config
文件.
When publishing my asp core project using visual studio a .config
file is created alongside my executable.
.config
包括几个bindingRedirect
,如下所示:
The .config
includes a couple of bindingRedirect
like this:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="6.0.0.0" newVersion="8.0.0.0" />
<bindingRedirect oldVersion="7.0.0.0" newVersion="8.0.0.0" />
<bindingRedirect oldVersion="6.0.0.0" newVersion="9.0.0.0" />
<bindingRedirect oldVersion="8.0.0.0" newVersion="9.0.0.0" />
<bindingRedirect oldVersion="7.0.0.0" newVersion="9.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Serilog" publicKeyToken="24c2f752a8e58a10" culture="neutral" />
<bindingRedirect oldVersion="1.5.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Collections.Immutable" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="1.1.37.0" newVersion="1.2.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Reflection.Metadata" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="1.2.0.0" newVersion="1.3.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
在这里,我要将Newtonsoft.Json
的bindingRedirect
更改为:
Here I want to change the bindingRedirect
for Newtonsoft.Json
to:
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" />
</dependentAssembly>
根据此博客文章: http://blog.rytmis.net/2016/03/29/asp-net-core-and-assembly-binding-redirects/我应该能够创建App.config
并在那里指定绑定.但是,我无法使其正常工作.当我添加一个时,它仍然会产生相同的.config
.
According to this blog post: http://blog.rytmis.net/2016/03/29/asp-net-core-and-assembly-binding-redirects/ I should be able to create an App.config
and specify the binding there. However, I cannot get it to work. When I add one it still produces the same .config
.
有什么想法吗?
注意:我可以在项目中创建一个与可执行文件同名的.config
文件,并使用正确的bindingRedirect
,然后在project.json
文件中编辑publishOptions
包括它.然后,我将不得不手动添加所有其他将来的bindingredirect
.
NOTE: I could create a .config
file in my project with the same name as my executable and with the correct bindingRedirect
and then edit the publishOptions
in my project.json
file to include it. Then I would manually have to add all the other future bindingredirect
.
推荐答案
您需要创建一个web.config转换文件.
You need to create a web.config transformation file.
此答案将派上用场,因为您自己添加起来并不容易- https://stackoverflow.com/a/16826106/1147920
This answer will come in handy in order to that as it is not easy to add it yourself - https://stackoverflow.com/a/16826106/1147920
您还可以通过创建web.config文件的副本并将其重命名为web.release.config或web.{PublishProfile} .config(如果使用的话)来手动完成操作.
You could also do it manually by creating a copy of the web.config file and renaming it to either web.release.config or web.{PublishProfile}.config (if you're using one).
要编写转换规则以编辑bindingRedirect,请参考官方文档-
To write the transform rule to edit the bindingRedirect refer to the official docs - https://docs.microsoft.com/en-us/aspnet/web-forms/overview/deployment/visual-studio-web-deployment/web-config-transformations
这篇关于ASP核心错误的程序集重定向在发布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!