Xep*_*pos 6 asp.net web-config web-config-transform xdt-transform
所以当有人将我的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>
Run Code Online (Sandbox Code Playgroud)
因此,我使用此xml文件并提供以下帮助:Web.config转换 - 缺少的手册
<?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>
Run Code Online (Sandbox Code Playgroud)
但是我收到了错误:在项目中将转换应用于'web.config'时发生错误:'blabla'具有无效的限定名称.
注意到当我将"Replace"更改为"Remove"时,它会删除完整的dependentAssembly,但不知何故,它会再次将相同的dependentAssembly添加到web.config中.也许是因为在web.config转换后添加了Common.Logging.Core依赖项?
也许这就是替换不起作用的原因?
小智 7
试试这个:
<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>
Run Code Online (Sandbox Code Playgroud)
下面的 XML 将绑定重定向应用于 assemble Common.Logging.Core。\n它包含两个变换操作。InsertIfMissing\n如果程序集条目不存在,则第一个, 会插入一个新条目,而第二个 ,Replace会在现有重定向已存在的情况下替换它。
<?xml version="1.0" encoding="utf-8"?>\n<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1">\n <runtime>\n <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">\n <dependentAssembly xdt:Transform="InsertIfMissing" xdt:Locator="Condition(asmv1:assemblyIdentity/@name=\'Common.Logging.Core\')">\n <assemblyIdentity name="Common.Logging.Core" publicKeyToken="af08829b84f0328e" culture="neutral" xmlns="urn:schemas-microsoft-com:asm.v1"/>\n <bindingRedirect oldVersion="0.0.0.0-3.1.0.0" newVersion="3.1.0.0" xmlns="urn:schemas-microsoft-com:asm.v1"/> \n </dependentAssembly>\n <dependentAssembly xdt:Transform="Replace" xdt:Locator="Condition(asmv1:assemblyIdentity/@name=\'Common.Logging.Core\')">\n <assemblyIdentity name="Common.Logging.Core" publicKeyToken="af08829b84f0328e" culture="neutral" xmlns="urn:schemas-microsoft-com:asm.v1"/>\n <bindingRedirect oldVersion="0.0.0.0-3.1.0.0" newVersion="3.1.0.0" xmlns="urn:schemas-microsoft-com:asm.v1"/>\n </dependentAssembly>\n </assemblyBinding>\n </runtime>\n</configuration>\nRun Code Online (Sandbox Code Playgroud)\n\n注意asmv1添加到configuration元素的名称空间。这是需要它才能发挥作用的。
注意:我想避免在转换中添加assemblyIdentity和bindingRedirect元素InsertIfMissing,但无法\xe2\x80\x99 使其工作。如果您知道怎么做,请告诉我。
| 归档时间: |
|
| 查看次数: |
2229 次 |
| 最近记录: |