因此,当有人将我的 nuget 包添加到他们的代码中时,我尝试替换 dependentAssembly。
我要更改的程序集是:
<dependentAssembly>
<assemblyIdentity name="Common.Logging.Core" publicKeyToken="af08829b84f0328e" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.1.0.0" newVersion="3.1.0.0" />
</dependentAssembly>
因此,我使用此 xml 文件并从以下位置获取帮助:Web.config transforms - the missing manual
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly xdt:Transform="Replace" xdt:Locator="Condition(./_defaultNamespace:assemblyIdentity/@name:'Common.Logging.Core')">
<assemblyIdentity name="Common.Logging.Core" publicKeyToken="af08829b84f0328e" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.1.0.0" newVersion="2.2.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
但我收到错误:对项目中的“web.config”应用转换时发生错误:“blabla”具有无效的限定名称。
注意到,当我将“替换”更改为“删除”时,它会删除完整的 dependentAssembly,但后来不知何故,它再次将相同的 dependentAssembly 添加到 web.config 中。也许是因为 Common.Logging.Core 依赖项是在 web.config 转换后添加的?
也许这就是替换不起作用的原因?
最佳答案
试试这个:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<!-- first completely remove the parent element -->
<dependentAssembly xdt:Transform="RemoveAll"
xdt:Locator="Condition(starts-with(./_defaultNamespace:assemblyIdentity/@name,'Microsoft.Diagnostics.Tracing.EventSource'))">
</dependentAssembly>
<!-- then add the new block -->
<dependentAssembly xdt:Transform="Insert">
<assemblyIdentity name="Microsoft.Diagnostics.Tracing.EventSource" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.1.16.0" newVersion="1.1.16.0 " />
</dependentAssembly>
</assemblyBinding>
</runtime>
关于asp.net - 如何在 Web 配置中转换替换 dependentAssembly?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30911209/