This forces Unity to recompile the assembly using the new ruleset files. Elevate ERP021, the warning about incorrect exception propagation, to an error.Īfter adding the ruleset files to your project, reimport any script that lives in an assembly where the rules should apply.Suppress EPC12, the warning about suspicious exception handling.The leset file defines the following rules: Create a leset file inside Assets with the following code:.Save a duplicate copy of RethrowError.cs.Create a subfolder named Subfolder inside your project’s Assets folder.To test ruleset files in Unity, follow these steps: Step 1: Set up the ruleset file ruleset files are permitted inside the root folder: For example, the rules in leset apply to the code in Assembly-CSharp.dll. ruleset file in the root folder with the name. To override the rules in leset for a predefined assembly, create a. The rules you define in leset apply to all predefined assemblies (for example Assembly-CSharp.dll), as well as all assemblies that are built using. In the Assets root folder, place a ruleset file named leset. For more information on how to create a custom ruleset, see Microsoft’s Visual Studio documentation on how to create a custom rule set. To define your own rules on how to handle the various warnings and errors that the analyzers in your project raise, you can create a ruleset file. More info See in Glossary can supply analyzers that only apply to code that uses the package, for example to help guide package users to use the package API correctly. Most of the time these are called packages, but occasionally they are called Unity Package Manager (UPM) packages. Packages are self-contained units that the Unity Package Manager can share across Unity projects. This means that a package A container that stores various types of features and assets for Unity, including Editor or Runtime tools and libraries, Asset collections, and project templates. If an analyzer is in a folder that contains an assembly definition, or a subfolder of such a folder, the analyzer only applies to the assembly generated from that assembly definition, and to any other assembly that references it. Use throw instead.Īnalyzers apply globally to any assembly in your project if they are in the Assets folder, or in a subfolder that does not contain an assembly definition file in any of their parent folders. More info See in Glossary: Assets\RethrowError.cs(14,23): warning EPC12: Suspicious exception handling: only e.Message is observed in exception block.Īssets\RethrowError.cs(15,19): warning ERP021: Incorrect exception propagation. Once you do this, you should see the following two warnings in the Console window A Unity Editor window that shows errors, warnings and other messages generated by Unity, or your own scripts. Throw new System.NotImplementedException() Public class RethrowError : MonoBehaviour This code causes ErrorProne.NET to raise warnings about incorrect exception propagation and suspicious exception handling: using System To test that everything works correctly, save a file named RethrowError.cs with the following code in your project’s Assets folder. Then, give all of the DLLs a new label called RoslynAnalyzer. ![]() Under Include platforms, disable Editor and Standalone platforms. ![]() In the Plugin Inspector, under Select platforms for plugin, disable Any Platform. dll files into the Assets folder (or any folder nested in the Assets folder) in your Unity project. dll files included in the project as analyzers: To use an existing Roslyn analyzer library, install the library from NuGet inside your project. Using an existing Roslyn analyzer library This page explains how to use Roslyn analyzers in an empty Unity Project. You can use existing analyzer libraries to inspect your code, as well as write your own analyzers to promote the best practices or conventions within your organization. Use Roslyn analyzers and ruleset files in Unity projects to inspect your code for style, quality, and other issues.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |