[英]Accessing Azure storage account from console app on OSX (Mac)
I am writing code using VS 2017 community edition for Mac and trying to access a Blob on Azure storage account. 我正在使用VS 2017 Community Edition for Mac编写代码,并尝试访问Azure存储帐户上的Blob。 However, I am running into exceptions as shown in the code below.
但是,我遇到了如下代码所示的异常。
The WindowsAzure.Storage version is 9.1.1 WindowsAzure.Storage版本为9.1.1
using System;
using Microsoft.Azure;
using Microsoft.WindowsAzure.Storage;
namespace storageaccount
{
class MainClass
{
public static void Main(string[] args)
{
var storageAccount = CloudStorageAccount.Parse(
CloudConfigurationManager.GetSetting("StorageConnection"));
//var blobClient = storageAccount.CreateCloudBlobClient();
//var container = blobClient.GetContainerReference("images");
//container.CreateIfNotExists(Microsoft.WindowsAzure.Storage.Blob.BlobContainerPublicAccessType.Blob);
//Console.ReadKey();
}
}
}
Exception thrown from the afore-mentioned code: 从上述代码引发的异常:
System.DllNotFoundException: fusion.dll
at at (wrapper managed-to-native) Microsoft.Azure.NativeMethods.CreateAssemblyCache(Microsoft.Azure.NativeMethods/IAssemblyCache&,int)
at Microsoft.Azure.NativeMethods.GetAssemblyPath (System.String name) [0x00037] in <bcbac5dcfbdd47eabe8212983b7d996d>:0
at Microsoft.Azure.AzureApplicationSettings.GetServiceRuntimeAssembly () [0x0000d] in <bcbac5dcfbdd47eabe8212983b7d996d>:0
at Microsoft.Azure.AzureApplicationSettings..ctor () [0x0001a] in <bcbac5dcfbdd47eabe8212983b7d996d>:0
at Microsoft.Azure.CloudConfigurationManager.get_AppSettings () [0x0001e] in <bcbac5dcfbdd47eabe8212983b7d996d>:0
at Microsoft.Azure.CloudConfigurationManager.GetSetting (System.String name, System.Boolean outputResultsToTrace) [0x00039] in <bcbac5dcfbdd47eabe8212983b7d996d>:0
at Microsoft.Azure.CloudConfigurationManager.GetSetting (System.String name) [0x00000] in <bcbac5dcfbdd47eabe8212983b7d996d>:0
at storageaccount.MainClass.Main (System.String[] args) [0x00001] in /Users/Projects/storageaccount/storageaccount/Program.cs:11
What's wrong with the code? 代码有什么问题? I am using Nuget package to access cloud storage account.
我正在使用Nuget程序包访问云存储帐户。 From the exception thrown it is not clear if this is supported on OSx.
从引发的异常尚不清楚OSx是否支持此功能。
Any help is appreciated. 任何帮助表示赞赏。
Additional information: I see that there are two project options in VS 2017 (for Mac) while creating a new project. 附加信息:我看到在创建新项目时,VS 2017(对于Mac)有两个项目选项。 1. .Net core console app 2. .Net console app (under .Net option) - What does this run against?
1. .Net核心控制台应用程序2. .Net控制台应用程序(在.Net选项下)- 此操作针对什么?
Thanks 谢谢
As you mentioned that Microsoft.WindowsAzure.ConfigurationManager is .net framework package, it is not compatible with .net core platform . 如您所提到的,Microsoft.WindowsAzure.ConfigurationManager是.net框架包,它与.net核心平台不兼容 。
I am still looking for information on how to read app.config for .Net application on Mac
我仍在寻找有关如何在Mac上阅读适用于.Net应用程序的app.config的信息
You could use the System.Configuration.ConfigurationManager to do that. 您可以使用System.Configuration.ConfigurationManager来做到这一点。
var storeageString = ConfigurationManager.AppSettings["storagestring"];
App.config App.config中
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="storagestring" value ="Test string"/>
</appSettings>
</configuration>
Another way is that you could add appsettings.json to a .NET Core console app. 另一种方法是,您可以将appsettings.json添加到.NET Core控制台应用程序。
All that's required is to add the following NuGet packages and an appsettings.json file.
所需要做的就是添加以下NuGet包和一个appsettings.json文件。
Microsoft.Extensions.Configuration
Microsoft.Extensions.Configuration
Microsoft.Extensions.Configuration.FileExtensions
Microsoft.Extensions.Configuration.FileExtensions
Microsoft.Extensions.Configuration.Json
Microsoft.Extensions.Configuration.Json
Demo code 演示代码
var builder = new ConfigurationBuilder()
.AddJsonFile("appsettings.json");
IConfigurationRoot configuration = builder.Build();
var connectionString = configuration["StorageConnection"];
Console.WriteLine(connectionString);
appsettings.json file: appsettings.json文件:
{
"StorageConnection": "Test Connection string"
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.