Unity プロジェクトが、デフォルトでコンパイルされない .NET クラスライブラリ API の一部にアクセスする必要がある場合、プロジェクトは Unity の C# コンパイラーに通知できます。この動作は、プロジェクトが使用する .NET プロファイルによって異なります。
プロジェクトで .NET Standard 2.0 の Api Compatibility Level (API の互換性レベル) を使用する場合は、.NET クラスライブラリ API の一部を使用するために追加の手順を行う必要はありません。API の一部が見つからない場合は、.NET Standard 2.0 に含まれていない場合があります。代わりに、プロジェクトで .NET 4.x の Api Compatibility Level を使用しなければならない場合があります。
デフォルトでは、.NET 4.x の Api Compatibility Level を使用する場合、Unityは以下のアセンブリを参照します。
他のクラスライブラリアセンブリを参照するには、csc.rsp ファイルを使用する必要があります。このファイルを Unity プロジェクトの Assets ディレクトリに追加し、それを使って追加のコマンドライン引数を C# コンパイラーに渡すことができます。例えば、System.Net.Http.dll アセンブリで定義された HttpClient
クラスをプロジェクトで使用すると、C# コンパイラーは以下の初期エラーメッセージを出力する場合があります。
The type `HttpClient` is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. (タイプ `HttpClient` は参照されていないアセンブリで定義されています。アセンブリに参照を加える必要があります。'System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' )
このエラーは、以下の csc.rsp ファイルをプロジェクトに加えることによって解決できます。
-r:System.Net.Http.dll
上記の例で説明したように、クラスライブラリアセンブリを参照する必要があります。それらは、Project ディレクトリにコピーしないでください。
クラスライブラリアセンブリを参照するために csc.rsp ファイルを使用する場合は注意が必要です。Api Compatibility Level を .NET 4.x から .NET Standard 2.0 に変更し、上記の例のような csc.rsp がプロジェクトに存在する場合、C# コンパイルは失敗します。 System.Net.Http.dll アセンブリが .NET Standard 2.0 プロファイルに存在しないため、C# コンパイラーは .NET Standard 2.0 プロファイルを見つけることができません。
csc.rsp ファイルには、現在の .NET プロファイル専用の部分を作ることができます。プロファイルに変更を加える場合は、csc.rsp ファイルを変更する必要があります。
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.