Rick Strahl's Weblog  

Wind, waves, code and everything in between...
.NET • C# • Markdown • WPF • All Things Web
Contact   •   Articles   •   Products   •   Support   •   Advertise
Sponsored by:
West Wind WebSurge - Rest Client and Http Load Testing for Windows

Getting burned by .NET 3.0 "Framework" Install


:P
On this page:

Aaargh… as I just have reinstalled Vista on this machine I ran into a little glitch with Help Builder today. Help Builder uses a .NET Interop assembly for importing .NET types and entire into Help its help content and since Help Builder is not a .NET application it uses COM interop to interface with .NET to provide for the needed Reflection APIs. I’ve basically built a wrapper around the various Reflection functions that handle the type information collection, formatting as well as picking up the XML comments.

 

All that is good and well, but COM interop has always been a pain in the ass because of the way that COM Interop assemblies register with RegAsm. Basically you need register with RegAsm.exe – which is a private component - rather than regsvr32.exe (which is a public component) and the big issue is finding where the right version of RegAsm.exe lives. Many installers don’t do regasm registration automatically so I’ve traditionally handled this in my application code.

 

The registration code I use currently checks for the .NET version by looking in the .NET Framework path and trying to find the highest installed version and using that on the assumption if the path exists it will be able to find the right utilities.

 

Now .NET 3.0 comes along and installs its files there, but of course .NET 3.0 isn’t really version 3.0 of the framework, but 2.0 with additional stuff. So we’ll have C# 2.0, ASP.NET 2.0 but we’re running the .NET Framework 3.0. This is absolutely silly - what are those guys at Microsoft smoking to come up with ideas like this? There’s going to be lots of code that breaks because of this non-sense. WinFx sounds to me like a platform update – these components are system components that are really part of Windows or the OS layer, not the ‘language’/developer layer.

 

Anyway – I disgress… <s>. For my application this means I’ll have to use a slightly different way to probe for the framework. The fix was easy enough to do: So now I check for the highest version installed and then check for specific files in the framework directory – if they’re not there I go backwards to the previous version and check there and so on. The code for this looks something like this (FoxPro code):

 

************************************************************************

* wwUtils :: IsDotNet

****************************************

***  Function: Returns whether .Net is installed

***            Optionally returns the framework path and version

***            of the highest installed version.

************************************************************************

FUNCTION IsDotNet(lcFrameworkPath,lcVersion)

LOCAL loAPI as wwAPI, x

 

lcVersion = ""

lcFrameworkPath = ""

 

loAPI = CREATEOBJECT("wwAPI")

lcWinDir = loAPI.getSystemdir(.t.)

 

IF EMPTY(lcVersion)

   *** If ASP.NET is not registered RootVer is not set

   *** we need a different way: probe for specific versions

   lcVersion = "v2.0.50727"

  

   *** Try to find the largest version number

   lcFrameworkPath = lcWinDir + "Microsoft.NET\Framework\"

   lnCount = ADIR(laNetDirs,lcFrameworkPath + "v?.*.*","D")

 

   *** Start with the latest version and go backwards

   *** until we find RegAsm

   FOR x = lnCount TO 1 STEP -1

      lcVersion = laNetDirs[x,1]

      lcTPath = ADDBS(lcFrameworkPath + lcVersion )

      IF FILE(lcTPath + "regasm.exe")

         lcFrameworkPath = lcTPath

         EXIT

      ENDIF

   ENDFOR  

   RETURN .T.

ENDIF

 

*** Strip of the build number and replace with 0

lnAt = AT(".",lcVersion,3)

IF lnAt > 0

   lcVersion = SUBSTR(lcVersion,1,lnAt) + "0"

ENDIF

 

lcFrameworkPath = loAPI.Readregistrystring(HKEY_LOCAL_MACHINE,"Software\Microsoft\ASP.Net\"+lcVersion,"PATH")

IF ISNULL(lcFrameworkPath)

   lcFrameworkPath = ""

ELSE

   lcFrameworkPath = ADDBS(lcFrameworkPath)

ENDIF  

 

RETURN .T.

ENDFUNC

*  wwUtils :: IsDotNet


BTW, to add insult to injury when Vista installed it added directories for all versions of .NET. There’s 1.0, 1.1, 2.0 and 3.0, but of course only 2.0 actually includes actual framework files.


The Voices of Reason


 

Philip Rieck
August 28, 2006

# re: Getting burned by .NET 3.0 &quot;Framework&quot; Install

If you're doing this from code, you can skip the RegAsm altogether and use the System.Runtime.InteropServices.RegistrationServices class (in mscorlib). I believe RegAsm.exe is just an executable wrapper around that class.

The nice thing here is that you automatically get the version you're running from.

Rick Strahl
August 28, 2006

# re: Getting burned by .NET 3.0 &quot;Framework&quot; Install

Philip, yeah, but this is not a .NET piece of code - it's a non-.NET app, so that doesn't help. I suppose I could create a small stub EXE that I could run to do the registration for me, but I'd like to avoid adding any more files to the distribution <g>...

For now this approach above works - until Microsoft comes up with another fabulous scheme that'll break it...

Jason Haley
August 28, 2006

# Interesting Finds: August 28, 2006


Philip Rieck
August 28, 2006

# re: Getting burned by .NET 3.0 &quot;Framework&quot; Install

Heh, I suppose I should have noticed that!

It'll also be fun for you when we have "3.0" with some files, but 2.0 dirs actually contain the core CLR (and most tools). Then when we hit 4.5, it's anyone's guess which folders actually contain the runtime, which contain tools, and which contain add-on libraries that were renamed .net for branding reasons.

Kevin Flick
January 12, 2009

# re: Getting burned by .NET 3.0 "Framework" Install

You're right Rick. Windows development seems to be increasingly becoming an undocumented bizarro land.

West Wind  © Rick Strahl, West Wind Technologies, 2005 - 2024