Download uploaded cspkg file from Azure

后端 未结 3 466
无人及你
无人及你 2020-12-20 17:37

Can I download the cspkg from Azure that I uploaded (rather than reuploading new package)?

The scenario is -

I need to add files into existing website - let

相关标签:
3条回答
  • 2020-12-20 18:22

    [The paragraph below is incorrect]

    Currently there is no API or mechanism which can download the exact same CSPKG directly from Windows Azure Portal which was uploaded. This sure is a big requirement from Windows Azure user specially when you loose your Windows Azure Project/Solution.

    [Edit- Correction to above paragraph]

    Using "Get Package" REST API you can download the package from specific deployment to your Azure Blog storage. IF you decide to write your own C# application to use REST API the sample is here. If you don't want to write API and just download the package using REST call, there are a few tools and I have used BURP (based on Java) as described in my blog here. You can use the info in the blog to setup connect to Azure Portal and then use REST call as documented to get the package.

    Next even if you download the CSPKG (or have a local copy of CSPKG) still you can not edit it by adding or removing any content directly to it because this will break the CSPKG package integrity and you will get an error uploading it. The package must be created using CSPACK tool.

    The Drive E:\ where your approot is does include most of your compiled code so if you can download it locally and come up with an idea to build a new project form that (???), that could be an option. If the package was created directly using CSPACK tool and the downloading the files from drive E:\ and recreating the package does work however if the project the a complex application included source and compiled code files i.e. ASP.NET/MVCx application, it is tough.

    0 讨论(0)
  • 2020-12-20 18:31

    I faced the similar issue,

    What I did was,

    Use Get-Package REST API calls to store cspkg and cscfg files in a storage container.

    Remember this storage container should be in under the same subscription, otherwise Get-Package REST API calls will fail.

    Then I used AzCopy (http://blogs.msdn.com/b/windowsazurestorage/archive/2012/12/03/azcopy-uploading-downloading-files-for-windows-azure-blobs.aspx) , to copy files from the storage container to my local disks.

    You can also use AzCopy to copy from one StorageContainer to another, even under different subscriptions.

    Let me know if you need more details.

    0 讨论(0)
  • 2020-12-20 18:37

    Using the Windows Azure Service Management Library NuGet Package, the C# code to get the package becomes:

    private static X509Certificate2 GetCertificate(string storeName, string thumbprint)
    {
        var store = new X509Store(storeName);
        store.Open(OpenFlags.ReadOnly);
        return store.Certificates.Find(X509FindType.FindByThumbprint, thumbprint, true)[0];
    }
    
    public static void ExportPackage(X509Certificate2 certificate, string subscriptionId, string serviceName, string deploymentName, string containerUri)
    {
        var managementService = ServiceManagementHelper.CreateServiceManagementChannel("WindowsAzureEndPoint", certificate);
    
        try
        {
            managementService.GetPackage(
                subscriptionId,
                serviceName,
                deploymentName,
                containerUri,
                true /*overwriteExisting*/);
        }
        catch (Exception ex)
        {
            System.Net.WebException exception = ex.InnerException as System.Net.WebException;
            if (exception != null)
            {
                string responseText;
    
                using (var reader = new System.IO.StreamReader(exception.Response.GetResponseStream()))
                {
                    responseText = reader.ReadToEnd();
                    Console.WriteLine("ERROR:" + exception);
                    Console.WriteLine(responseText);
                }
            }
        }
    }
    

    My problem, however, is that no matter what I pass in as the containerUri, I get back 400 Bad request - Parameter value 'something.blob.core.windows.net/somecontainer'; specified for parameter 'ContainerUriString' is invalid.

    Update: my problem was due to the storage container belonging to a different subscription - that was obviously not working. I made sure the container belonged to the same subscription, and voila!

    Update: This code assumes the following app.config:

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
    </startup>
    <system.serviceModel>
        <bindings>
            <webHttpBinding>
                <binding name="WindowsAzureServiceManagement_WebHttpBinding" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00">
                    <readerQuotas maxStringContentLength="1048576" maxBytesPerRead="131072"/>
                    <security mode="Transport">
                        <transport clientCredentialType="Certificate"/>
                    </security>
                </binding>
            </webHttpBinding>
        </bindings>
        <client>
            <endpoint name="WindowsAzureEndPoint" address="https://management.core.windows.net" binding="webHttpBinding" bindingConfiguration="WindowsAzureServiceManagement_WebHttpBinding" contract="Microsoft.Samples.WindowsAzure.ServiceManagement.IServiceManagement" />
        </client>
    </system.serviceModel>
    </configuration>
    

    or, alternatively, for LinqPad users, you can configure web service inline as follows:

            var b = new WebHttpBinding(WebHttpSecurityMode.Transport);
            b.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;
            var address = new EndpointAddress("https://management.core.windows.net");
            var managementService = ServiceManagementHelper.CreateServiceManagementChannel(b, address.Uri, certificate);
    

    Typical use:

    X509Certificate2 certificate = GetCertificate("My", "NNNNNNNNNNNNN");
    ExportPackage(certificate,
                "00000000-0000-0000-0000-000000000000",
                "yourservice",
                "00000000000000000000000000000000",
                "https://yourstorage.blob.core.windows.net/container");
    
    0 讨论(0)
提交回复
热议问题