public static string GetCompilerPath(IDictionary <string, string> provOptions, string compilerExecutable)
{
// Get the location of the runtime, the usual answer
string compPath = Executor.GetRuntimeInstallDirectory();
// if provOptions is provided check to see if it alters what version we should bind to.
// provOptions can be null if someone does new VB/CSCodeProvider(), in which case
// they get the default behavior.
if (provOptions != null)
{
string directoryPath;
bool directoryPathPresent = provOptions.TryGetValue(DirectoryPath, out directoryPath);
string versionVal;
bool versionValPresent = provOptions.TryGetValue(NameTag, out versionVal);
if (directoryPathPresent && versionValPresent)
{
throw new InvalidOperationException(SR.GetString(SR.Cannot_Specify_Both_Compiler_Path_And_Version, DirectoryPath, NameTag));
}
// If they have an explicit path, use it. Otherwise, look it up from the registry.
if (directoryPathPresent)
{
return(directoryPath);
}
// If they have specified a version number in providerOptions, use it.
if (versionValPresent)
{
switch (versionVal)
{
case RedistVersionInfo.InPlaceVersion:
// Use the RuntimeInstallDirectory, already obtained
break;
case RedistVersionInfo.RedistVersion:
// lock to the Orcas version, if it's not available throw (we'll throw at compile time)
compPath = GetCompilerPathFromRegistry(versionVal);
break;
case RedistVersionInfo.RedistVersion20:
//look up 2.0 compiler path from registry
compPath = GetCompilerPathFromRegistry(versionVal);
break;
default:
compPath = null;
break;
}
}
}
if (compPath == null)
{
throw new InvalidOperationException(SR.GetString(SR.CompilerNotFound, compilerExecutable));
}
return(compPath);
}