A useful helper class from the Microsoft.Build.Utilities (v4.0) assembly: ToolLocationHelper.
With this helper it is easy to retrieve the location of MSBuild.exe and gacutil.exe.
//Gacutil: ToolLocationHelper. GetPathToDotNetFrameworkSdkFile("gacutil.exe", TargetDotNetFrameworkVersion.VersionLatest) //MSBuild: ToolLocationHelper. GetPathToDotNetFrameworkFile("msbuild.exe", TargetDotNetFrameworkVersion.Version40)
Use the overload with DotNetFrameworkArchitecture to retrieve the location of the 32 or 64 bit version or use Current to retrieve the version corresponding the current process. The latter can be used when the MSBuild.ToolPlatform property of your custom activity is set to “Auto”.
Mind the difference between GetPathToDotNetFrameworkFile and GetPathToDotNetFrameworkSdkFile.