Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
6
Question by Bobat · Feb 13, 2012 at 03:22 PM · c#compilerwarnings

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!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

5 Replies

· Add your reply
  • Sort: 
avatar image
6
Best Answer

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 /?

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Rod-Green · Mar 11, 2014 at 09:54 PM 1
Share

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 /?

avatar image mquitoss01 · Apr 16, 2014 at 08:33 AM 0
Share

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

avatar image
2

Answer by Delacrowa · Mar 01, 2017 at 02:00 PM

You should use mcs.rsp to have needed results for Unity 5.5+.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

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?

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

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.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image kOnINC · May 04, 2021 at 12:52 PM 0
Share

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.

avatar image doron-matific1 kOnINC · Jan 27 at 05:22 PM 0
Share

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.

avatar image
0

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

14 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges