I am currently building a project with msbuild that contains generated code. Is it possible to squelch build warnings from specific files (preferred) or classes?
If you have control of your code generation process you can use pragma statements in the code to suppress warnings.
At the top of the code you want to suppress warnings, add
#pragma warning disable
then at the end of the code add
#pragma warning restore
Note: In most cases you will want to suppress only specific warnings. You do that with
#pragma warning disable warning-list
where warning-list is a comma-separated list of warning number without the prefixes.
Another option is to suppress specific warnings across the whole project.
See How to: Suppress Compiler Warnings
Related
I am working in a C# project where this has been turned off.
I can't find out how to turn it on again.
It's pretty hard to google as it's default behavior, and no sane person would turn it off...
Did you perhaps change your compiler warning level?
Unused variables should have the warning of CS0168. If you look at that page, the title is "Compiler Warning (level 3) CS0168".
In solution explorer, right click your project and go to Build and check your Warning Level:
If you set it to anything lower than three, then the CS0168 warnings will never be shown. Also, just below the drop down is a suppress warnings text box. Make sure you don't have CS0168 in that text box.
Are you using an .editorconfig file?
If you are using an .editorconfig file, you may have suppressed this particular warning. Removing that suppression should resolve this as well. It would look something like this in your .editorconfig file:
[*.cs]
# CS0168: Variable is declared but never used
dotnet_diagnostic.CS0168.severity = none
In Xcode 7.1 after adding a single swift file to a large Objective-C project, build fails with many "No visible #interface for XYZ declares the selector ABC" and "method definition for ABC not found" errors.
All these errors appear in one file only.
Adding a swift file automatically changed the build setting "Enable Modules" to "YES". Changing this back to "NO" results in an error free build, but prevents mixing with swift.
The problem was an errant #import "header.h" in the middle of the file. This was probably left over from some copy and paste in the past.
Seems that when enabling modules the compiler sees this header and marks the objective c class' #end at this point, meaning all method implementations after this were not being seen.
Due to my compiler setting of all warnings being treated as errors, I never saw this issue as the compiler stopped outputting errors after the max number had been displayed.
I'm trying to build two separate applications for release. One of them should have less features than the other. I would disable those features with macros. Something in the lines of:
#ifdef DEMO_VERSION
// less code
#else
// more code
#endif
The question is, how do i define the DEMO_VERSION (which i would usually just put under "other preprocessor macros") so that i could easily switch it on and off? I could just define it manually every time i need to compile the app and delete it when compiling the actual release version, but i suspect there could be a smarter way of achieving this.
You can manage build configurations from the project info view in Xcode. Here, you can duplicate the default "Release" configuration, and then adjust the build settings to define a specific preprocessor macro for each configuration:
Select your project from the project navigator pane on the left. In the projects/targets list that is shown, ensure you have the project selected.
Choose the Info tab. Under Configurations, click + > Duplicate "Release" Configuration and rename it something like "Release (Demo)".
Choose the Build Settings tab. Expand the Preprocessor Macros entry to show the per-configuration settings. Add DEMO_VERSION=1 for the "Release (Demo)" configuration only.
Now, at compile time, your preprocessor statements will conditionally compile based on your current build configuration.
How can I suppress the "dead store" warning on a single file in Xcode?
I tried
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-value"
without luck. Any suggestions?
BTW, I don't want to "fix" the code, because I'm creating a bunch of objects only for the sake of inserting them into a Core Data database. I don't want to do anything else with them at the moment.
Although it doesn't work for the whole file, you can silence individual warnings for dead stores by adding
(void)variable;
after the line causing the warning
The answer given for How to get Intellij Idea to display compilation warnings? no longer applies from version 12. There is no longer a messages panel, as far as I can see.
How can I see a full list of all warnings in the project in version 12?
This option and the Messages panel is on the same place as before in IDEA 12.0.3:
If you don't see it, it means that your project has no errors. Make any error and the panel will appear. Verify that Hide warnings is not enabled. Fix the error, Make the project again, you should see only warnings:
Note that Make is incremental, if there were no changes, it will not compile and report any old warnings, so you may need to Rebuild to see all of them.