Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / CompMod / System / CodeDOM / Compiler / RedistVersionInfo.cs / 1305376 / RedistVersionInfo.cs
//------------------------------------------------------------------------------
//
//
// [....]
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.CodeDom.Compiler {
using System;
using System.Diagnostics;
using System.IO;
using System.CodeDom.Compiler;
using System.Configuration;
using System.Collections.Generic;
using Microsoft.Win32;
// The default compiler is the one corresponding to the current-running version of the runtime.
// Customers can choose to use a different one by setting a provider option.
internal static class RedistVersionInfo {
// Version identifier added for Dev10. Takes the full path, doesn't depend on registry key
internal const String DirectoryPath = "CompilerDirectoryPath"; // location
// Version identifier added for Orcas. Depends on registry key.
internal const String NameTag = "CompilerVersion"; // name of the tag for specifying the version
internal const String DefaultVersion = InPlaceVersion; // should match one of the versions below
internal const String InPlaceVersion = "v4.0"; // Default
internal const String RedistVersion = "v3.5"; // May change with servicing
internal const String RedistVersion20= "v2.0";
private const string MSBuildToolsPath = "MSBuildToolsPath";
private const string dotNetFrameworkRegistryPath = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\MSBuild\\ToolsVersions\\";
public static string GetCompilerPath(IDictionary 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;
}
/// this method returns the location of the Orcas compilers, but will return whatever
/// version is requested via the COMPlus_ environment variables first
private static string GetCompilerPathFromRegistry(String versionVal) {
string dir = null;
// if this is running in a private running environment such as Razzle, we would use the path
// based on the environment variables: COMPLUS_InstallRoot and COMPLUS_Version.
string comPlus_InstallRoot = Environment.GetEnvironmentVariable("COMPLUS_InstallRoot");
string comPlus_Version = Environment.GetEnvironmentVariable("COMPLUS_Version");
if (!string.IsNullOrEmpty(comPlus_InstallRoot) && !string.IsNullOrEmpty(comPlus_Version))
{
dir = Path.Combine(comPlus_InstallRoot, comPlus_Version);
if (Directory.Exists(dir))
return dir;
}
String versionWithoutV = versionVal.Substring(1);
String registryPath = dotNetFrameworkRegistryPath + versionWithoutV;
dir = Registry.GetValue(registryPath, MSBuildToolsPath, null) as string;
if (dir != null && Directory.Exists(dir)) {
return dir;
}
return null;
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------
//
//
// [....]
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.CodeDom.Compiler {
using System;
using System.Diagnostics;
using System.IO;
using System.CodeDom.Compiler;
using System.Configuration;
using System.Collections.Generic;
using Microsoft.Win32;
// The default compiler is the one corresponding to the current-running version of the runtime.
// Customers can choose to use a different one by setting a provider option.
internal static class RedistVersionInfo {
// Version identifier added for Dev10. Takes the full path, doesn't depend on registry key
internal const String DirectoryPath = "CompilerDirectoryPath"; // location
// Version identifier added for Orcas. Depends on registry key.
internal const String NameTag = "CompilerVersion"; // name of the tag for specifying the version
internal const String DefaultVersion = InPlaceVersion; // should match one of the versions below
internal const String InPlaceVersion = "v4.0"; // Default
internal const String RedistVersion = "v3.5"; // May change with servicing
internal const String RedistVersion20= "v2.0";
private const string MSBuildToolsPath = "MSBuildToolsPath";
private const string dotNetFrameworkRegistryPath = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\MSBuild\\ToolsVersions\\";
public static string GetCompilerPath(IDictionary 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;
}
/// this method returns the location of the Orcas compilers, but will return whatever
/// version is requested via the COMPlus_ environment variables first
private static string GetCompilerPathFromRegistry(String versionVal) {
string dir = null;
// if this is running in a private running environment such as Razzle, we would use the path
// based on the environment variables: COMPLUS_InstallRoot and COMPLUS_Version.
string comPlus_InstallRoot = Environment.GetEnvironmentVariable("COMPLUS_InstallRoot");
string comPlus_Version = Environment.GetEnvironmentVariable("COMPLUS_Version");
if (!string.IsNullOrEmpty(comPlus_InstallRoot) && !string.IsNullOrEmpty(comPlus_Version))
{
dir = Path.Combine(comPlus_InstallRoot, comPlus_Version);
if (Directory.Exists(dir))
return dir;
}
String versionWithoutV = versionVal.Substring(1);
String registryPath = dotNetFrameworkRegistryPath + versionWithoutV;
dir = Registry.GetValue(registryPath, MSBuildToolsPath, null) as string;
if (dir != null && Directory.Exists(dir)) {
return dir;
}
return null;
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ColumnReorderedEventArgs.cs
- DataViewSettingCollection.cs
- StartFileNameEditor.cs
- XmlSchemaImport.cs
- BackgroundWorker.cs
- ObjectManager.cs
- XmlReaderSettings.cs
- WindowsListViewItem.cs
- BackoffTimeoutHelper.cs
- EncryptedType.cs
- SmiEventSink.cs
- LabelTarget.cs
- CodeAttachEventStatement.cs
- ListMarkerLine.cs
- TogglePattern.cs
- ImageAnimator.cs
- Schema.cs
- addressfiltermode.cs
- EntryPointNotFoundException.cs
- ApplicationException.cs
- StreamUpgradeProvider.cs
- ApplicationContext.cs
- Constants.cs
- BuildManagerHost.cs
- InfoCardArgumentException.cs
- ChineseLunisolarCalendar.cs
- RegistrationServices.cs
- TransferRequestHandler.cs
- ItemTypeToolStripMenuItem.cs
- RequestCache.cs
- PixelFormat.cs
- CommandManager.cs
- EventLogPermissionEntry.cs
- System.Data.OracleClient_BID.cs
- WeakKeyDictionary.cs
- Vector3DValueSerializer.cs
- XmlQueryCardinality.cs
- HostUtils.cs
- ValidatorCompatibilityHelper.cs
- PropertyBuilder.cs
- WsatConfiguration.cs
- CallContext.cs
- FlowDocumentPageViewerAutomationPeer.cs
- NameScope.cs
- ServerType.cs
- SafeSystemMetrics.cs
- WebRequestModuleElement.cs
- ServerIdentity.cs
- ComponentChangedEvent.cs
- EditorAttributeInfo.cs
- EngineSiteSapi.cs
- DataGridSortingEventArgs.cs
- WeakReferenceEnumerator.cs
- DataServiceClientException.cs
- HttpServerUtilityWrapper.cs
- JavascriptCallbackBehaviorAttribute.cs
- PageCache.cs
- DataGridViewComboBoxColumn.cs
- StorageTypeMapping.cs
- EmptyEnumerator.cs
- PropertyGridCommands.cs
- DispatcherEventArgs.cs
- ByteStorage.cs
- KeyManager.cs
- PropertyFilter.cs
- InlineObject.cs
- ISFTagAndGuidCache.cs
- XmlAttributes.cs
- OdbcReferenceCollection.cs
- Int64Animation.cs
- WebPart.cs
- HtmlInputButton.cs
- SymDocumentType.cs
- SchemaMerger.cs
- PathFigureCollection.cs
- StringUtil.cs
- TextEditorMouse.cs
- cryptoapiTransform.cs
- ListViewContainer.cs
- TextSelectionProcessor.cs
- CounterCreationData.cs
- WebPartTracker.cs
- HatchBrush.cs
- ProxyFragment.cs
- WindowsGraphics2.cs
- CultureMapper.cs
- SQLResource.cs
- DocumentViewerConstants.cs
- PassportPrincipal.cs
- PeerChannelFactory.cs
- CryptoConfig.cs
- TypeReference.cs
- DynamicDiscoSearcher.cs
- ToolStripItemEventArgs.cs
- TrackingStringDictionary.cs
- HtmlInputHidden.cs
- tooltip.cs
- SqlBuilder.cs
- UnsafeNativeMethods.cs
- ProcessProtocolHandler.cs