2015-06-23 19 views
0

這裏是我使用部署在Azure中的服務代碼,使用Azure管理庫來部署服務。錯誤:「給定路徑的格式不受支持。」

internal async static Task DeployCloudService(this SubscriptionCloudCredentials credentials) 
     { 
      try 
      { 
       using (var _computeManagementClient = new ComputeManagementClient(credentials)) 
       { 
        Console.WriteLine("Deploying a service..."); 
        var storageConnectionString = await GetStorageAccountConnectionString(credentials); 

        var account = CloudStorageAccount.Parse(storageConnectionString); 

        var blobs = account.CreateCloudBlobClient(); 

        var container = blobs.GetContainerReference(ConfigurationManager.AppSettings["containerName"]); 

        if (!container.Exists()) { Console.WriteLine("Container not found"); }; 

        await container.SetPermissionsAsync(
         new BlobContainerPermissions() 
         { 
          PublicAccess = BlobContainerPublicAccessType.Container 
         }); 

        var blob = container.GetBlockBlobReference(
         Path.GetFileName(ConfigurationManager.AppSettings["packageFilePath"])); 
        var blob1 = container.GetBlockBlobReference(
         Path.GetFileName(ConfigurationManager.AppSettings["configFilePath"])); 
        await _computeManagementClient.Deployments.CreateAsync(ConfigurationManager.AppSettings["serviceName"], 
          DeploymentSlot.Production, 
          new DeploymentCreateParameters 
          { 
           Label = ConfigurationManager.AppSettings["label"], 
           Name = ConfigurationManager.AppSettings["serviceName"], 
           PackageUri = blob.Uri, 
           Configuration = File.ReadAllText((blob1.Uri).ToString()), 
           StartDeployment = true 
          }); 
        Console.WriteLine("Deployment Done!!!"); 
       } 
      } 
      catch (Exception e) { 
       throw; 
      } 
     } 

的想法是,包和配置文件已經存在在斑點一些容器內,我可以當我使用部署我的服務Configuration = File.ReadAllText(ConfigurationManager.AppSettings["configFilePath"])(從本地路徑獲取文件並按預期正常工作),但是因爲我不想這樣做,所以我嘗試使用Azure blob中的配置文件,但是File.ReadAllText未使用我的文件的Uri,而我檢查是否正常並給出System.SystemException {System.NotSupportedException}base {"The given path's format is not supported."}。(如查找字符串參數)

My Question is that how can we use the config file (.cscfg) from the server

回答

0

您可以使用DownloadText方法嘗試讀取blob的內容。喜歡的東西:

new DeploymentCreateParameters 
          { 
           Label = ConfigurationManager.AppSettings["label"], 
           Name = ConfigurationManager.AppSettings["serviceName"], 
           PackageUri = blob.Uri, 
           Configuration = blob1.DownloadText(), 
           StartDeployment = true 
          }); 
+0

有沒有像'DownloadText()'方法 – ashishraaj

+0

肯定有:https://msdn.microsoft.com/en-us/library/microsoft.windowsazure.storage.blob.cloudblockblob。 downloadtext.aspx –

+0

那麼也許這不是正確的方法,無論如何謝謝@Gaurav。如果我有什麼,我會評論。 – ashishraaj

相關問題