Excluding Code Analysis rule in source - visual-studio

In a project I'm working on FxCop shows me lots of (and I mean more than 400) errors on the InitializeComponent() methods generated by the Windows Forms designer. Most of those errors are just the assignment of the Text property of labels.
I'd like to suppress those methods in source, so I copied the suppression code generated by FxCop into AssemblyInfo.cs, but it doesn't work.
This is the attribute that FxCop copied to the clipboard.
[module: SuppressMessage("Microsoft.Globalization",
"CA1303:DoNotPassLiteralsAsLocalizedParameters",
Scope = "member",
Target = "WindowsClient.MainForm.InitializeComponent():System.Void",
MessageId = "System.Windows.Forms.Control.set_Text(System.String)")]
Anyone knows the correct attribute to suppress this messages?
PS: I'm using Visual Studio 2005, C#, FxCop 1.36 beta.

You've probably got the right code, but you also need to add CODE_ANALYSIS as a precompiler defined symbol in the project properties. I think those SuppressMessage attributes are only left in the compiled binaries if CODE_ANALYSIS is defined.

In FxCop 1.36 there is actually a project option on the "Spelling & Analysis" tab that will supress analysis for any generated code.
If you don't want to turn analysis off for all generated code, you need to make sure that you add a CODE_ANALYSIS symbol to the list of conditional compilation symbols (project properties, Build tab). Without this symbol defined, the SupressMessage attributes will be removed from the compiled code so FxCop won't see them.
The other problem with your SuppressMessage attribute is that you are listing a "Target" of a specific method name (in this case WindowsClient.MainForm.InitializeComponent():System.Void) and listing a specific "Scope". You may want to try removing these; otherwise you should add this SuppressMessage to each instance of the method.
You should also upgrade to the RTM version of FxCop 1.36, the beta will not automatically detect the newer version.

Module level suppression messages need to be pasted into the same file as the code that is raising the FxCop error before the namespace declaration or in assemblyinfo.cs. Additionally, you will need to have CODE_ANALYSIS defined as a conditional compiler symbols (Project > Properties > Build). Once that is in place, do a complete rebuild of project and the next time you run FxCop the error should be moved to the "Excluded in Source" tab.
Also, one small tip, but if you are dealing with a lot of FxCop exclusions it might be useful to wrap a region around them so you can get them out of the way.

Related

Seeing many compilation errors after upgrading my c++ project to VS19

I had built a c++ dektop project with VS17.
Now due to certain requirements, I needed it to migrate to VS19.
After making changes to compile my project with VS19, I am seeing many errors like below:
C3646 'OVERRIDE': unknown override specifier
C2039: 'wstring': is not a member of 'std'
I found this link - https://learn.microsoft.com/en-us/cpp/error-messages/compiler-errors-2/compiler-error-c3646?view=msvc-170
but could not find it useful to fix my issue.
I am looking for an easy fix, like if there is a way to use VS17 c++ compiler in VS19.
Rather than going back to the old compiler, you might be better off tackling the errors one-by-one:
OVERRIDE: is probably defined as macro somewhere in your project. Find out, what value OVERRIDE is being resolved to. Put the cursor into the word OVERRIDE to get the value. It could be that the respective include file is not properly included for some reason. Does your old project include a forced include for global definitions?
wstring: to be recognized as std::wstring, you have to include <string>.
Check your UNICODE settings. They determine the usage of 8-byte vs. multi-byte characters for strings. Look at Configuration Properties / Advanced / Character Set in the solution properties.

Disable built-in HLSL Compiler in Visual Studio 2017?

I am trying to get custom effects in Direct2D working in my c++ project which is included in an c#/XAML solution. I have been trying to adapt the CustomPixelShader project from the D2DCustomEffects solution from the Windows-universal-samples git repo.
My problem (I think) is that they are configuring a Custom build step in the project solution to get fxc to compile the shader. When I have tried to mimic their configuration, I have noticed that in my project property pages I have an additional property - HLSL compiler - that is not present in the CustomPixelShader example project (see image).
When I try to build the project without trying to configure HLSL Compiler, I get the error
Error X1507 failed to open source file: 'd2d1effecthelpers.hlsli'
which is a file that is clearly indicated in the custom effects example as important for the shader compilation. The path to d2d1effecthelpers.hlsli is included in the Custom build step config and I have checked that the file is there. However, if I add the path to d2d1effecthelpers.hlsli to Additional include directories in the HLSL Compiler config, that error message disappears but I get other problems instead. I’m interpreting this as if the HLSL compiler tries to compile the shader, even though I really want to use a Custom build step to do that instead.
My questions are: is it possible to disable the Visual Studio HLSL compiler in any way? I have noticed that if I exclude any shader files from the project the HLSL compiler disappears from the project property page, but how to do that manually?
Alternatively, is there any documentation on the Visual Studio built-in HLSL Compiler anywhere? I haven't really found any. I have tried but failed to get the HLSL Compiler to build according to the same rules as the Custom build step from the example.
I’m using Visual Studio Community 2017 v 15.3.5.
The first thing is that Visual Studio HLSL compiler is actually fxc. If you want to compile your shader manually as a part of Custom build step then you can disable hlsl compilation performing the following steps: right click on .hlsl file in Solution Explorer; select "Properties" in context menu; change Configuration Properties -> General -> Item Type entry from HLSL compiler to Text or Does not participate in build;
I got the answer in another forum (link to answer).
Summary: right click on the .hlsl-file in the solution explorer in Visual Studio. That will result in showing the properties for that file. Under Configuration Properties -> General you can change Item Type to something other than "HLSL Compiler". Changing it to "Text" worked for me, "Does not participate in build" was suggested in the answer in the other forum. If that does not do the trick, changing the value for Exclude from build to "No" could work. For me, just changing the Item type of the .hlsl-file was enough.
This should result in the HLSL Compiler disappearing from the project property pages (see the image in the question), and the HLSL Compiler will not try to compile the .hlsl-file.

Does MS-Build Definition inherit property from projects?

I've some sql projects with the property "Treat Warnings as Errors" enabled for every build configuration set (Debug, Release, etc.).
Building locally this property works without problem (so every warning is managed as error).
Using instead the MSBuild-Definition tool the same warnings are not managed as errors but just as warnings.
I cannot add the MS Build Argument /p:TreatWarningsAsErrors=True to the Build level because in the same build definition there are other projects (not only sql projects) where the property "Treat Warnings as Errors" isn't enabled, so every build is going to fail.
What I want is to have the possibility to set my Build definition so that they can manage some project as "TreatWarningsAsErrors" and some other not.
I read in some documents that the build definition should inherit its property from the project built.
Is this wrong? Should I just add some configuration to my Build Process Template?
I am using the TfvcTemplate.12.xaml
If you need some other details just ask me.
Hope you can help me
Thanks
I have tested in my VS 2015.3 + TFS 2015.3, and used XAML Build with default build process template TfvcTemplate.12.xaml, but couldn't reproduce your issue.
If I enable "Treat Warnings as Errors" for one project in a solution, I would get an error for XAML build. If I disable this option, there is no error but warning in XAML build:
Please compare your environment with mine, and double check whether
you have checked in your solution after you enable the "Treat Warnings
as Errors" option.

Intellisense error / including additional libraries with environment variables

I'm working on a C++ project (VS 2010) using CPLEX.
I have included the required cplex libraries in the project settings as follows:
added the "additional include directories" under C/C++ > general
added the "additional library directories" under linker > general
added the .lib files as "additional dependecies" under linker > input
Everything compiles fine, however my problem is that intellisense still reports errors (red squiggly underlines) such as "cannot open source file" in the #include line, and "identifier undefined" when using variable types defined in the CPLEX library.
The only difference with other projects that don't have this behaviour is that this time I have used windows environment variables in setting the include path, i.e. the library directories and include directories are defined similar to: %CPLEX_STUDIO_DIR%\cplex\include
I have set it like this so that I can build this project on different machines without messing around in the project properties. Since CPLEX is installed separately, using relative paths to specify additional directories is not really an option.
I'd like to repeat that the project compiles, it's only the intellisense errors that are bothering me.
I know I can turn off the intellisense error reporting, but if someone has a workaround for this I'd love to hear about it.
Kind regards,
This problem is known to Microsoft:
http://connect.microsoft.com/VisualStudio/feedback/details/779874/intellisense-cant-handle-using-environemt-variable-in-include-path
The only way I know of to avoid it is to manually enter the full literal path. The bug is marked "deferred" which I think means Microsoft has regarded it not serious enough to be fixed soon.
The solution is to replace %CPLEX_STUDIO_DIR%\cplex\include with $(CPLEX_STUDIO_DIR)\cplex\include. This is the syntax Visual Studio uses for its built-in variables such as $(VCInstallDir), but it also works for environment variables (so long as they don't have the same name as a built-in variable) and is recognised by intellisense as well as the compiler.
(I realise this is an old question, but it ranks highly in search results so it could help others even if not the original poster.)

CA2240 warning for DataSet and DataTable within

I've created a DataSet that contains a simple DataTable containing five columns. When I link to the DataSet from another solution and build my project I get the compiler warning CA2240 (from code analysis), suggesting to
add an implementation of GetObjectData to type 'SomeDataSet'
add an implementation of GetObjectData to type 'SomeDataSet.dtSomeDataTable'
Do I need these implementations or can I ignore the warnings in my case? The serialization works as expected, so I'm not sure why I get the warnings.
I figured out how to add an implementation in the DataSet's .cs class, but how can I do that for the DataTable? All DataTable related code is auto-generated in the .designer files, so even if I changed it there it would be overwritten anyway.
Thanks in advance
G.
According to Microsoft, the warning about the missing implementation for the DataTable can be ignored. The warning is issued so that any users of the DataSet (with the DataTable in it) have to decide deliberately whether they need their own implementation of GetObjectData or not (in which case the warning can be suppressed with an appropriate comment).
HTH
G.
Finally found a solution in Visual Studio 2015 to exclude this warnings message.
On Visual Studio Solution Explorer, right click the project you have this warnings CA2240 warning for DataSet and DataTable
Run Analyze -> Run Code Analysis and Suppress Active Issues
This will generate a new file GlobalSuppressions.vb or GlobalSuppressions.cs
After that, when you run Code Analyze again, the CA2240 warning is gone.
For solution, you can run Analyze -> Run Code Analysis and Suppress Active Issues -> For Solution

Resources