NuGet包GAC依赖

时间:2014-12-19 11:55:55

标签: .net azure web-config nuget azure-service-runtime

运行我的.NET项目时,出现以下运行时错误:

Could not load file or assembly 'Microsoft.WindowsAzure.ServiceRuntime, Version=2.4.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.

根据我的理解,Microsoft.WindowsAzure.ServiceRuntime是GAC依赖项,在NuGet上不可用。

我的.NET项目从Azure SDK 2.5引用了2.5.0.0的ServiceRuntime。异常的堆栈跟踪显示我们的一个自定义NuGet包引用了2.4.0.0。

在查看NuGet包的依赖项时,它没有显示ServiceRuntime,我认为这是因为它是GAC引用(NuGet无法解析的东西):

NuGet Depedencies

我发现通过添加以下web.config更改,它现在可以正常运行:

<dependentAssembly>
    <assemblyIdentity name="Microsoft.WindowsAzure.ServiceRuntime" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-2.5.0.0" newVersion="2.5.0.0" />
</dependentAssembly>

我认为这仅在2.5.0.0向后兼容2.4.0.0规范时才有效。

问题:

  • 如果它不向后兼容会发生什么?
  • 为什么不是Microsoft.WindowsAzure.ServiceRuntime NuGet包?

1 个答案:

答案 0 :(得分:3)

尽管回答这个问题可能为时尚晚,但迟到总比没有好。以下是我的观点:

如果它不向后兼容会发生什么?

你的解决方案会破坏,虽然下一个版本的程序集不太向后兼容,你可以运行任何旧的.net程序和更新版本的.Net / CLR,最近它会显示弃用消息及其只有在很长一段时间后才会立即停止支持,就像在这种情况下一样。只有向后兼容时,程序集才是下一个版本,否则它是一个新程序集。

为什么Microsoft.WindowsAzure.ServiceRuntime不是NuGet包?

首先要了解Nuget here存在的原因,实质上它只适用于第三方库/扩展。它不适用于核心MS / .Net框架库,其源代码不可用且无法由外部开发人员修改。

希望这在某种程度上有所帮助。

相关问题