拡張機能用のC#プロジェクトを作成

この記事の内容

Beutl拡張機能用に空のC#プロジェクトを作成する方法を説明します。

この記事では、Visual Studio CodeVisual Studio を使う方法を紹介します。 また、対象とするBeutlのバージョンは1.0.0-preview.6とします。

Visual Studio Code

  1. ターミナルを使用して、クラスライブラリを作成します。
dotnet new classlib -o MyBeutlExtension

ディレクトリ構造が以下のようになることをご確認ください。

MyBeutlExtension
┣━ obj
┃  ┗━ (...)
┣━ Class1.cs
┗━ MyBeutlExtension.csproj
  1. 生成された MyBeutlExtension.csproj を以下のように編集します。
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <!-- TargetFrameworkはBeutlのバージョンに応じて変更してください -->
    <TargetFramework>net8.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>

    <!-- 以下は任意です。 -->
    <RepositoryUrl>url/to/repository</RepositoryUrl>
    <PackageId>MyBeutlExtension</PackageId>
    <Title>拡張機能のサンプル</Title>
    <Description>サンプル</Description>
    <PackageTags>sample</PackageTags>
    <Version>1.0.0</Version>
    <AssemblyVersion>1.0.0.0</AssemblyVersion>
    <Authors>作者名</Authors>
  </PropertyGroup>

  <!-- ビルドしたときに、サイドロード拡張機能として認識されるようにする。 -->
  <PropertyGroup Condition="'$(Configuration)'=='Debug'">
    <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
    <AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
    <EnableDynamicLoading>true</EnableDynamicLoading>
    <OutputPath>$([System.Environment]::GetFolderPath(SpecialFolder.UserProfile))\.beutl\sideloads\$(AssemblyName)</OutputPath>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Beutl.Extensibility" Version="1.0.0-preview.6" />
    <PackageReference Include="Beutl.ProjectSystem" Version="1.0.0-preview.6" />
    <PackageReference Include="Beutl.Operators" Version="1.0.0-preview.6" />
  </ItemGroup>

</Project>
  1. 以下のコマンドを実行して、nuget.config を生成し、パッケージソースを追加します。
dotnet new nugetconfig
dotnet nuget add source "https://nuget.beditor.net/v3/index.json" --name nuget.beditor.net

以上で拡張機能用に空のC#プロジェクトを作成することができました。

Visual Studio

  1. Visual Studio を開いて、ファイル > 新規作成 > プロジェクト をクリックします。
    Visual Studioプロジェクトを作成

  2. クラスライブラリを選択して、次へをクリックします。
    クラスライブラリを選択

  3. プロジェクト名、場所を入力して次へをクリックします。 プロジェクト名、場所を入力

  4. フレームワークはBeutlのバージョンに応じて選択してください。

  5. 作成をクリックします。

ディレクトリ構造が以下のようになることをご確認ください。

MyBeutlExtension
┣━ MyBeutlExtension
┃  ┣━ obj
┃  ┃  ┗━ (...)
┃  ┣━ Class1.cs
┃  ┗━ MyBeutlExtension.csproj
┗━ MyBeutlExtension.sln
  1. 生成された MyBeutlExtension.csproj を以下のように編集します。
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <!-- TargetFrameworkはBeutlのバージョンに応じて変更してください -->
    <TargetFramework>net8.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>

    <!-- 以下は任意です。 -->
    <RepositoryUrl>url/to/repository</RepositoryUrl>
    <PackageId>MyBeutlExtension</PackageId>
    <Title>拡張機能のサンプル</Title>
    <Description>サンプル</Description>
    <PackageTags>sample</PackageTags>
    <Version>1.0.0</Version>
    <AssemblyVersion>1.0.0.0</AssemblyVersion>
    <Authors>作者名</Authors>
  </PropertyGroup>

  <!-- ビルドしたときに、サイドロード拡張機能として認識されるようにする。 -->
  <PropertyGroup Condition="'$(Configuration)'=='Debug'">
    <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
    <AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
    <EnableDynamicLoading>true</EnableDynamicLoading>
    <OutputPath>$([System.Environment]::GetFolderPath(SpecialFolder.UserProfile))\.beutl\sideloads\$(AssemblyName)</OutputPath>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Beutl.Extensibility" Version="1.0.0-preview.6" />
    <PackageReference Include="Beutl.ProjectSystem" Version="1.0.0-preview.6" />
    <PackageReference Include="Beutl.Operators" Version="1.0.0-preview.6" />
  </ItemGroup>

</Project>
  1. 以下のコマンドを実行して、nuget.config を生成し、パッケージソースを追加します。
dotnet new nugetconfig
dotnet nuget add source "https://nuget.beditor.net/v3/index.json" --name nuget.beditor.net
  1. NuGetパッケージの復元 をクリックして、正常にNuGet依存関係を復元できることをご確認ください。
    NuGetパッケージを復元

以上で拡張機能用に空のC#プロジェクトを作成することができました。

GitHub LogoGitHubで表示この記事のソースはGitHubにあります。<br />改善点があればIssueやPull requestを開いてください。

この記事の内容