Get Project information from IVsHierarchy - visual-studio-2010

I already get hold of a IVsHierarchy object, the information I want is the project type (WinForm, WPF, ASP, etc.), language (C#, VB, F#, etc.) and debug configuration (debug, release, x86, amd64, etc.). What the reliable way to get this information?
I can get an EnvDTE.Project from the IVsHierarchy, and it contains properties like CodeModel.Language, Kind, and ConfigurationManager.ActiveConfiguration, but I’m not sure those are the right properties to check against. For example, the possible language values are as following
vsCMLanguageCSharp Visual C# constant.
vsCMLanguageIDL Microsoft IDL constant.
vsCMLanguageMC Visual C++ constant.
vsCMLanguageVB Visual Basic constant.
vsCMLanguageVC Visual C++ constant.
This seems to be a very limited list, where are the languages like F#?
It’s even worse for project kind, the only possible values are prjKindCSharpProject, prjKindVBProject, prjKindVSAProject. Is it possible to get more detailed information like C# ASP, VB WPF etc.?

Well, http://www.mztools.com/articles/2008/mz2008017.aspx and How to Get Project Type Guid of selected project in the Solution Explorer by using VS Package gave me a fairly good idea of how to get the project type, and I can also figure out the language type from it. CodeModel seems to be the wrong approach to get it.

Related

Find all references doesn't locate member references in other .NET projects of differing language

I have a VS 2013 solution with one VB.NET ASP.NET project which references several c# class library projects (not DLLs) within the same solution. I made lots of changes to logic within some of the method overloads in one of the c# projects. Since the VB.NET project uses these overloads extensively, I want to see how many places these methods are referenced. I go to the c# project that contains the changes, right-click the overload I want, and select Find All References, but it only shows me the references in the c# projects. However, when I go to one of those methods in the VB.NET project, it finds all the references within the VB.NET project as well as the method declarations in the c# project.
I could do a solution-wide text search for the method name, but this method name is used multiple times because it's overloaded. Therefore, I want to search for a particular overloaded method signature, not the method name.
Is this a known shortcoming of VS 2013? Something else I've also noticed that I've noticed is that selecting Go To Reference from within a VB.NET project on a method that's declared in a c# project will take you to the object browser rather than directly to the method definition in the source project itself.
This is an old problem, there are many bug feedback reports for it on Microsoft's feedback site. The canonical one is probably this one. Quoting Dustin Campbell's response:
The general problem is that C# and Visual Basic do not share any common infrastructure with regard to the symbol tables that are used for features like Find All References, Go to Definition or Rename. So, such features don't work between multiple languages. That said, we are looking at ways to change this in the future, but the work required is very substantial.
Annotating a bit, the C# and VB.NET IDEs look similar at the surface but they are very different under the hood. Part of that is them being supported by distinct groups within Microsoft, a survival strategy for any software company, big groups don't work. But above all history plays a strong role in this, Visual Basic had strong IDE support for a very long time. They did not throw away that work when they moved to VB.NET, not in the least because they had to support all previous IDE features so not to alienate their existing customer base. The C# team got a fresh start without that baggage, they started from scratch. Inevitably the internals between them, like the IntelliSense symbol tables, are drastically different.
Tackling the "common infrastructure" problem was not forgotten, the Roslyn project was the instrumental step. It took a very long time to get finished but it is ready to go today. Integrated into VS2015. Whether it actually solves this problem is something I don't know yet, I will in a couple of months. Maybe somebody that has the RC version can confirm. They did create two versions of Roslyn, one for C# and another for VB.NET. Uh-oh.

Visual Studio UML designer - data types

I'm using the Visual Studio UML designer to create some class diagrams. Since I would like to generate code from the diagrams it need to be accurate.
Now I'm trying to define the type of some properties of my classes, but I can't find a way to give them a type different from bool, string, int and UmlimitedNatural (and my own types of course). I found a tutorials that claims I would have to create custom stereotypes. Really? I mean it's VS, I'm just asking for some build in reference/value types like byte or GUID.
Do I overlook a hidden switch or if there is really now way to tell VS to bring up some commonly used types does anyone know a source for UML profiles that provide it? And how I can define more complex types like generics?
UML is implementation language neutral. Since types differ by platforms it is necessary to define an implementation language profile for any UML tool. Most UML CASE tools include the option to choose the language and apply a built in profile, which should make them available.

Visual C++ browse information

I am trying to figure out what the browse information (.sbr files) is used for but find only references how to create it. So what is it for?
Thanks
Dima
Read here (Visual C++ Team Blog: IntelliSense History, Part 1)
Capturing information about a C or C++
program’s structure has been around
for a very long time in Microsoft’s
products. Preceding even Visual C++
1.0, the compiler supported generating program information through .SBR and
.BSC files. (Note: The compiler in
Visual C++ 1.0 was already version 8,
so the command line tools had been
around a while already.) The SBR
files contain reference and definition
information for a single translation
unit that the compiler generates as it
compiles. These SBR files are
combined in a later step using the
BSCMAKE tool to generate a BSC file.
This file can then be used to look at
many different aspects of a program:
reference, definitions, caller-callee
graphs, macros, etc.
.sbr is pretty much Visual Studio's ctags - an index of symbols with backreferences to the source. When available, it's used by "Find Symbol" and other similar tools. It's more accurate than the built-in VS parser, because C++ can be tricky, and the real compiler can do a better job (though that is not quite true in VS2010 anymore).
At one time browse info drove the "Go to definition" engine, but that has been reworked in later version of Visual C++. Some third-party tools still use browse info (can't remember for sure, but I think one of Rational's tools does) to cross-reference code.
I always disable it, to shorten build times.

Find Programming Language Used

Whats the easiest way to find out what programming language an application was written in?
I would like to know if its vb or c++ or delphi or .net etc from the program exe file.
Try PEiD
of course if they used a packer, some unpacking will need to be done first :)
Start it up and check what run-time DLLs it uses with Process Explorer.
If that doesn't make it immediately obvious, search the web for references to those DLLs.
Most disassemblers (including Olly I think) can easily show you the text contained in an EXE or DLL, and that can also sometimes give a clue. Delphi types are often prefixed with T as in TMyClass.
If it's a small executable with no DLL references and no text you might be SOL. At that point you'd need to look for idioms of particular compilers, and it would be mostly guesswork.
There is an art to detecting what language a program was written in. It is possible but there are no hard and fast rules. It takes a lot of experience (and it also leads to the question "Why would you want to..." but here are a few ideas on how to go about it.
What you're looking for is a "signature". The signature could be a certain string that is included by the compiler, a reference to an API that is quite common in the programming tool being used, or even a style of programing that is common to the tools being used, visible in the strings contained in the application.
In addition, there are styles to how an application is deployed: various configuration files found in the deployment directory, dlls and assemblies and even images, directories or icons.
Java applications wrapped in a self-launching executable will contain references to java libs, and will likely have certain libraries or files included in the same directory that indicate that it's java.
As indicated in other answers a managed assembly will show certain signs as well: you can open it in Reflector etc. While it is correct that c# and VB are "interchangable" once compiled, it is not true that they are identical. If you use Reflector to disassemble VB code you will quite often see that the assembly references the Microsoft.VisualBasic.dll assembly. You'll be able to tell the difference between Mono applications because they will most likely contain references to the mono assemblies.
Many compilers assemble and link code in certain ways, and leave footprints behind. For example, examining a window executable using "strings: tab in Process Explorer, you'll see a lot of strings. Using these you may be able to determine programming styles, methods called, error or trace methods withint the exe.
An example is that compilers use different mechanisms for localization: Microsoft stores localized strings in XML files or resource files. Other compilers will use a different tactic.
Another example is c++ name mangling. The CodeWarrior compiler uses a different algorithm to mangle the names of the member variables and functions of a call than Visual Studio.
I suppose you could write a book on the subject of accurately determining the lineage of any executable. This subject would probably be called "programming archeology".
You could try using Depends to see what runtime dependancies it has, which might give some clues.
The easiest way is to ask the developer of the program. It does not require any knowledge and utility programs.
Determine Delphi Application
Use eda_preview270.exe (from here) or some other spy tool and check the window class names. If they read like TButton or TfrmBlubb, it's a VCL app. If there is an "Afx" in them, it's probably MFC.
Compiled languages (by this I mean no scripting languages, or Java, .NET, etc.) are compiled into CPU assembly instructions, which is essentially a one-way conversion. It is not usually possible to determine which language a program was written in. However, using a dependency walker, you could potentially determine which runtime library the program was loading (if any) and therefore determine which language it used (e.g. MS Visual C++ 9 uses msvcr90.dll).
you can check is that a .net assembly or not by trying to open with ildasm.exe tool
PE Detective works best for me.
In general, you can't.
If you can load it into Reflector, you know it is a managed assembly.
That's a good question. There isn't any general way to tell, but I bet most compilers and libraries leave a mark in the resulting EXE file. If you wanted to spend a lot of time on it, you could gather a bunch of EXEs written in known languages and scan for common strings. I would image you'd find some.
Dependancy Walker, which someone else mentioned would be a good way to look for telltale dependencies, like versions of MSVCRT, etc
i'd try running the .exe thru a 'strings' program to get assorted hints.
If I remember correctly PE Explorer Disassembler gives some information about compiler that creates given not .net and java binary, for .net use Reflector or ILDAsm tool
The easiest way that I found (at least in computer games) was to look in the "redist" folder nested within the game's main folder. It might be obvious to some of you that are more experienced in programming yourself, but the specific purpose of the MSI in this folder is to allow the setup.exe file to automatically install the prerequisites for the game itself.
For example:
In Empire Total War, there is an MSI called "vcredist_x86-sp1.exe". This indicates that the game/program was written in Microsoft's "Visual C 2005" in the .NET Framework (usually).
In fact, if you open the MSI/EXE, the installer should immediately indicate the language it's written in and which version.
The reason I'm familiar is because I code in C# and VB in the .NET Framework and we auto-install the prerequisites for our business app.
Hope this helps!

Why the option to use attributes in new ATL projects was removed from Visual Studio 2008?

This is the text from MSDN comment: "According to the book ATL Internals (2ed) the use of attributes is deprecated and should not be used in new ATL projects."
But WHY?!!
In ATL these attributes were a compiler trick. They were not a core part of the platform like attributes in C#. They were also more confusing to debug than macros's and the method of dumping generated attribute code was a hassle.
I suspect another issue is likely to have been C++ compiler compatibility and standards-adherence. Attributes didn't make for more beautiful C++ code, and perhaps this syntax may be used in a future version of a real C++ standard.
Appendix D of the book goes into this.
Attributed ATL requires compiler extensions, and the problems encountered include
debugging either code generated by the attribute or the interaction between the attribute and your code
no control over the code generated
bugs, especially around connection points

Resources