how to Import fxcop file to stylecop - c#

I have one .fxcop rule file is there any way where i can import this file to Stylecop?
Please let me know the step by step approach for this.
Thanks...

Don't think that's possible as FxCop and StyleCop are completely different tools for different purposes. See Stylecop vs FXcop

Depending on the rule you have in FxCop, it might be possible to port it to StyleCop (or Roslyn), but you can's simply import or combine these tools. The reason behind this is that FxCop inspects the compiled binaries, while StyleCop parses the actual source code.
If you update your question to include the purpose of the rule, we might be able help you with that.

Related

Export Resharper code style settings into Editor.Config

I am trying to create a single place for code-style and formatting rules for our solution.
We are currently using Resharper, which stores this info in the {slnName}.dotSettings file. However, some developers don't want to use Resharper due to its performance issues. So they don't get these rules and warnings.
EditorConfig seemed like a suitable replacement, but I wanted to translate the ReSharper rules (where possible) into editor config rules and also include all the ReSharper specific rules so that those who do use ReSharper get the extra rules too, and they are all stored in one place (One source of truth!).
Anyway, trying to grasp what the .dotSettings file is doing has been unfruitful, and I know that Resharper will read in editor config files, so I'd like it to export it too
With Resharper 2019.1 you can now 'Export settings to .editorconfig'. The option lives in Resharper -> Tools.
This will export the standard editor config options, the Visual Studio specific config options and the resharper specific configs. Very useful!
In Reshaper 2019.3, this option is found in "Resharper Options | Code Editing | General Formatter Style"
As described here -> https://blog.jetbrains.com/dotnet/2019/03/28/export-editorconfig-code-style-optimize-references-sdk-projects-resharper-2019-1-eap-updates/

Disable Resharper intellisense for single assembly

I'm working on a project that references a dll that has been obfuscated. The dll has many namespaces and classes that are single letters.
My issue is that many times while typing, Resharper will suggest classes from this assembly, e.g. if I am typing 'Report' it will suggest 'r.e.p' from this other assembly.
Is there a way I can get Resharper to ignore this one particular assembly for intellisense options?
Thanks
It is not possible now - there is the same feature request.
If your source code is located under a single parent directory, Resharper allows you to exclude it:
Goto Resharper -> Options, Settings, then press the 'advanced button'
There you can enter the directory and/or files to exclude from the solution wide analysis.
Go to Resharper > Options > Intellisense. Just look at it if you can find what you are looking for.

A way to modify class (and general assembly) data at build time

This thing I want to do might not even be worth doing but I thought it would be cool.
So what I want to do is to have some code that runs when my project is building (not only when compiling), and adds stuff to my classes based on things like attributes and general code analysis. What I want to do is have dynamically generated fields/properties that are usable through intellisense, but not visible in the actual source.
The reason for that being that I might potentially want to generate a lot of them, and outputting them to source would turn into a mess very quickly.
The potential possibilities of a system like that would be stuff like vector swizzling.
Is there maybe a library of some sort for that that I could just plug my generation code in? If not, what would be the best way to approach this, if there is any?
The most visible example of this is done by Microsoft for XAML files. During the build, a C# source file is created for each XAML file and placed in the obj/Debug or obj/Release folder. In addition to that, the MSBuild .targets file where the relevant tasks are defined is specially configured to tell Visual Studio that the generated files are required for proper IntelliSense support, which means you don't actually have to explicitly build the project in order for IntelliSense to allow items declared in XAML to be used in C# code elsewhere in the project.
This is exactly the method I use for generating code for ANTLR grammar files during a build. You can see a complete example with a build task assembly and custom .targets file here:
https://github.com/antlr/antlrcs/tree/master/AntlrBuildTask
You should be aware that some 3rd party extensions for Visual Studio completely replace the IntelliSense support with their own implementation of code completion. Some of these extensions are known to not support the MSBuild IntelliSense extensibility features required for this to work with custom code generators. If you run into problems with IntelliSense and have any extensions installed, you may find that removing the extensions completely resolves the problems.
You should compile code by the class CSharpCodeProvider/ICodeCompiler/CompilerParameters when application run.

Antlr4 C# targets and output path of generated files

I have a C# solution with an Antlr3 grammar file, and I'm trying to upgrade to Anltr4. It turns out the grammar was the easy part (it became better, and one third the size!). Generating the parser turned out to be the tricky part.
In the old solution I merely ran AntlrWorks to update the lexer and parser .cs files when the grammar file changed. The lexer and parser were included directly in the same project as the grammar so the framework around the parser could make use of them directly.
With the Antlr4 targets for C# I noticed that (at least by default) the output path of the generated Parser C# classes is in the intermediate directory, e.g. obj\Debug. This means I can't use the parser directly in the same project. Am I supposed to change the output path if I want the generated source usable in my sln? Don't I want it in my sln?
I tried making a separate project for the parser generation, that is, a project containing only the grammar file. When this project is built using the Antlr4 targets, the resulting assembly can be referenced from projects needing the parser classes. However, if this project is included in the solution I still don't get any intellisense in visual studio since it bases its intellisense on source files for loaded projects, so it is still not quite usable. The only way I could get it working properly was to build then unload the parser project, and have other projects reference it as an assembly file rather than a project.
EDIT:
After looking on the antlr-interest list I found this thread indicating that the problem with intellisense may be Resharpers fault. If this is the case, then my question is rather how to keep using both Antlr4 and Resharper in my solution?
https://groups.google.com/forum/#!topic/antlr-discussion/QSuJXphaBDg
I found an extension for Resharper: ReSharper.ExternalCode.
Tip for Antlr: add obj\Debug in Resharper -> Code Inspection -> External Code and reload solution.
It's works for me.
There is an easy way to get the best of both Antlr 4 and Visual Studio. You are on the right track in having a separate grammar project and implementation project, but you are missing a couple steps.
Follow these steps to get the Intellisense working
In Visual Studio, go to Tools -> Extensions and Updates and search the Online section for "ANTLR Language Support" by Sam Harwell.
This does a few things:
Adds Templates for the combined grammars.
Adds Syntax Highlighting
Adds an MSBuild target for the grammar to generate the parser.
In your solution, set up your project structure like this:
Solution
Grammar Project
ANTLR 4 Combined Grammar
Implementation Project
Folder for Links to Generated files
Listener Implementation Class
Write and Compile your grammar.
In your folder for the Links to Generated Files, Right-Click the folder and click Add -> Existing Item
Browse to Grammar Project\obj\Debug and select all the generated parser files.
This next step is important. On the Add button there is a little drop-down arrow. Click the drop-down arrow and click "Add As Link".
This will add the generated files to the implementation project using a symbolic link instead of a direct copy.
This gives the added benefit of not having to remove and re-add the parser files if you have to change your grammar later.
Intellisense should work now for your generated parser classes, and you don't
even have to disable ReSharper.
You are encountering a known bug with ReSharper. The ANTLR 3 and ANTLR 4 C# build integration is reliable, and uses long-established patterns that Microsoft uses with other languages and code generation tasks. Your options are:
Stop using ReSharper
Get the ReSharper authors to address the lack of support for this feature, or
Modify the ANTLR 4 target to work around the limitation in ReSharper, which will introduce other problems into the build which may or may not be acceptable for your use.
Option 1 is certainly the least expensive, and most likely to provide reliable long-term support for your projects.

Is there a way to sync settings from Settings.StyleCop to ReSharper?

My question is quite simple: Is there a way to sync the changes you make in the Settings.StyleCop file into the ReSharper settings?
As it is now I have to first make the changes in Settings.StyleCop (so that StyleCop can validate my code using the rules I want) and then I have to make the same changes in ReSharper to get syntax highlighting and warnings in code as i type.
I found this question but it doesn't seem to apply anymore. ReSharper doesn't read StyleCop.Settings.
With the StyleCop (4.7.44.0) plugin for R#:
Under the R# options, Tools, StyleCop section:

Categories

Resources