https://github.com/needle-tools/unity-analyzers-starter
Custom Analyzers Sample / Starter
https://github.com/needle-tools/unity-analyzers-starter
Last synced: 10 months ago
JSON representation
Custom Analyzers Sample / Starter
- Host: GitHub
- URL: https://github.com/needle-tools/unity-analyzers-starter
- Owner: needle-tools
- Created: 2022-03-17T18:54:52.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2023-07-04T13:12:47.000Z (almost 3 years ago)
- Last Synced: 2025-08-18T09:52:16.709Z (10 months ago)
- Language: C#
- Homepage:
- Size: 127 KB
- Stars: 12
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Unity Analyzer test/dev package.
The included solution is setup to copy the dll to the package on build time
## Introduction
- Analyzers are dlls in Unity
- They apply globally if they are outside of an asmdef (can be inside a package) or locally when inside a package
- Dll settings: turn everything off (Auto Reference, Validate References, Any Platform, Editor, Standalone) and add an AssetTag named "RoslynAnalyzer" (the tags ui is not visible inside packages...)
### Examples of Analyzers usage (included in this template)
- Analyzers allow you to run fixes in your IDE:

- Analyzers allow you to produce logs, warnings, errors or even compiler errors

## Updating the Analyzer
- Open ``analyzers/UnityAnalyzers.sln``
- Build ``UnityAnalyzers.csproj``
- The dll is copied to the ``package`` folder on build and Unity reimports the dll. Done.
## Unity Documentation
- https://docs.unity3d.com/2021.2/Documentation/Manual/roslyn-analyzers.html
- **NOTE**: to add the necessary AssetLabel ``RoslynAnalyzer`` the dll must be copied to the Assets folder to show the UI (and can then go to the package)
There are also [two more labels mentiond](https://github.com/needle-mirror/com.unity.entities/blob/2b7ad3ab445aff771ddffa3dd9d330f21fb1dd70/Unity.Entities/SourceGenerators/Source~/README.md?plain=1#L59) `SourceGenerator` and `RunOnlyOnAssembliesWithReference`
Alternativelly you can edit the dll meta manually to add the label:
```meta
guid: ...
labels:
- RoslynAnalyzer
PluginImporter:
...
```
- [Debugging SourceGenerators](https://github.com/needle-mirror/com.unity.entities/blob/2b7ad3ab445aff771ddffa3dd9d330f21fb1dd70/Unity.Entities/SourceGenerators/Source~/README.md?plain=1#L25)
## Debugging
```csharp
#if DEBUG
if (!Debugger.IsAttached)
{
Debugger.Launch();
}
#endif
```
When using Rider set Rider as the default JIT debugger in Settings/Debugger and clicking the `Set As Default Debugger` button

## Other Resources
- https://github.com/microsoft/Microsoft.Unity.Analyzers
- https://github.com/Cybermaxs/awesome-analyzers