2015-06-23 16 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

相关问题