在Azure函数中使用Microsoft.WindowsAzure.Management.WebSites时出错

时间:2017-03-01 10:58:08

标签: c# azure azure-functions azure-management-api

在我的Azure功能中,我引用了Microsoft.WindowsAzure.Management.WebSites程序集

{
  "frameworks": {
    "net46":{
      "dependencies": {
        "Microsoft.WindowsAzure.Management.WebSites": "4.0.0"
      }
    }
   }
}

并尝试使用WebSiteManagementClient

var client = new WebSiteManagementClient(
    new Microsoft.WindowsAzure.CertificateCloudCredentials("my sub ID", cert));

但它失败并出现错误:

Microsoft.WindowsAzure.Common: 
The type initializer for 'Microsoft.WindowsAzure.Common.ServiceClient`1'
threw an exception. Microsoft.WindowsAzure.Common: Operation is not 
supported on this platform.

在日志中我可以看到

Unable to find assembly 'Microsoft.WindowsAzure.Common.NetFramework'. Are you missing a private assembly file?
Unable to find assembly 'Microsoft.WindowsAzure.Common.WindowsStore'. Are you missing a private assembly file?
Unable to find assembly 'Microsoft.WindowsAzure.Common.WindowsPhone'. Are you missing a private assembly file?
Unable to find assembly 'Microsoft.WindowsAzure.Common.WindowsPhone81'. Are you missing a private assembly file?
Unable to find assembly 'Microsoft.WindowsAzure.Common.Silverlight'. Are you missing a private assembly file?
Unable to find assembly 'Microsoft.WindowsAzure.Common.Test'. Are you missing a private assembly file?

我也尝试引用所有依赖的NuGet包,但没有运气来修复错误。

我错过了什么?

1 个答案:

答案 0 :(得分:0)

添加以下项目解决了问题。

 //Add in run.csx
 using Microsoft.WindowsAzure.Management.WebSites; 

在project.json

中添加以下JSON配置
    {
      "frameworks": {
        "net46":{
         "dependencies": {
         "Microsoft.WindowsAzure.Management.WebSites": "4.0.0",
         "Microsoft.WindowsAzure.Common": "1.4.1"
         }
        }
       }
      }

有关其他信息: 我也试过最新的预发布版本,

    "Microsoft.WindowsAzure.Management.WebSites": "5.0.0-prerelease"

Azure功能也适用于预发行版。