The Artima Developer Community
Sponsored Link

.NET Buzz Forum
How do I get the .NET Framework directory?

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Ashish Shetty

Posts: 402
Nickname: nerddawg
Registered: Oct, 2004

Ashish Shetty is a Program Manager at Microsoft.
How do I get the .NET Framework directory? Posted: Oct 2, 2006 9:43 AM
Reply to this message Reply

This post originated from an RSS feed registered with .NET Buzz by Ashish Shetty.
Original Post: How do I get the .NET Framework directory?
Feed Title: Even a chimp can write code
Feed URL: http://nerddawg.blogspot.com/rss.xml
Feed Description: Ideas on software and elsewhere by Ashish Shetty: erstwhile chimp and occasional re-inventor of the wheel.
Latest .NET Buzz Posts
Latest .NET Buzz Posts by Ashish Shetty
Latest Posts From Even a chimp can write code

Advertisement

Let's look at several ways to slice this one:

Hard code the path
Use %WinDir%\Microsoft.NET\Framework\v2.0.50727
This method is fragile and involves knowing the several things not least the version of the Framework. If you were looking for simplicity, say in the WiX configuration file, you might go with this. Otherwise, there are much better options available.


HttpRuntime.ClrInstallDirectory
If you're in ASP.NET or otherwise already have a reference to System.Web.dll, you may want to use the HttpRuntime.ClrInstallDirectory property. Otherwise, this may not be worth loading yet another assembly.


GetCORSystemDirectory
The GetCORSystemDirectory method, in mscoree.dll, returns the fully qualified installation dir of .NET Framework loaded into the current process.

HRESULT GetCORSystemDirectory (  LPWSTR pbuffer, DWORD cchBuffer, DWORD* dwlength );

pbuffer - [out] Buffer in which the runtime returns a string containing the fully qualified name of the installation directory of the runtime

cchBuffer - [in] the size in bytes of pbuffer

dwlength - [out] The number of chars returned in pbuffer

Of course, if your managed code file needs this info, you'll need p/invoke.


RuntimeEnvironment.GetRuntimeDirectory
My personal favorite. The RuntimeEnvironment class is in the System.Runtime.InteropServices namespace. I'd use RuntimeEnvironment.GetRuntimeDirectory() simply for elegant, readable and maintable code. Plus, it is in mscorlib.dll.


This post is by no means comprehensive. If you know of a better way to do this, please drop a comment.


Tags: , ,

Read: How do I get the .NET Framework directory?

Topic: High performance SOA - an oxymoron? Umm, no. Previous Topic   Next Topic Topic: Letting your users do your bidding

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use