I've inherited a rather complex AsP.Net 3.5 web application derived from
Several DLLs. I've used .Net Reflector to examine the DLL contents. However, I am looking for a code analysis tool that might help identify key class files, show how the application makes database calls (it's not obvious from the codebase), and generally suggests ways to improve the codebase.
Does such a (free?) tool exist?
Take a look at NDepend (no, it's not free). It might not do everything you want, but it's a great code analysis tool.
I like AQTime from http://www.automatedqa.com/ for this. There's a free trial. The architecture tools in Visual Studio 2010 Ultimate also allow you to generate graphs from assemblies.
Edit: You can also right-click on any method in VS 2010 and select Generate Sequence Diagram ... which is very helpful sometimes.
how come you use reflector to examine the DLL's rather than visual studio?
There's a reflector plugin to decompile the DLL's back to projects: FileDisassembler
Stepping thru the code in the VS debugger is the best code analysis tool, otherwise possibly even Rd-Gate Perf Profiler to record call stacks over time.
+1 for the architecture tools in Visual Studio 2010
Related
So what I need is some why to write a solution analyzer for Visual Studio, that can:
detect move class and move method refactorings.
display the recommended refactorings in Visual Studio.
apply the refactorings.
I have a console application that can do this (using the Roslyn compiler), but I want to integrate the logic inside Visual Studio. From what I have read, the current code fix/refactoring/analyzers support only document level of refactoring, but for me that is not enough information to recommend one of the mentioned refactorings. I need information about the whole solution.
So my question is what is the best way to do this? Can you recommend a starting point? Some articles related to the topic? Any advice would help me a lot.
Short Answer: There is no reasonable way to do this with the Roslyn API
Long Answer:
The api as it is currently implemented only allows analyzers to know about things in the current compilation (a project in Visual Studio). If you call RegisterCompilationAction from within the Initalize method in your analyzer, you will be able to look at all the symbols within the compilation.
Why can't analyzers see the scope for an entire solution? The simplest answer is: because the compiler can't, and analyzers run inside the compiler. This is done so that analyzers can be run on continuous integration servers without Visual Studio installed. MSBuild reads the solution file and then invokes the compiler once for each project. The compiler is never aware of project dependencies and the compiler team does not want to be in that business, they are happy to leave it to MSBuild.
People have tried to work around this by loading their solution using MSBuildWorkspace and attempting to look at documents across projects that way. This will fail occasionally because MSBuildWorkspace is not thread-safe. It will also cause memory usage to skyrocket. People have tried to cache MSBuildWorkspace instances to partially resolve this problem but the cache needs to be invalidated every time a new compilation is created (essentially in the event of all but the most trivial changes). Basically, going down this path is rife with pain and is unsupported.
Enough people have asked for this feature that its something we think we need to do eventually. There is no reasonable way to accomplish it today unless you are willing to write a Visual Studio extension that imports the Visual Studio Workspace and attempts to run its own analysis engine. Please file feature request on https://github.com/dotnet/roslyn
Does roslyn or visual studio 2015 provide API to rewrite IL or "something like that"? Let me explain...
I've read in msdn magazine's article Use Roslyn to Write a Live Code Analyzer, that it is possible to write custom code analyzers distributed via nuget packages, without need for visual studio plugins.
I'm really curious, if roslyn compiler and visual studio 2015 will allow to implement e.g. Code Cotracts such way, that no plugin is required to build it correctly.
Also, I would like to gain productivity and readability of my code with aspects like [NotifyPropertyChanged] data annotation on properties, but again, if it won't build correctly on every machine with visual studio 2015, it's not a good idea.
It is possible to use DispatchProxy from System.Reflection.DispatchProxy package. Unfortunately I haven't found any examples how to use it, but it looks like a replacement for RealProxy class with some differences (examples how to use RealProxy: hear and here).
I'm beginning to work on a COBOL/BASIC IDE at work (to replace the one that we have currently that's a slight step up from Notepad). It'll be made in C#. The management is really interested in implementing some Visual Studio type features, and a big one is code folding. I've looked on MSDN, but I didn't see any good way to collapse lines (or to add the expand/collapse buttons).
I'm assuming that the text area should be a RichTextBox. Am I off track here? I suppose it could be done with some sort of modified TreeView, but that seems a little wrong to me. Is there some way of doing this that I'm just missing?
Why not use an existing IDE and extend it? Writing one from scratch is a huge undertaking (you need a parser, lexer, syntax highlighter and more), and is even more complicated if you need to support multiple languages (you mention COBOL and Basic).
Notepad++ has syntax coloring and one can add languages to it - COBOL is one of the ones installed by default. It supports code folding and has many plugins (you can write your own, that will suit your needs).
Edit:
Eclipse is another excellent IDE that has similar support, and as mentioned in the comments has a COBOL plug-in.
I suggest you take a look at SharpDevelop. It's a pretty good IDE with a bunch of Visual Studio like features already built in. It's written in C# and fully supports code folding with syntax highlighting in several languages. Plus, it's Open Source under the LGPL license. So, if you don't want to base your app on SharpDevelop then you can still reuse some of their controls like the code editor or windowing toolkit.
You should consider adding the COBOL language to SharpDevelop instead of starting from scratch. If you can't do this, then you can still use the SharpDevelop code as a decent reference on how to make a good IDE work.
Sometimes embedding Eclipse or a full-fledged editor is not appropriate. It's overkill or overweight or wrong for some other reason. I appreciate the first inclination suggested in other posts to not re-invent here, but in some cases a small invention is what is necessary. For example, the textbox used to make Stack Overflow posts .... is neither Eclipse nor an embedded Visual Studio. I wonder why?
It's important to ask the question - build it or buy it? - but sometimes, the correct answer is BUILD IT.
XPathVisualizer provides a simple example of a code-folding text editor implemented in C#, and based on a RichTextBox. It's not VB, though - it's an XML editor. But the general principles apply.
Here's a look at it.
To implement XML syntax colorization dynamically, while the user types, it uses a separate background thread. The reasons why and some of the details are described in a separate answer on Stack Overflow.
You could do something similar for your COBOL/VB thing. XPathVisualizer is open source, licensed with MS-PL, so you can browse and borrow.
If your team is used to "Visual Studio features," then I'll assume you use Visual Studio there at the office. Here are my suggestions:
Base your IDE on Visual Studio, for the following reasons:
Use Visual Studio 2010 if possible. The SDK is greatly improved from 2008/earlier.
Use Visual Studio 2008/2005 otherwise. At the moment, all of my commercial IDE products only support 2005/2008.
If your team uses Visual Studio, they will hate Eclipse. Not even an option to consider in this case unless you choose to use an existing Eclipse plug-in, saving you the time of creating a new IDE.
If your team isn't using Visual Studio 2010, you can use the Visual Studio 2010 Shell in Integrated Mode for free (Isolated Mode is not what you want). This lets you use Visual Studio 2010 for your IDE for now, and should the team upgrade later to one of the full versions of Visual Studio 2010, the IDE for your language will cleanly integrate into the full version. Edit: Visual Studio Shell is basically the core of Visual Studio without any specific languages (C#, C++, VB, etc.) included. Microsoft provides this core for free, and it's a great option specifically for people interested in creating their own language support.
Read my answers in the following two questions:
Here's a longer post on my reasons for using 2010 over 2008: How do I implement intellisense support for a custom DLR language in VS2008?
Here's a very long answer on implementing various features (most of which are based on the 2005/2008 SDK): How do i implement intellisense for my language in visual studio?
Writing a complete IDE is a HUGE task. I would recommend trying to find an existing one that has what you want, or make adaptions to an existing open source IDE.
To answer your question: I guess that the Visual Studio IDE uses a custom control, written from scratch, rather than a RichText control.
In Visual Studio 2005 and prior you could export your code to Visio and view the relationships between the objects and what methods, properties and fields it had. This was great as it allowed you to tweak the appearance to improve the look.
In VS 2008 that option is gone, replaced (supposedly) with the class diagram system. It is functional but not pretty.
What I am looking for is some software that allows me to visualise in a prettier way or at least provide me with enough options to filter, arrange and so on so that I could touch it up in something else.
Do you require the software to be free? If not, you might consider a UML tool like Sparx Enterprise Architect. It can import your code, and has two add-ons that go further in terms of Visual Studio integration.
Not quite what you're asking for but it's worth checking out some of the add-ins for .Net Reflector
E.g.
Graph
Dependency Structure Matrix PlugIn for .NET Reflector
100% Reflective Class Diagram Creation Tool
Visual Studio 2010 Ultimate supports UML class, sequence, component, use case, and activity diagrams. It also supports creating sequence, dependency graphs, and layer diagrams from code. Other tools include Architecture Explorer, which lets you browse and explore your solution.
For more info, see the following links:
To download the RC release, visit: Microsoft Visual Studio 2010 Ultimate RC
To see the RC documentation, see Modeling the Application.
To discuss these tools, visit the Visual Studio 2010 Architectural Discovery & Modeling Tools forum.
Have you tried the PowerToys?
NDepend is certainly the .NET tool you are looking for. It comes with a dependency graph coupled with a dependency matrix. You can try NDepend straight on your code by downloading the free Trial Edition.
More on NDepend Dependency Graph
More on NDepend Dependency Matrix:
Disclaimer: I am part of the tool team
There is a decent, free version of a UML diagramming tool called Argos here http://argouml.tigris.org/features.html. Out of the box it can both forward and reverse engineer Java, I'm fairly certain there are add-ins for Visual Studio that help support forward and reverse engineering of C# code. I would look into that.
Not your answer, but related...
Codeplex's VisioAutoExt library:
http://www.codeplex.com/visioautoext
Visio ActiveX component:
http://www.c-sharpcorner.com/UploadFile/mgold/VisioInDotNet12032006222024PM/VisioInDotNet.aspx
When i search for code in codeplex i found this http://vsdm.codeplex.com/ maybe help you.
With VS2005 & VS2008 you have the option of designing your own modelling language (DSL) here you can choose how your model is rendered, it would be a big investment if its just to make the diagrams look a little better, but it does provide you with option to customise how the code is generated from your model.
You may have tried PowerDesigner, it runs under Eclipse through a plugin and it also supports Visual Studio. The only downside is that it only works on Windows.
Another application for modeling is System Architect from IBM (Popkin). It has been used by some major corporations and is still maintained.
How can I convert my C# code to DLL file in a way that the user of DLL can’t view my source code?
When I make DLL in the way I always do by making a class library project, importing my classes and compiling it, the source code can still be viewed.
I believe you are looking for an obfuscator. This is a tool that will take a compiled DLL and rewrite the code with the intent of it not being meaningfully decompiled by another user. Visual Studio comes with a free Dotfuscator
Note, this will not actually prevent people from looking at your code. They will instead be looking at a very weird translation of your code. There is no way to prevent people from looking at decompiled versions of your code in C# or any other .Net language for that matter.
This is not something that is unique to C#. It is fact a flaw of every language in existence. It's perfectly possible to decompile C code. The difference though is it's much easier to maintain a lot of the original code structure when decompiling managed languages (.Net and Java for instance) because the metadata maintains the original structure.
obfuscation is what you want to search for.
There is a free one (that is limited) in visual studio called Dotfuscator.
Uses fancy methods to rename your code and alter flowpaths to obscure it.
Consider using an obfuscator.
If you are developing desktop applications converting your code to Dll will not hide the it( there are many tools to decompile the dll or exe files).
but if you are using Asp.Net, then you can compile your site to Dll, and the code will not be visible in the aspx pages, it will be compiled to Dll, you can do that by right click on your project on solution explorer, then choose Publish website
But in all cases .Net Exe files and DLL will be easy to decompile and extract the source code again, unless you use tool to obfuscator your code.
If you mean, the end-user can view your source code by decompiling it, you can protect yourself using an obfuscator.
There is standard obfuscator build in into Visual Studio. In the menu choose Tools / Dotfuscator community edition.
I think my reply to a similar question about JavaScript obfuscation applies here as well: in short, why bother? Your question has already been answered here ("use an obfuscator"), but I thought it wouldn't hurt to find out what your motivations are. Generally, code that you give to people is "in the hands of the enemy" -- if somebody wants to use it/figure out how it works badly enough, they will.