How can I selectively ignore compiler warnings at a folder level without altering the source code files (*.cs)? With the toy example below, I want to ignore CS0001 only for Lib1 (reviewed it to be ok) but nowhere else (since they could be unreviewed). Right now I can ignore compiler warnings only at the project level. Or I need to add #pragma to the source code which makes my source different from the library repository upstream which we cannot directly use (or link).
Project
+-LibSrc
+-Lib1 // Ignore CS0001 here
+-Lib2 // Ignore CS0002 here
+-Lib3
I'm hoping for some sort of project setting or some file places in the folder that signals this to the C# tools.
You can select the files to ignore, on File Properties, set Build Action to None. The compiler would ignore warnings from the files and build.
Related
Is it possible to enable treating warnings as errors per file?
I'm working on a large project and it's impossible to set it at project level, it would require a lot of work to fix thousands of errors due to treating all warnings as errors. And this kind of refactoring won't be approved anyway.
So I'd like to enable it per .cs file if possible.
Something like how C# 8 has with #nullable enable ?
Or maybe by some Roslyn magic? (if not a VS extension, at least a tool which parses the project files)
I'm trying to configure my project from within the Unity Editor to treat all warning messages as errors, but I can't seem to find any documentation pertaining to this. Is there a way that I can configure this for my project? Thank you so much!
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 /?
More on https://answers.unity.com/questions/216838/how-to-force-warnings-as-errors.html
I like to have clean, "0 warnings" - projects in C#. This includes my project having XML comments for every public property and class.
Now I use entity framework with migrations (code first). The migrations are created by using "Add-Migration" which cause automatic code to be generated in the Migrations folder (standard behavior). I might want/need to modify these classes a bit but do not want to add Comments for the public classes created there.
I know I can disable the warnings using #pragma disable but again do not want to have to do this for every Migration-class.
So: Is there a possibility to use #pragma disable (or something similar) on a complete folder or namespace?
I do NOT want to use something like GhostDoc as a workaround.
Add a new .editorconfig file to that specific folder with this content:
[*.cs]
generated_code = true
dotnet_analyzer_diagnostic.severity = none
To suppress warnings for generated code in a project
Right-click the project in Solution Explorer, and then click
Properties.
Click Code Analysis.
Select the Suppress results from generated code check box.
Reference: How to: Suppress Code Analysis Warnings for Generated Code
One of the C# project uses multiple C++ DLLs. I want to hide below warning in the same project.
ALINK : warning AL1073: Referenced assembly 'mscorlib.dll' targets a different processor
I know it can be use C# code to do this using code file. But in my case I want to use the project file to do this.
In C++ project file, It can be done by
<Link>
<AdditionalOptions> /ignore:xxxx %(AdditionalOptions)</AdditionalOptions>
</Link>
Is there anyway to do this using C# project file?
In the .csproj file
Add the tag <NoWarn>1073</NoWarn> to the desired build configuration in a <PropertyGroup> tag. Suppress multiple warnings by inserting a ;.
In Visual Studio
Right click the project -> property -> build tab
You can explicitly specify the warning you would like to hide or lower the warning level to do that.
Please see the two posts below for reference:
https://msdn.microsoft.com/en-us/library/jj715718.aspx
https://msdn.microsoft.com/en-us/library/13b90fz7(v=vs.120).aspx
Is there a way to easily stop StyleCop warnings from being displayed within specific projects in a solution. Or, more pointedly, a way to select which projects StyleCop analysis should be performed on by Visual Studio?
We have a solution with 9 projects in it. There are only 2 projects that I actually want to see StyleCop warnings for, so I've created StyleCop.Settings files within those project root directories. This means that, for the rest of the projects, the default rule set is applied and I get a screen full of warnings every time I open a class.
The only way I can think to remove these warnings is to add another StyleCop.Settings file a folder level above with all the rules switched off and set merge options on the specific Settings files I am interested in to not merge with this parent file. This just feels wrong though. Is there a cleaner option or is this my only one?
UPDATE: I'm specifically looking for a way to stop the warnings from appearing within Visual Studio. I've added a Settings.StyleCop file to the solution folder and disabled all the rules. I run StyleCop analysis across one of my test projects and there are no errors reported. However, opening a test class reveals a raft of StyleCop warnings, which I want to suppress. Could this be the StyleCop for ReSharper plugin? I have a code cleanup profile created and have disabled certain rules within there but that doesn't appear to make any difference within my test classes.
Please have a look at File Lists configuration - they allow to disable rules by default per project:
Enabled Or Disabled By Default
In addition, a new setting allows you to determine whether rules
should be enabled or disabled by default. This can be set either at
the project level or at the SourceFileList level. For example, here’s
how you would set up a project with all rules disabled by default, and
only two rules explicitly enabled:
<StyleCopSettings Version="4.3">
<GlobalSettings>
<BooleanProperty Name="RulesEnabledByDefault">False</BooleanProperty>
</GlobalSettings>