Reputation: 1844
I have a project which is developed with Unity3D. Now I want to add StyleCop to this project.
I have added this awesome package which shows the warnings already in VisualStudio (this is a great benefit over StyleCop Classic). But now I want to see the warnings in Unity and let the build fail. To let the build fail if there are any warnings, I have already added a csc.rsp
file with -warnaserror+
, but unfortunately, I don't have any warnings in Unity.
Is it possible to get the StyleCop-warnings to the Unity-Editor?
Unity-Version 2019.3.0b7 if that matters.
Edit: Another view of the same issue would be:
How to install an analyzer to roslyn?
Unfortunately I the options to install a roslyn analyzer seem to be to install it as nuget package or as Visual Studio extension. But since both ways integrate the errors into Visual Studio, I need another way to add an analyzer to roslyn, which lets the compiler issue errors which then get displayed in Unity3D.
Edit2: To be absolutely clear: I already can do UnityEngine.Debug.LogError
and print every StyleCop error to the UnityConsole. But I want StyleCop to be integrated in the compilation pipeline of unity. So that I cannot press play anymore.
Upvotes: 1
Views: 560
Reputation: 667
Here is a solution if you don't mind to write some little pieces of code.
Unity has an editor log file, it records every warning during your build. Like this:
Assets/SomeScript.cs(134,33): warning CS0618:
UnityEngine.Random.RandomRange(float, float)
is obsolete: UseRandom.Range
instead.
Unity has a callback IPreprocessBuildWithReport.OnPreprocessBuild , which has the following description:
Implement this interface to receive a callback before the build is started.
You can start to monitor the log changes from then on.
Unity also has a callback when a build is end, by adding a PostProcessBuildAttribute to a specific function. Here is the description:
Add this attribute to a method to get a notification just after building the player.
[Update]
EditorApplication.ExitPlaymode()
Upvotes: 0