暗黙的な global using でインポートされるアセンブリ

暗黙的な global using でインポートされるアセンブリを紹介します。

概要

暗黙的な global usingでインポートされるアセンブリは、プロジェクトの/obj/Debug/(.NETバージョン) /obj/Release/(.NETバージョン) フォルダ内の (プロジェクト名).GlobalUsings.g.cs ファイルに記述されます。
(プロジェクト名).GlobalUsings.g.csファイルの内容は、.NET SDK がプロジェクトの種類や対象フレームワークに応じて内部的に決定しています。

(プロジェクト名).GlobalUsings.g.cs

(プロジェクト名).GlobalUsings.g.cs ファイルの内容は以下の通りです。

Windows Formアプリケーションの場合は以下になります。

// <auto-generated/>
global using global::System;
global using global::System.Collections.Generic;
global using global::System.Drawing;
global using global::System.IO;
global using global::System.Linq;
global using global::System.Net.Http;
global using global::System.Threading;
global using global::System.Threading.Tasks;
global using global::System.Windows.Forms;


ASP.NET Coreアプリケーションの場合。

// <auto-generated/>
global using global::Microsoft.AspNetCore.Builder;
global using global::Microsoft.AspNetCore.Hosting;
global using global::Microsoft.AspNetCore.Http;
global using global::Microsoft.AspNetCore.Routing;
global using global::Microsoft.Extensions.Configuration;
global using global::Microsoft.Extensions.DependencyInjection;
global using global::Microsoft.Extensions.Hosting;
global using global::Microsoft.Extensions.Logging;
global using global::System;
global using global::System.Collections.Generic;
global using global::System.IO;
global using global::System.Linq;
global using global::System.Net.Http;
global using global::System.Net.Http.Json;
global using global::System.Threading;
global using global::System.Threading.Tasks;


ASP.NET Core Blazorアプリケーションの場合。

// <auto-generated/>
global using global::Microsoft.Extensions.Configuration;
global using global::Microsoft.Extensions.DependencyInjection;
global using global::Microsoft.Extensions.Logging;
global using global::System;
global using global::System.Collections.Generic;
global using global::System.IO;
global using global::System.Linq;
global using global::System.Net.Http;
global using global::System.Threading;
global using global::System.Threading.Tasks;

暗黙的な global usingを利用しない場合に追記するusing

暗黙的な global usingを利用しない場合に追記が必要となるusing次の通りです。
以下のusingから、ビルドに必要なusingを追加します。

Windows Form アプリケーション

using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

ASP.NET Core アプリケーション

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Json;
using System.Threading;
using System.Threading.Tasks;

ASP.NET Core Blazor アプリケーション

using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
AuthorPortraitAlt
著者
iPentecのメインプログラマー
C#, ASP.NET の開発がメイン、少し前まではDelphiを愛用
作成日: 2025-01-20
Copyright © 1995–2025 iPentec all rights reserverd.