By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,282 Members | 1,491 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,282 IT Pros & Developers. It's quick & easy.

How to get .NET version programmatically?

P: n/a
Hi,

Is there a programmatic way to get the "general" or "overall" version of a
currently running instance of the Visual Studio .NET compiler? What I mean
by "general" or "overall" version is, I want to programmatically get the
version string that I see in the registry underneath the
HKLM\SOFTWARE\Microsoft\VisualStudio key, such as "7.0" or "7.1" (for .NET
2002 or .NET 2003, respectively). My registry contains both 7.0 and 7.1
keys, so I want to know which one I'm currently running. Note that I am not
interested in getting the CLR version (that is, the version that is returned
by the GetCORVersion() call).

Thanks!
--
Whitney Kew
Software Engineer
Rain Bird Corporation
http://rainbird.com
Jul 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
What is someone has both 2002 and 2003 installed side-by-side?

Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph

Whitney Kew wrote:
Hi,

Is there a programmatic way to get the "general" or "overall" version of a
currently running instance of the Visual Studio .NET compiler? What I mean
by "general" or "overall" version is, I want to programmatically get the
version string that I see in the registry underneath the
HKLM\SOFTWARE\Microsoft\VisualStudio key, such as "7.0" or "7.1" (for .NET
2002 or .NET 2003, respectively). My registry contains both 7.0 and 7.1
keys, so I want to know which one I'm currently running. Note that I am not
interested in getting the CLR version (that is, the version that is returned
by the GetCORVersion() call).

Thanks!

Jul 21 '05 #2

P: n/a
Your question is a bit intriguing, because:

- At coding time, you know which VS.NET version you are using.

- At run-time, the executable can be running with .NET Framework 1.0 or 1.1,
depending on its configuration and the .NET Version on the target machine,
but it seems that you are not interested in the .NET Framework version
(returned by System.Environment.Version() )

The only relationship of the running executable with VS.NET is that maybe it
has attached the VS.NET debugger: your code can guess if it is beeing
debugged through System.Diagnostics.Debugger.IsAttached(), but I think that
you can not know which the debugger is.

So, although the goal of your question is beyond me, the only way that I can
think is guessing the running VS.NET through indirect ways, assuming that
you don´t have VS.NET 2002 and 2003 running side by side. For example:

- You can get the processes with the name "devenv.exe" and from there try to
get the path to the file and its version.

- You can get if there are COM objects running with the ProgIDs
"VisualStudio.DTE.7" (VS.NET 2002) or "VisualStudio.DTE.7.1" (VS.NET 2003).
In VB6 you would use the GetObject("MyProgID") function.

--

Carlos J. Quintero (Visual Developer - .NET MVP)

FAQs, Knowledge Base, Files, Docs, Articles, Utilities, etc. for .NET
addins:
http://groups.yahoo.com/group/vsnetaddin/ (free join)


"Whitney Kew" <Wh********@discussions.microsoft.com> escribió en el mensaje
news:FD**********************************@microsof t.com...
Hi,

Is there a programmatic way to get the "general" or "overall" version of a
currently running instance of the Visual Studio .NET compiler? What I mean by "general" or "overall" version is, I want to programmatically get the
version string that I see in the registry underneath the
HKLM\SOFTWARE\Microsoft\VisualStudio key, such as "7.0" or "7.1" (for .NET
2002 or .NET 2003, respectively). My registry contains both 7.0 and 7.1
keys, so I want to know which one I'm currently running. Note that I am not interested in getting the CLR version (that is, the version that is returned by the GetCORVersion() call).

Thanks!
--
Whitney Kew
Software Engineer
Rain Bird Corporation
http://rainbird.com

Jul 21 '05 #3

P: n/a
Hi Carlos,

Thanks for the quick reply! Actually, it's a Custom Tool that runs during a
build. Its "Register for COM Interop" property is set to True, and it has
functions utilizing the [ComRegisterFunction] and [ComUnregisterFunction]
attributes that register and unregister the tool as a custom code generator
with the current version of .NET. Thus, I want the tool to be able to detect
which version of the compiler is being used when the build is occurring, so
that it knows with which .NET version to register before it runs. I
appreciate your solution about getting the file version of the current
running instance of devenv.exe, and that would probably work for us, but I'd
be surprised if there isn't another, more .NET-centric way of getting the
"7.0" or "7.1" strings. Any thoughts?

Whitney Kew

"Carlos J. Quintero [MVP]" wrote:
Your question is a bit intriguing, because:

- At coding time, you know which VS.NET version you are using.

- At run-time, the executable can be running with .NET Framework 1.0 or 1.1,
depending on its configuration and the .NET Version on the target machine,
but it seems that you are not interested in the .NET Framework version
(returned by System.Environment.Version() )

The only relationship of the running executable with VS.NET is that maybe it
has attached the VS.NET debugger: your code can guess if it is beeing
debugged through System.Diagnostics.Debugger.IsAttached(), but I think that
you can not know which the debugger is.

So, although the goal of your question is beyond me, the only way that I can
think is guessing the running VS.NET through indirect ways, assuming that
you don´t have VS.NET 2002 and 2003 running side by side. For example:

- You can get the processes with the name "devenv.exe" and from there try to
get the path to the file and its version.

- You can get if there are COM objects running with the ProgIDs
"VisualStudio.DTE.7" (VS.NET 2002) or "VisualStudio.DTE.7.1" (VS.NET 2003).
In VB6 you would use the GetObject("MyProgID") function.

--

Carlos J. Quintero (Visual Developer - .NET MVP)

FAQs, Knowledge Base, Files, Docs, Articles, Utilities, etc. for .NET
addins:
http://groups.yahoo.com/group/vsnetaddin/ (free join)


"Whitney Kew" <Wh********@discussions.microsoft.com> escribió en el mensaje
news:FD**********************************@microsof t.com...
Hi,

Is there a programmatic way to get the "general" or "overall" version of a
currently running instance of the Visual Studio .NET compiler? What I

mean
by "general" or "overall" version is, I want to programmatically get the
version string that I see in the registry underneath the
HKLM\SOFTWARE\Microsoft\VisualStudio key, such as "7.0" or "7.1" (for .NET
2002 or .NET 2003, respectively). My registry contains both 7.0 and 7.1
keys, so I want to know which one I'm currently running. Note that I am

not
interested in getting the CLR version (that is, the version that is

returned
by the GetCORVersion() call).

Thanks!
--
Whitney Kew
Software Engineer
Rain Bird Corporation
http://rainbird.com


Jul 21 '05 #4

P: n/a
2 more thoughts:

- That kind of things (pre/post build actions) can be done with .NET
add-ins, which offer a direct way of getting the .NET version where they are
hosted (DTE.Version, DTE.Edition, etc.)

- If you are using a custom tool, external to VS.NET, I think that the only
way is to guess the running devenv.exe and get its version as I told you, or
pass the version to the custom tool somehow: for example, external tools can
receive the Solution and Project file names, and since the internal format
of those files is different in 7.0 and 7.1, parsing them you can guess the
target IDE. By the way, how do you call the custom tool when a build is
performed?
--

Carlos J. Quintero (Visual Developer - .NET MVP)

FAQs, Knowledge Base, Files, Docs, Articles, Utilities, etc. for .NET
addins:
http://groups.yahoo.com/group/vsnetaddin/ (free join)

"Whitney Kew" <Wh********@discussions.microsoft.com> escribió en el mensaje
news:D8**********************************@microsof t.com...
Hi Carlos,

Thanks for the quick reply! Actually, it's a Custom Tool that runs during a build. Its "Register for COM Interop" property is set to True, and it has
functions utilizing the [ComRegisterFunction] and [ComUnregisterFunction]
attributes that register and unregister the tool as a custom code generator with the current version of .NET. Thus, I want the tool to be able to detect which version of the compiler is being used when the build is occurring, so that it knows with which .NET version to register before it runs. I
appreciate your solution about getting the file version of the current
running instance of devenv.exe, and that would probably work for us, but I'd be surprised if there isn't another, more .NET-centric way of getting the
"7.0" or "7.1" strings. Any thoughts?

Whitney Kew

Jul 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.