Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CloudConfigurationManager incompatible with .NetCoreApp

I have been trying to access Azure's Blob Storage in dotnet core with the following line of code:

CloudStorageAccount account = CloudStorageAccount.Parse(
            CloudConfigurationManager.GetSetting("<MyStorageName>_AzureStorageConnectionString")
            );

Beforehand I have installed the required Azure SDK, and updated it to the dotnet core compatible version, then, since CloudConfigurationManager was missing, I installed Microsoft.WindowsAzure.ConfigurationManager, according to this answer. After having updated this package as well, Package restore failed with the following error message:

Package Microsoft.WindowsAzure.ConfigurationManager 3.2.1 is not compatible with netcoreapp1.0 (.NETCoreApp,Version=v1.0). Package Microsoft.WindowsAzure.ConfigurationManager 3.2.1 supports: net40 (.NETFramework,Version=v4.0)
One or more packages are incompatible with .NETCoreApp,Version=v1.0.

Is there any option in order to get CloudConfigurationManager working or do I need to find a workaround?

like image 337
WizardOfMenlo Avatar asked Sep 27 '16 18:09

WizardOfMenlo


1 Answers

Package Microsoft.WindowsAzure.ConfigurationManager 3.2.1 is not compatible with netcoreapp1.0 (.NETCoreApp,Version=v1.0). Package Microsoft.WindowsAzure.ConfigurationManager 3.2.1 supports: net40 (.NETFramework,Version=v4.0)

In ASP.NET Core, the settings have been moved to appsettings.json. As far as I know, using CloudConfigurationManager with .NETCoreApp is not supported by now.

For a workaround, you could follow the code below to implement your account:

CloudStorageAccount account = new CloudStorageAccount(
    new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials(
        "<storage-accountname>",
        "<storage-accountkey>"), true);

Additionally, you could refer to this related SO thread. Also, for a better understanding of Configuration in .NET Core, you could follow this tutorial.

like image 61
Bruce Chen Avatar answered Sep 30 '22 06:09

Bruce Chen