Azure Function Nuget 缓存恢复失败 "The user name or password is incorrect."

Azure Function Nuget Cache restore failing with "The user name or password is incorrect."

我有一个 Azure 函数,我将其部署为 ARM 模板的一部分。此 Azure 函数引用了一些外部 .NET DLL。我在 project.json 文件中添加了对这些 DLL 的引用:

project.json:

{
    "frameworks": {
        "net46": {
            "dependencies": {
                "Microsoft.IdentityModel.Clients.ActiveDirectory":"3.13.8",
                "Newtonsoft.Json":  "10.0.2",
                 "Microsoft.CrmSdk.CoreAssemblies" : "8.2.0.2" 
            }
        }
    }
 }

当我点击 运行 时,Nuget 缓存恢复被启动。它因 "The user name or password is incorrect."

而失败

奇怪的是 Nuget 包被正确复制到 Functions Nuget 缓存,但是 project.lock.json 文件创建失败。似乎在 Nuget 缓存还原完成后以及 Azure 尝试写入 project.lock.json 文件时抛出用户名/密码错误。然后编译失败,因为未创建 project.lock.json 文件。

2017-11-14T21:06:34.892 Restoring packages.
2017-11-14T21:06:34.892 Starting NuGet restore
2017-11-14T21:06:36.239 Function started (Id=1340feea-174d-4bee-97f2-e06afc2e2d6e)
2017-11-14T21:06:36.239 Package references have been updated.
2017-11-14T21:06:36.239 Restoring packages.
2017-11-14T21:06:36.239 Starting NuGet restore
2017-11-14T21:06:36.955 Restoring packages for D:\home\site\wwwroot\ProvisionUserToCRM\project.json...
2017-11-14T21:06:37.456 CACHE https://api.nuget.org/v3-flatcontainer/microsoft.identitymodel.clients.activedirectory/index.json
2017-11-14T21:06:37.486 CACHE https://api.nuget.org/v3-flatcontainer/microsoft.identitymodel.clients.activedirectory/3.13.8/microsoft.identitymodel.clients.activedirectory.3.13.8.nupkg
2017-11-14T21:06:37.705 CACHE https://api.nuget.org/v3-flatcontainer/newtonsoft.json/index.json
2017-11-14T21:06:37.705 CACHE https://api.nuget.org/v3-flatcontainer/newtonsoft.json/10.0.2/newtonsoft.json.10.0.2.nupkg
2017-11-14T21:06:37.800 CACHE https://api.nuget.org/v3-flatcontainer/microsoft.crmsdk.coreassemblies/index.json
2017-11-14T21:06:37.800 CACHE https://api.nuget.org/v3-flatcontainer/microsoft.crmsdk.coreassemblies/8.2.0.2/microsoft.crmsdk.coreassemblies.8.2.0.2.nupkg
2017-11-14T21:06:37.881 CACHE https://api.nuget.org/v3-flatcontainer/microsoft.identitymodel/index.json
2017-11-14T21:06:37.881 CACHE https://api.nuget.org/v3-flatcontainer/microsoft.identitymodel/6.1.7600.16394/microsoft.identitymodel.6.1.7600.16394.nupkg
2017-11-14T21:06:38.002 Installing Microsoft.IdentityModel 6.1.7600.16394.
2017-11-14T21:06:38.362 Installing Microsoft.CrmSdk.CoreAssemblies 8.2.0.2.
2017-11-14T21:06:38.939 Restoring packages for D:\home\site\wwwroot\ProvisionUserToCRM\project.json...
2017-11-14T21:06:39.113 Installing Newtonsoft.Json 10.0.2.
2017-11-14T21:06:39.255 CACHE https://api.nuget.org/v3-flatcontainer/microsoft.identitymodel.clients.activedirectory/index.json
2017-11-14T21:06:39.284 CACHE https://api.nuget.org/v3-flatcontainer/microsoft.identitymodel.clients.activedirectory/3.13.8/microsoft.identitymodel.clients.activedirectory.3.13.8.nupkg
2017-11-14T21:06:39.455 CACHE https://api.nuget.org/v3-flatcontainer/newtonsoft.json/index.json
2017-11-14T21:06:39.455 CACHE https://api.nuget.org/v3-flatcontainer/newtonsoft.json/10.0.2/newtonsoft.json.10.0.2.nupkg
2017-11-14T21:06:39.470 CACHE https://api.nuget.org/v3-flatcontainer/microsoft.crmsdk.coreassemblies/index.json
2017-11-14T21:06:39.470 CACHE https://api.nuget.org/v3-flatcontainer/microsoft.crmsdk.coreassemblies/8.2.0.2/microsoft.crmsdk.coreassemblies.8.2.0.2.nupkg
2017-11-14T21:06:39.490 CACHE https://api.nuget.org/v3-flatcontainer/microsoft.identitymodel/index.json
2017-11-14T21:06:39.502 CACHE https://api.nuget.org/v3-flatcontainer/microsoft.identitymodel/6.1.7600.16394/microsoft.identitymodel.6.1.7600.16394.nupkg
2017-11-14T21:06:39.642 Installing Microsoft.IdentityModel.Clients.ActiveDirectory 3.13.8.
2017-11-14T21:06:41.211 Installing Microsoft.IdentityModel 6.1.7600.16394.
2017-11-14T21:06:42.367 Installing Microsoft.CrmSdk.CoreAssemblies 8.2.0.2.
2017-11-14T21:06:46.398 Installing Microsoft.IdentityModel.Clients.ActiveDirectory 3.13.8.
2017-11-14T21:06:49.197 Installing Newtonsoft.Json 10.0.2.
2017-11-14T21:06:52.171 The user name or password is incorrect.
2017-11-14T21:06:52.189 
2017-11-14T21:06:52.189 
2017-11-14T21:06:52.189 Packages restored.
2017-11-14T21:06:52.500 Script for function 'ProvisionUserToCRM' changed. Reloading.
2017-11-14T21:06:52.813 run.csx(2,18): error CS0234: The type or namespace name 'IdentityModel' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
2017-11-14T21:06:52.813 run.csx(3,8): error CS0246: The type or namespace name 'Newtonsoft' could not be found (are you missing a using directive or an assembly reference?)

有谁知道为什么会显示这个错误?它似乎断断续续地出现在我身上。似乎是 Azure Functions 中的错误。有任何已知的解决方法吗?

我发现在 Azure Functions 上启用 'Slots' 预览功能实际上解决了这个问题,但是 'Slots' 对我不起作用,因为它们与 Azure 逻辑应用程序不兼容。

看起来 Microsoft 已经确认这是 Azure Functions 中的错误 https://github.com/Azure/Azure-Functions/issues/590

我知道的唯一解决方法是:

  • 启用插槽功能
  • 继续重新部署您的 ARM 模板,直到它起作用
  • (我没有验证这一点)但我怀疑如果您手动生成锁定文件并将其放到 Functions 文件系统中,它会起作用。您可以使用 visual studio 在本地生成锁定文件。我怀疑这会起作用,因为据我观察,NuGet 包似乎已正确恢复,并且错误出现在 JSON 文件的写入过程中。编译器在尝试编译时必须引用锁定文件而不是实际的 NuGet 缓存(因此即使 DLL 实际存在也会出现错误)。