SQLの窓

2020年09月21日


nuget.exe CLI を使用してパッケージをダウンロードし、C# のソースコードで利用して PowerShell でビルドする

 ps.bat ( PowerShell をそのまま使えない場合は以下のバッチファイルを作成して使用します )
@powershell -NoProfile -ExecutionPolicy Unrestricted "./%1.ps1"
nuget.exe - recommended latest のダウンロードページ nuget.exe CLI を使用してパッケージを管理する( Microsoft のドキュメント )
nuget.exe を最新にするには
nuget update -Self

ここで使用するパッケージの最新バージョンの確認は こちらから 行って以下のコマンドライン
nuget install Newtonsoft.Json -Version バージョン
json_sample_01.cs
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Web;
using System.Windows.Forms;
using Newtonsoft.Json;

public class Program
{
	public static void Main()
	{
		ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;	

		string url = "https://lightbox.sakura.ne.jp/demo/json/syain_json.php";
		
		string json = "";

		using( WebClient wc = new WebClient() ) {
			wc.Encoding = Encoding.UTF8;
			json = wc.DownloadString( url );
		}

		Syain[] syain = JsonConvert.DeserializeObject<Syain[]>(json);

		foreach (Syain data in syain) {
			Console.WriteLine( data.社員コード );
			Console.WriteLine( data.氏名 );
			Console.WriteLine( data.フリガナ );
		}

		MessageBox.Show("処理が終了しました");

	}

	private class Syain
	{
		public string 社員コード  { get; set; }
		public string 氏名  { get; set; }
		public string フリガナ  { get; set; }
	}

}


build.ps1

Newtonsoft.Json.dll は、ソースコードと同じ場所に置きます
Add-Type -path "json_sample_01.cs" `
	-ReferencedAssemblies "Newtonsoft.Json.dll", System.Web, System.Windows.Forms `
	-OutputAssembly json_sample_01.exe `
	-OutputType ConsoleApplication

Read-Host "何かキーを押してください"


run.ps1

Newtonsoft.Json.dll は、ソースコードと同じ場所に置きます
Add-Type -path "Newtonsoft.Json.dll"
Add-Type -path "json_sample_01.cs" `
	-ReferencedAssemblies "Newtonsoft.Json.dll", System.Web, System.Windows.Forms

[Program]::Main()

Read-Host "何かキーを押してください"




posted by lightbox at 2020-09-21 18:32 | PowerShell + C# | このブログの読者になる | 更新情報をチェックする
container 終わり



フリーフォントで簡単ロゴ作成
フリーフォントでボタン素材作成
フリーフォントで吹き出し画像作成
フリーフォントではんこ画像作成
ほぼ自由に利用できるフリーフォント
フリーフォントの書体見本とサンプル
画像を大きく見る為のウインドウを開くボタンの作成

CSS ドロップシャドウの参考デモ
イラストAC
ぱくたそ
写真素材 足成
フリーフォント一覧
utf8 文字ツール
右サイド 終わり
base 終わり