Reputation: 6882
I'm trying to add an Azure storage account to my ASP.NET Core project (.NET Core 2.0 + VS2017) using Connected Services.
Following this tutorial, Visual Studio should list "Cloud Storage with Azure Storage" in Connected Services, but it doens't. The only item in the list is Application Insights.
I did some research and I read about installing Cloud Explorer for Visual Studio 2017 extension... unfortunately, without success, the only item still being Application Insights.
Is there any workaround or solution for this? If not, how can I connect my project to my Azure Storage account?
Upvotes: 1
Views: 2257
Reputation: 28332
Based on my test, no matter net core 1.1 or 2.0, visual studio 2017 all doesn't support add the azure storage using Connected Services now.
The workaround is connecting to the azure storage account by yourself.
More details, you could refer to below steps:
1.Install the WindowsAzure.Storage from Nuget Package manager.
2.Find the connection string from azure portal.
Find the storage connection string
Directly use the connection string in the project.
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
"yourconnectionstring");
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer container = blobClient.GetContainerReference("brandotest");
// Retrieve reference to a blob named "myblob".
CloudBlockBlob blockBlob = container.GetBlockBlobReference("myblob.txt");
// Create or overwrite the "myblob" blob with contents from a local file.
using (var fileStream = System.IO.File.OpenRead(@"D:\json2.txt"))
{
blockBlob.UploadFromStreamAsync(fileStream);
}
You could also set the connection string in the appsetting.json and inject to your codes. More details, you could refer to this article.
Upvotes: 3