BannedApiAnalyzers.Unity 1.0.2

dotnet add package BannedApiAnalyzers.Unity --version 1.0.2
                    
NuGet\Install-Package BannedApiAnalyzers.Unity -Version 1.0.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="BannedApiAnalyzers.Unity" Version="1.0.2">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="BannedApiAnalyzers.Unity" Version="1.0.2" />
                    
Directory.Packages.props
<PackageReference Include="BannedApiAnalyzers.Unity">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add BannedApiAnalyzers.Unity --version 1.0.2
                    
#r "nuget: BannedApiAnalyzers.Unity, 1.0.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package BannedApiAnalyzers.Unity@1.0.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=BannedApiAnalyzers.Unity&version=1.0.2
                    
Install as a Cake Addin
#tool nuget:?package=BannedApiAnalyzers.Unity&version=1.0.2
                    
Install as a Cake Tool

BannedApiAnalyzers for Unity

Build NuGet

A Unity-focused fork of Microsoft.CodeAnalysis.BannedApiAnalyzers that uses Unity additional files instead of BannedSymbols.txtno .csproj edits required.

[!NOTE]
This package is based on dotnet/roslyn-analyzers v3.11.0.

[!NOTE]
Unity additional files require Unity 2021.3 or later.

Analyzer Rules

RS0030 — Do not use banned APIs

The symbol has been marked as banned in this project, and an alternate should be used instead.

Item Value
Category ApiDesign
Enabled True
Severity Warning
CodeFix False

RS0031 — The list of banned symbols contains a duplicate

The list of banned symbols contains a duplicate.

Item Value
Category ApiDesign
Enabled True
Severity Warning
CodeFix False

RS0035 — External access to internal symbols outside the restricted namespace(s) is prohibited

RestrictedInternalsVisibleToAttribute enables a restricted version of InternalsVisibleToAttribute that limits access to internal symbols to those within specified namespaces. Each referencing assembly can only access internal symbols defined in the restricted namespaces that the referenced assembly allows.

Item Value
Category ApiDesign
Enabled True
Severity Error
CodeFix False

Usage

1. Install the analyzer package

Install BannedApiAnalyzers.Unity from a package registry using either NuGetForUnity or UnityNuGet.

NuGetForUnity
  1. Open the NuGetForUnity window via NuGet > Manage NuGet Packages
  2. Search "BannedApiAnalyzers.Unity" and click Install
UnityNuGet (hosted on OpenUPM)
  1. Install the package:

    openupm add org.nuget.BannedApiAnalyzers.Unity
    
  2. Open the .asmdef of each assembly you want the analyzer to apply to, and add BannedApiAnalyzers.Unity_Unity to its Assembly Definition References.

[!TIP]
Analyzers installed via NuGetForUnity apply to all assemblies in the project (including those in the PackageCache), while analyzers installed via UnityNuGet apply only to the referenced assembly and any assemblies that depend on it.

2. Create a banned symbols additional file

Create one or more files named according to the pattern <Filename>.BannedApiAnalyzers.Unity.additionalfile (the <Filename> part must not contain a period) and place them anywhere under Assets/:

  • BannedSymbols.BannedApiAnalyzers.Unity.additionalfile
  • Platform.BannedApiAnalyzers.Unity.additionalfile (one file per concern)

Unity automatically discovers .additionalfile files in Assets/ and passes them to the analyzer — no .csproj edits required.

For more details on Unity's additional files feature, see Additional files for Roslyn analyzers and source generators.

3. Add entries to the banned symbols file

To add a symbol to the banned list, just add an entry in the format below to one of the additional files (Description Text will be displayed as description in diagnostics, which is optional):

{Documentation Comment ID string for the symbol}[;Description Text]

Comments can be indicated with //, in the same way that they work in C#.

For details on ID string format, please refer to "ID string format".

Examples of banned symbols entries for symbols declared in the source below:

namespace N
{
    class BannedType
    {
        public BannedType() {}
        public int BannedMethod() {}
        public void BannedMethod(int i) {}
        public void BannedMethod<T>(T t) {}
        public void BannedMethod<T>(Func<T> f) {}
        public string BannedField;
        public string BannedProperty { get; }
        public event EventHandler BannedEvent;
    }

    class BannedType<T> {}
}
Symbol in Source Sample Entry in *.BannedApiAnalyzers.Unity.additionalfile
class BannedType T:N.BannedType;Don't use BannedType
class BannedType<T> T:N.BannedType`1;Don't use BannedType<T>
BannedType() M:N.BannedType.#ctor
int BannedMethod() M:N.BannedType.BannedMethod
void BannedMethod(int i) M:N.BannedType.BannedMethod(System.Int32);Don't use BannedMethod
void BannedMethod<T>(T t) M:N.BannedType.BannedMethod`1(``0)
void BannedMethod<T>(Func<T> f) M:N.BannedType.BannedMethod`1(System.Func{``0})
string BannedField F:N.BannedType.BannedField
string BannedProperty { get; } P:N.BannedType.BannedProperty
event EventHandler BannedEvent; E:N.BannedType.BannedEvent
namespace N N:N

License

MIT — see License.txt.

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.2 153 7/6/2026
1.0.1 239 6/12/2026
1.0.0 242 6/12/2026