LoginSignup
9
12

More than 3 years have passed since last update.

[.NET Core].NET Coreで実行ファイルを作成する

Last updated at Posted at 2017-03-11

.NET Core3.1で実行ファイルを作成するためのメモ

実行ファイルを作成するといっても事前にネイティブコードにビルドするAOTではなく.NET Coreの本体ごと配布するSelf-contained deployments (SCD)です。

下記のサイトに全部記載されているので詳細はそこで確認してください。
.NET Core Application Deployment

プロジェクトの作成

$ mkdir sample
$ cd sample
$ dotnet new console
Content generation time: 342.4191 ms
The template "Console Application" created successfully.
$ ls
Program.cs    sample.csproj

.csprojを編集

PropetyGroupRuntimeIdentifiersを追加します。
今回はMac向けのバイナリを作成するためにosx.10.11-x64を追加しました。
使用できるRuntimeIdentifierここに記載されています。
複数指定したい場合は;で区切ります。

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp1.1</TargetFramework>
    <RuntimeIdentifiers>osx.10.11-x64</RuntimeIdentifiers>
  </PropertyGroup>
</Project>

ビルド&配置

$ dotnet publish -c release -r osx.10.11-x64

実行

ビルド結果はbin/release/netcoreapp3.1/osx.10.11-x64/publishにあります。
(release, netcoreapp3.1, osx.10.11-x64の部分は設定によって違います。)

$ cd bin/release/netcoreapp3.1/osx.10.11-x64/publish
$ ./sample
Hello World!
9
12
1

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
9
12