C# Compiler Options – Unity Plugin Documentation
Asset Store Page | Support | Discord
This Unity Plugin allows you to easily add, remove, or modify the compiler options in your Unity project without the need to remember the .rsp file syntax. Avoid making mistakes. Get right to the documentation.
Quick Start
After importing this plugin, open the Editor window by pressing Window -> C# Compiler Options.
“General” tab allows you to see all the currently enabled compiler options, remove them by pressing ‘x’ or add new ones by pressing “(+) Add Option”.
You can see what each option does by pressing “?” next to it (or just below, in this documentation).
You can toggle the “Enable .rsp Editor” on the “Settings” tab to view and edit compiler options right in the Inspector just by selecting the csc.rsp or mcs.rsp file.
Documentation
.rsp file, also called the response file, contains user-specified compiler options. Your project may already have a csc.rsp if you are using a newer scripting runtime (Roslyn compiler), or mcs.rsp if you are on the deprecated .NET 3.5 (Mono compiler). If you don’t – the plugin will create a correct file when needed.
Supported Options
-warnaserror / Treat Warnings As Errors
Some of the warnings the compiler shows you are really useful and can prevent you from making mistakes in your code.
For example, the CS0067 warning prevents you from accidentally creating an event Action and forgetting to invoke it.
But there are hundreds of possible warnings the compiler detects that may save you from debugging.
Optionally you can specify a list of warnings to be treated as errors.
This compiler option may also be useful when developing libraries or plugins to not add any warnings for the person that will be using your code.
-nowarn / Ignore Warnings
This option allows you to specify one or more warnings that will be ignored and will not show up.
This may be useful together with the “-warnaserror” option, to ignore some warnings for your project, but still get compilation errors for others.
For example, the CS0219 warning can be annoying when you just want to comment out some lines for debugging purposes.
You can add new ignored warnings by writing it in the form of ‘CS0001’, just the number part like ‘0001’, or even without the leading zeroes, so just ‘1’. You can also add multiple warnings at a time by separating them with a comma.
Then press the “Add New Warning“ or just hit Enter.
Warnings in the wrong format will not be added, an exact error will be shown instead.
Alternatively, to not ignore a specific warning for the whole project, you can use #pragma warning disable & #pragma warning restore in specific scripts.
-unsafe / Allow Unsafe Code
This option allows you to use unsafe code (use the unsafe keyword) in your project, which is disabled by default.
-reference -r / Import From a File, Reference Assembly (dll)
Some of the System libraries are not included by default, and you will need this compilation option to enable them.
For example, to use the zip from the standard library, you will need to add two references
System.IO.Compression.dll
System.IO.Compression.FileSystem.dll
You can also use it to add a reference to a dll containing an assembly manifest.
-define -d / Define Symbols, Change Compiler Directives
This option isn’t necessary because you can also set Scripting Define Symbols in the PlayerSettings window, but it may be more convenient to set defines via the .rsp file, and some .rsp files already have directives, and so it can be edited from the General tab.
-warn -w / Warning Level
This one allows you to change the Warning Level, for example, to hide all not Severe warnings and keep your project clean, only fixing all the severe warnings. This may be useful together with the “-warnaserror” option, to only stop the compilation when severe warnings occur.
You can easily see what each available number means and select them from a drop-down menu.
Add Custom
This menu option allows you to add any number of custom compiler options that isn’t yet supported with a custom editor by the plugin.
Tabs
General Tab
If you already have a csc.rsp or the mcs.rsp file, current compiler options will be displayed and be available to be modified or removed.
If there isn’t a response file already, when you add your first option – the plugin will create one and place it in the “Assets/“ folder.
Press “(+) Add Option” to show a menu of available options to add. Some options, like “-r” and custom, can be added multiple times.
Press ‘x’ to remove any compilation option or warning.
When adding, removing, or changing the compiler options, please wait for recompilation to finish before they take effect.
Option & Warning Documentation Links
“?” next to each compilation option will lead to an official Microsoft documentation for this option.
“doc” button next to each warning will lead to the warning documentation so that you can easily remove the ones you don’t need to ignore.
Force Recompilation
If you change the compiler options using this asset, the recompilation happens automatically. But if you would like to change the .rsp file syntax yourself, you can just hit this button to force the recompilation instead of changing some script back and forth. Without the recompilation, your manual changes will not take effect because Unity doesn’t automatically recompile when changing this file.
Settings Tab
Custom Compiler Option Inspector
On the settings tab, you can enable the custom .rsp Editor (which works for both csc.rsp & mcs.rsp response files)
With it enabled, you don’t need the main plugin window, its full functionality becomes available from the inspector window.
But because it is not possible to change the custom editor only for these two files, when you toggle the checkbox, a custom editor is added for the DefautAsset (or TextAsset for Unity 2018). If you already had a custom inspector for the DefaultAsset, then this or the other custom inspector may not work.
Log Level
You can change the log level for the plugin itself. Leaving only errors or disabling them fully.
Other Features
Migrate Compiler Options from .NET 3.5 (Mono) to .NET 4.0 (Roslyn)
If you were using a mcs.rsp for the older Scripting Runtime version, when you update to .NET 4.x, the mcs.rsp actually becomes obsolete.
A warning will appear in the plugins window, allowing you to click on it to fix it -file will be renamed to the current version it should be.
Detect Warning as Error
When using -warnaserror you may get some warnings as error that you would rather ignore by adding them to the -nowarn list.
If the plugin detects errors – you can add these warnings to ignored with a click of a button (even if you don’t have a -nowarn yet).
Support
If something is missing, not working, or you have some ideas for improvement, please contact me at https://letsmakeagame.net/support
Asset Store Page | Support | Discord