- Home /
How to force warnings as errors?
I've always considered it a best practive to crank the warning level of the compiler as high as it will go and to set warnings to be errors (so they break the build). This is a really good way to ensure that your team always writes 'solid' code because often warnings have valid risks associated with them.
Is it possible set warnings to be flagged as errors in Unity? And is it also possible to crank up warning level?
Thanks!
Answer by keely · Jun 13, 2012 at 10:17 PM
Create a text file in ProjectFolder/Assets/smcs.rsp
Everything in that file will end up as compiler command-line parameters
The parameter to force warnings as errors is -warnaserror+
, so add this to the smcs.rsp
If you are interested in other available parameters, run UnityInstallFolder/editor/data/bin/smcs /?
As a note on OSX it's the path to your unity.app then "/Contents/Frameworks/$$anonymous$$ono/bin/smcs /?" i.e.
/Applications/Unity/Unity.app/Contents/Frameworks/$$anonymous$$ono/bin/smcs /?
If your project contains C#-Editor scripts, you should edit too the file gmcs.rsp
See: https://docs.unity3d.com/Documentation/$$anonymous$$anual/PlatformDependentCompilation.html
Answer by Delacrowa · Mar 01, 2017 at 02:00 PM
You should use mcs.rsp to have needed results for Unity 5.5+.
Answer by ofusion · Nov 06, 2015 at 07:10 AM
When using .NET 2.0 subset, -warnaserror+ will produce the following internal compiler errror:
Internal compiler error. See the console log for more information. output was:error CS0618:
System.Security.Permissions.SecurityPermissionAttribute' is obsolete:
CAS support is not available with Silverlight applications.'
It seams a Unity internal problem. Any one knows how to fix it?
Answer by ZackSheppard · Jan 29, 2021 at 01:38 AM
The accepted answer here did not work for me. I am using unity 2019.4.5f1. I can't seem to find any way to make this happen.
Are you target .NET 4.X ? According: docs.unity3d.com/Manual/PlatformDependentCompilation.html Note that the .rsp file needs to match the compiler being invoked. For example: when targeting the .NET 3.5 Equivalent (deprecated) scripting runtime version, mcs is used with mcs.rsp, and when targeting the .NET 4.x Equivalent scripting runtime version compiler, csc is used with csc.rsp.
Do you know of a way to make this work only for a certain 1 or 2 folders? I want this warn as error only on scripts i have written.
Answer by JacquesJ · May 27 at 11:37 PM
This post is very old, is there an updated way to do this for unity 2021+ ?
Adding the file and contents above just makes the warnings all disappear.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Stop Monodvelop adding new line when using attribute 1 Answer
MySql compiler error help~ (OSX) 0 Answers
is it possible to pass functions through functions? 2 Answers