0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Raspberry PiでC#(ASP.NET)のWebアプリを動かす

Last updated at Posted at 2025-01-05

やりたいこと

開発マシン(PC)で作ったASP.NETのWebアプリをRaspberry Piで動かしたい。

技術的要件

ソフト

  • Webアプリ:C#(ASP.NET)

ハード

  • 開発マシン:Windows PC
  • サーバーマシン:Raspberry Pi 3B

手順

開発用PC:ASP.NETアプリを発行する

Visual Studio等を使用して、新しいASP.Netプロジェクトを作成する。
基本的なコーディング以外に下記の2点を行う。

ルーティング設定

同ネットワーク内のPC・スマホからRaspberryPiにアクセスするため、IPアドレス0.0.0.0にサーバーが立ち上がるように設定する。
※ポート番号はWebアプリが立ち上がるポートに合わせる。

var builder = WebApplication.CreateBuilder(args);

// raspi用に追加
builder.WebHost.UseUrls("http://0.0.0.0:44400");

発行

  1. プロジェクトを右クリック>発行
  2. ターゲット:フォルダ を選択後、完了
  3. すべての設定を表示>ターゲットランタイム:linux-arm を選択image.png
  4. 保存後、発行

Raspberry Pi:dotnetコマンドのインストール&実行

dotnetダウンロード

.Netのダウンロードページ(https://dotnet.microsoft.com/ja-jp/download/dotnet) から、対応するバージョンのバイナリ(Arm32)をダウンロードする。
image.png
ブラウザからダウンロードするか、以下のようにwgetコマンドを使う。

wget https://download.visualstudio.microsoft.com/download/pr/4b1d565b-7a3d-4e7e-87ad-7c662ec59020/4c6cb8a150efb42f7cea7e0b4c2f61cf/dotnet-sdk-7.0.410-linux-arm.tar.gz

解凍する。

tar xvfz  dotnet-sdk-7.0.410-linux-arm.tar.gz

dotnetコマンドが実行可能であることを確認する。

[解凍したフォルダ]/dotnet --version

実行ファイルをRaspberry Piに転送する

開発マシンで発行した実行ファイルをRaspberry Piに転送する。

  1. bin>Releaseフォルダ配下のPublishフォルダをzip化する
  2. TeraTerm の ファイル>SSH SCP でzipファイルをRasPiのフォルダに転送する。
  3. RasPi側でunzipコマンドを使ってzipファイルを解凍する。

Raspberry Piで実行する

dotnetコマンドを使用して実行ファイル(.dll)を実行する。

[解凍したフォルダ]/dotnet XXXXX.dll

PCからアクセスできることが確認できた!

参考にさせて頂いた記事

Raspberry Pi で .Net を使う
ASP.NET Core webアプケーションを公開する

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?