Powershell コマンドを使用してログインするのと同じ方法で Azure に接続したいと考えています。.NET でこれを行うための API が見つからなかったので、PS スクリプトを .NET で実行することをお勧めします。
ラップトップに azure 用の Powershell を既にインストールしています
Install-Module -Name Az -AllowClobber
また、PC の Windows Powershell だけで「Connect-AzAccount」コマンドを使用しようとしましたが、正常に動作しました。
そこで、Visual Studio で次のことを試しました。
using System.Management.Automation;
namespace AzureTestVM
{
class Program
{
static void Main(string[] args)
{
PowerShell ps = PowerShell.Create().AddCommand("Connect-AzAccount");
ps.Invoke();
}
}
}
問題は、次のエラーが発生することです。
Unhandled Exception: System.Management.Automation.CmdletInvocationException: Method
'get_SerializationSettings' on type'
Microsoft.Azure.Management.Internal.Resources.ResourceManagementClient 'of assembly'
Microsoft.Azure.PowerShell.Clients.ResourceManager, Version = 1.0. 0.0, Culture = neutral,
PublicKeyToken = 31bf3856ad364e35 'does not have an implementation. --->
System.TypeLoadException: Method 'get_SerializationSettings' on type'
Microsoft.Azure.Management.Internal.Resources.ResourceManagementClient 'of assembly'
Microsoft.Azure.PowerShell.Clients.ResourceManager, Version = 1.0.0.0, Culture = neutral,
PublicKeyToken = 31bf3856ad364e35 'does not have an implementation.