Azure功能本地(CLI)与云DLL不匹配

时间:2017-02-15 12:10:13

标签: azure azure-functions

概述

我制作的自定义程序集需要使用不同版本的WindowsAzure.Storage,具体取决于我是在本地运行,使用Azure Fucnctions CLI还是在Azure上远程运行

描述

我正在使用Azure Functions的自定义assemlby来执行一些blob操作逻辑。因此,它取决于程序集Microsoft.WindowsAzure.Storage。所以我有一个Visual Studio解决方案,其中包含:

  • 包含自定义程序集的类库项目
  • 类库projecx,包含自定义程序集的单元测试
  • 功能项目

作为构建触发器的一部分,我将自定义程序集复制到fucnxtions中的适当位置,并使用引用标记将其拉入。

在本地工作时,我可以使用Azure Functions CLI来运行相关功能。部署到Azure时,我可以使用门户来运行我的功能。 (我通过本地git repo部署,如果相关的话)。

我遇到的困难是AF CLI似乎需要运行不同版本的WindowsAzure.Storage程序集才能运行真正的Azure功能门户。我将TraceWriter实例传递给支持库,因此我需要使用Microsoft.Azure.WebJobs,它具有自己对WindowsAzure.Storage的依赖。

要使Azure功能在云中运行,我使用以下版本:

Microsoft.Azure.WebJobs.Core v1.1.2
Microsoft.Azure.WebJobs      v1.1.2
WindowsAzure.Storage         v6.1.0

但是在使用本地托管环境时,我看到以下错误消息:

Exception while executing function: Functions.SdcLaundrySriTrigger. 
mscorlib: Exception has been thrown by the target of an invocation. f-<Redacted>Trigger__1261552806: Method not found: 
'Void <RedactedClassname>..ctor(Microsoft.Azure.WebJobs.Host.TraceWriter, System.String)'.

如果我使用更新版本的WebJobs库,我可以解决本地环境的问题:

Microsoft.Azure.WebJobs.Core v2.0.0-beta1
Microsoft.Azure.WebJobs      v2.0.0-beta1
WindowsAzure.Storage         v7.2.1.0

(通过增加WebJobs版本进行更改,并且WindowsAzure.Storage版本因为依赖而上升)。然后使用func funcxtion run运行良好。但是当我将其部署到云环境时,我收到以下错误:

error CS1705: Assembly '<redacted>' with identity 
'<redacted>, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' uses
'Microsoft.WindowsAzure.Storage, Version=7.2.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' 
which has a higher version than referenced assembly 
'Microsoft.WindowsAzure.Storage' with identity 
'Microsoft.WindowsAzure.Storage, Version=6.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
 2017-02-14T16:49:56.279 Function completed (Failure, Id=f17a046f-e66b-4f50-a812-bc7532db7a0f)2017-02-14T16:49:58.007 Exception while executing function: Functions.<redacted>. Microsoft.Azure.WebJobs.Script: Script compilation failed.

此时,显而易见的事情是将存储组件的版本撤回到6.1.0.0版本 - 但是这会将WebJobs程序集的版本拉回到我开始使用的版本,从而导致该功能不在当地工作。

实际Behvaiour

使用支持程序集的功能不可能在本地和Azure上依赖于相同版本的Microsoft.Azure.WebJobs。

预期行为

一旦我在本地运行该函数并将其推送到Azure,它应具有相同的版本。

问题

有没有人见过这个? 有一个简单的解决方法吗?

我知道这看起来与This issue非常相似,但我认为这是一个不同的问题。它可以被认为类似于This issue as well,但我仍然认为它不完全相同

2 个答案:

答案 0 :(得分:0)

我不喜欢&#39;认为你需要为

添加外部包或dll
  • Microsoft.Azure.WebJobs.Core
  • Microsoft.Azure.WebJobs
  • WindowsAzure.Storage

默认情况下,功能应用

已存在

你需要在你的本地项目中拥有像azure函数一样的环境。

如果已添加,请尝试从project.json文件中删除这些项目的nuget dependancies。

答案 1 :(得分:0)

我能够在本地VisualStudio调试和Azure中使用7.2.1。 Trick正在更新函数dir中的project.json:

{
  "frameworks": {
    "net46":{
      "dependencies": {
        "WindowsAzure.Storage": "7.2.1.0"
      }
    }
   }
}