How do I change severity of put into 'using' statement suggestion? I'd like to have it treated as warning. Currently it is only available as context action.
I tried searching for this setting in Editor > Inspection Settings > Inspection Severity > C#, and in Jetbrains docs, but I could not find any info regarding this setting. Is it even possible to change this?
It is not possible, you cannot change the severity of this issue with Rider.
We're the Roslyn analyzer IDisposableAnalyzers for these issues.
Related
In a css file of an asp.net Blazor app when I use ::deep VS emits a warning "Validation (CSS 4.0): "::deep" is not a valid pseudo-element." That might be true for regular CSS, but not in the context of a Blazor app.
Is there a way to suppress it? Right-click -> Suppress -> In File / In Source do nothing.
You can add deep to the vendor specific extensions.
I've added it to the Microsoft extension and it works.
Open with an editor (in Administrator mode) the file:
C:\Program Files (x86)\Microsoft Visual Studio\2019\<your version>\Common7\IDE\Extensions\Microsoft\Web Tools\Languages\Schemas\CSS\1033\css-vendor-ms.xml
Go to line ~69 and add the following code:
<CssPseudo name="::deep"
_locID="ms-browse-pseudo-element"
_locAttrData="description"
version="3.0"
browsers="IE11"
description="Blazor child component support."
standard-reference="https://learn.microsoft.com/en-us/aspnet/core/blazor/components/css-isolation?view=aspnetcore-5.0"/>
Restart Visual Studio.
Now I can see the source code as:
For Resharper users, editing the css-vendor-ms.xml is needed but does not completely solve the issue. Resharper will continue to highlight ::deep elements as errors in your solution. This is currently a known bug, which will hopefully be resolved in a future build.
As a work around, go to Resharper Options --> Code Inspection --> Inspection Severity --> CSS --> Potential Code Quality Issues --> Unknown CSS symbol and drop the severity to Warning (or lower).
This has now been fixed as of the latest preview version of Visual Studio 2022:
https://developercommunity.visualstudio.com/t/Support-::deep-in-razorcss-CSS-isolati/1623976
I just downloaded 17.3 and my project is now down to zero warnings again! Look forward to it being released properly.
How to hide the ... that appeared everywhere in Visual Studio 16.10?
e.g.
It appears for unused usings, expression value not assigned, and many more.
[I'm NOT asking how to turn off graying out of unused usings.]
Dots like that, along with squiggly underlines, are coming from diagnostics issued by the compiler and analyzers.
Each diagnostic has its own identifier code such as CS1234 or IDE1234, etc.
You can configure the severity of each of these as described here:
https://learn.microsoft.com/en-us/visualstudio/code-quality/use-roslyn-analyzers?view=vs-2019
The easiest way is to add/edit your .editorconfig file and put the following in:
dotnet_diagnostic.<rule ID>.severity = <severity>
Where <rule ID> is the diagnostic ID, and <severity> is one of none, silent, suggestion, warning or error.
This gives you very fine grained control over these kinds of tips in your solution.
If you put the .editorconfig file in the root of your repo, it will apply to all projects in the solution.
Here's an example of using the lightbulb menu (Ctrl+.) to configure the severity of a diagnostic with code VSTHRD002:
There's also a section "Suppress ..." which lets you suppress a specific instance of the diagnostic, in contrast to changing the severity which applies across a broader scope.
Note you have have multiple .editorconfig files. For example, if all your unit tests are under a test folder, you could drop an .editorconfig file in there that has more relaxed rules.
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.
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: Use Random.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]
Now you've recorded if there are warnings in last build, you can make a flag in memory or in file system, then you add few lines of code to check this flag, if it's true then stop the playing by using EditorApplication.ExitPlaymode()
Don't know why I did, but I updated to .Net Core 2.1 yesterday. Ever since I updated, I am seeing tons of squiggly lines throughout my solution in Visual Studio on mac (so annoying). Here's the warning message -
I think understand the source of the warning. Basically, I am referencing to a lot of 3rd party Nuget packages (Autofac, Serilog, etc.) and they are built with an older version of .Net Core. This is what the warning is trying to tell me I think. But my code works just fine, don't have any issues running it.
After researching a little bit, I think the error is CS1701. It is also added [by default] to be ignored in the Compiler settings for all projects in my solution. This is why I am not seeing this warning reported when I build my project/solution. However, the squiggly's are still shown in the text editor in Visual Studio.
Visual Studio is kind enough to offer a solution to suppress these squiggly lines, by adding a pragma statement at the top of .cs file - #pragma warning disable CS1701 // Assuming assembly reference matches identity. But I am afraid I need to add this line to all .cs file in my solution (there are a lot).
Does anyone know any other better way to suppress these squiggly lines in the text editor, please?
Goto Preferences->Text Editor -> Source Code Analysis -> Code Rules (tab) and change the line
Rule Id="CS1701" Action="Warning" to
Rule Id="CS1701" Action="Hidden"
and press OK.
Wait a for a short while and the lines will disappear.
Below I have added a screenshot to explain the issue. I am trying to fix certain warnings across solution, not just in a single file. It's really hard to fix them across solution when you're editing an old project with 1,000+ files and you've got 1000+ warnings that could simply be fixed in a matter of minutes, but I've been juggling with them for days.
Is there a way to enable ReSharper option to fix across solution? Or fix across folder even. This happens with a lot of issues, "Remove redundant initializer", "Remove case 0", and "Convert body to LINQ"
You can change the Resharper settings from Resharper Options menu.
Go to :
Resharper --> Options --> Code Inspection --> Inspection Severity.
Choose C# or VB.Net as per your project language then find "Language Usage Opportunities" and change the settings for "Convert body to LINQ" from 'Warning' to 'Hint'.
Your other problems are also can be fix in similar manner.