How to get list of available analyzers? - c#

I'd like to add rulesets to my project following the fashion I can see in the EFCore and MachineLearning projects.
I have read through the Roslyn Analyzers doc but I didn't find a file or a method where one can get the list of avaialble analyzers. Ofcourse, I can copy and paste what I can see in the above examples, but this way I won't have a sustainable method to maintain when new rules are released.
So, the question is how can I get a list of rules in a ruleset format?
Update:
I opened my solution in VS which has a ruleset editor, but seemenhly it writes the rules into file randomly.
I also asked the StylecopAnalyzers guys.

Related

Find out what packages, classes and methods the Jar file contains

I have a Java code editor with syntax highlighting, with a code hint menu and quick actions. The editor is written in C#. Once again, this editor is for editing Java code! I need to know what packages, classes, methods are in the Jar library (Jar file) for further
code hinting and syntax highlighting.
I have an idea about decompiling the Jar to find out "its contents", but I suspect that there is another more efficient way to implement this.
This is what my editor looks like:
It turned out to be relatively simple. I found the 'jd-gui' repository (https://github.com/java-decompiler/jd-gui), here is the app: (http://java-decompiler.github.io/). The program itself is written in java and is a very good java decompiler based on the jd-core core (https://github.com/java-decompiler/jd-core).
I liked this application, because. it implements a detailed overview of the entire decompiled application (you can see what packages, classes, methods, fields are in the jar), that's exactly what I needed! Because it was an open source repository, I just tweaked it a little, and now when decompiling, the program saves the xml file with the "contents of the jar file". And then I wrote an xml parser in c# to load data and further work with them. That's all...
Code with edited jd-gui saving xml file with jar content: https://drive.google.com/drive/folders/1_opg0BBIrmHoZ125F0Fyl9n_0o4xutiL?usp=sharing When loading a jar file, next to it (in the same folder) an xml file with the contents of this file will be saved.

understanding the content of a csproj file

I have some older projects in non-SDK style which were created using Visual Studio; the csproj files were almost never modified manually. They were done partly by colleages before I came to this company, so I have very incomplete knowledge about what should or shouldn't be in these files.
Now I am trying to turn them into SDK-style projects by manually modifying the csproj files. In order to do that, I need to understand for each tag what it is for, and if it can be omitted or must be modified.
There might be
non-SDK-style leftovers that can just be deleted,
content we were not aware of (because we don't always know what we are doing when playing around with settings in a project),
content that needs to be modified to fit the new SDK-style specification,
content that can be omitted because it contains just its default value,
etc.
I try getting by by googling a given tag together with "csproj", but more often than not I cannot find useful content. I also noticed that most of the time I DO NOT find a source from Microsoft, mostly blog entries by private guys that sometimes, sometimes not tell me what I want to know.
There are some Microsoft docs like sdk reference or common properties, but they do not cover all tags that I have in my project.
So, how can I understand the content of my csproj file? Is the documentation there and I am merely not finding it? If so, what to search for? Shouldn't Microsoft have a comprehensive list of all possible tags? They have invented the csproj format, so they should know. Or do I need to learn something else first that is a prerequisite of working with csproj files (like before constructing bridges one should know about basic algebra and calculus), that will help me figure out stuff on my own?
cproj files can have a lot of project configurations. Visual Studio Extensions might also modify cproj files and add custom values.
As per the comments on this answer, there isn't a complete list of available properties for Visual Studio projects. The links provided in the question contains most used properties, so that should cater for the average project.
It is very rare that properties will be used that is not contained in those links. If you do run across an unknown property, try searching online, if that fails, ask on SO.
A good search query that hasn't failed me yet, {Project Type} "{Property}" csproj property : .Net "TestProjectType" csproj property.

Does documentation for file Microsoft.CSharp.targets with default C# targets exist?

When I create C# project in Visual Studio 2010, file Microsoft.CSharp.targets is included.
Is any documentation available for it?
Which targets in it, which properties are used?
It is especially useful when editing build script manually without VS.
The file with targets could be investigated manually (what I do from time to time).
But in such case it is not clear what is a matter of changes, what is by specification and what is no.
Everytime I need something about Microsoft.CSharp.targets I found it in different places.
I have not found "one place" with all described.
Does complete reference available?
Thanks.
No specific documentation I know of, it is an implementation detail for C# projects. You can find plenty of documentation about MSBuild in the MSDN library, the Microsoft.CSharp.targets file just contains targets that are specific to building a C# project.
The most important targets it implements are Build, Clean and Rebuild. They directly correspond to the commands you find in the VS build menu. The .csproj file merely sets properties that affect the outcome of the general targets. All of this is readily available on your machine, you can look at .targets files with an editor. There's just a whole lot of it and it is isn't exactly that easy to read, the concept of XML as a programming language is a bit, well, flawed. No debugger either.

How does resharper recognise what files to include for its intellisense?

It is a well known issue with Resharper that it fails to recognize generated C# files using Custom Tasks (making intellisense fail). Does anyone know how to fix this without adding the files to the project?
(BTW, including the generated files in the project or creating a separate assembly and other such flawed suggestions are totally out of the question).
Can we write a Resharper plugin for this? We have a fairly large number of developers that cannot use Resharper, so this would well be worth the effort.
Can we somehow add the obj/*.g.cs files to
Resharpers non msbuild based csproj parser (lurking somewhere within Resharper)?
Is the method used by Resharper on how to resolve the list of .cs files to include documented somewhere?
As this issue is experienced and reported again and again for years, surely there must be someone who has cracked it by now?
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.

How do I programatically create an NDepend project file?

To start, this may be a useful link: http://www.ndepend.com/NDependConsole.aspx
As anyone who has used Visual NDepend may know, with NDepends you need to import project / solution files, and the corresponding output directories, namespaces, and assemblies are added to the NDepends project.
The problem I have, is I have TONS of these projects and solutions to add. It seems ridiculous to sit there for 45 minutes adding 300 solutions click by click. There must be a way to create an NDepend project file from a list of the paths to these solution / project files.
My first thought was to find the same information NDepends does (output directories, used namespaces and output executables dll's, etc) and programmatically create the NDepend project as a massive string. However, this seems like unnecessary work.
It would be nice if there was a way to invoke the command line and target specific projects, not output directories, as some of the projects have PostBuild tasks to copy assemblies to different directories, some projects specify the output directory as an upward relative path (ie ....), and so it isn't safe to assume that the output directory of a project is the same directory it is in.
Any ideas?
Stefan, I am the lead developer of NDepend.
We recently released NDepend.API that can do exactly what you are asking for.
NDepend.API overview
NDepend.API introduction
NDepend.API getting started
In the getting started section you'll find code example about how to use NDepend.API to create a temporary NDepend project initialized with assemblies generated from a Visual Studio solution.
You can also dig into the source code of Power Tools to see how to create or modify NDepend porjects. This source code can be found in: $NDependInstallPath$\NDepend.PowerTools.SourceCode\NDepend.PowerTools.sln

Categories