private void OpenSourceCode(Assembly assembly) { string[] projectpath = assembly.FullName.Split(','); var folder = projectpath[0].Split('.')[1].Replace("demos", ""); if (folder == "chart") { folder = folder + "s"; } string frameworkVersion = new System.Runtime.Versioning.FrameworkName(AppDomain.CurrentDomain.SetupInformation.TargetFrameworkName).Version.ToString(); frameworkVersion = frameworkVersion.ToString().Replace(".", string.Empty); string project = projectpath[0] + "_" + frameworkVersion + ".sln"; string root = System.IO.Path.GetFullPath(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"..\\..\\" + folder + "\\" + project)); if (!File.Exists(root)) { return; } try { var process = new ProcessStartInfo { FileName = root, UseShellExecute = true }; Process.Start(process); } catch (Exception e) { ErrorLogging.LogError("Requested directory not found." + "\n" + e.Message + "\n" + e.StackTrace); } }
/// <summary> /// Generate the set of chained reference assembly paths /// </summary> private IList <String> GetPaths(string rootPath, FrameworkNameVersioning frameworkmoniker) { IList <String> pathsToReturn = null; if (String.IsNullOrEmpty(rootPath)) { pathsToReturn = ToolLocationHelper.GetPathToReferenceAssemblies(frameworkmoniker); } else { pathsToReturn = ToolLocationHelper.GetPathToReferenceAssemblies(rootPath, frameworkmoniker); } if (!SuppressNotFoundError) { // No reference assembly paths could be found, log an error so an invalid build will not be produced. // 1/26/16: Note this was changed from a warning to an error (see GitHub #173). if (pathsToReturn.Count == 0) { Log.LogErrorWithCodeFromResources("GetReferenceAssemblyPaths.NoReferenceAssemblyDirectoryFound", frameworkmoniker.ToString()); } } return(pathsToReturn); }
void InstallPackage(System.Runtime.Versioning.FrameworkName TargetFramework, IPackage Package) { if (Package == null) { throw new ArgumentNullException("Package", "Package cannot be null"); } try { if (!System.IO.Directory.Exists(InstallPath)) { System.IO.Directory.CreateDirectory(InstallPath); } InstallPackageDependencies(TargetFramework, Package); packageManager.InstallPackage(Package, true, false, true); //packageManager.InstallPackage(SelectedValue.Package, false, false, false); PackageInstalled(null, new PackageOperationEventArgs(Package, FileSystem, RepositoryPath + @"\" + Package.Id + "." + Package.Version.ToString())); } catch (Exception ex) { logger.Log(MessageLevel.Error, ex.ToString()); System.Diagnostics.Debug.WriteLine(ex.ToString()); } finally { } }
/// <summary> /// Generate the set of chained reference assembly paths /// </summary> private IList <String> GetPaths(string rootPath, FrameworkNameVersioning frameworkmoniker) { IList <String> pathsToReturn = null; if (String.IsNullOrEmpty(rootPath)) { pathsToReturn = ToolLocationHelper.GetPathToReferenceAssemblies(frameworkmoniker); } else { pathsToReturn = ToolLocationHelper.GetPathToReferenceAssemblies(rootPath, frameworkmoniker); } // No reference assembly paths could be found, log an error so an invalid build will not be produced. // 1/26/16: Note this was changed from a warning to an error (see GitHub #173). Also added the escape hatch // (set MSBUILDWARNONNOREFERENCEASSEMBLYDIRECTORY = 1) in case this causes issues. // TODO: This should be removed for Dev15 if (pathsToReturn.Count == 0) { var warn = Environment.GetEnvironmentVariable(WARNONNOREFERENCEASSEMBLYDIRECTORY); if (string.Equals(warn, "1", StringComparison.Ordinal)) { Log.LogWarningWithCodeFromResources("GetReferenceAssemblyPaths.NoReferenceAssemblyDirectoryFound", frameworkmoniker.ToString()); } else { Log.LogErrorWithCodeFromResources("GetReferenceAssemblyPaths.NoReferenceAssemblyDirectoryFound", frameworkmoniker.ToString()); } } return(pathsToReturn); }
public MainWindow() { InitializeComponent(); ButtonUpdateAll.IsEnabled = false; DataContext = this; // https://api.nuget.org/v3/index.json // https://www.nuget.org/api/v2/ // https://packages.nuget.org/api/v2 // https://nuget.pkg.github.com/open-rpa/index.json #if DEBUG // repo = PackageRepositoryFactory.Default.CreateRepository(@"C:\code\OpenRPA\packages"); repo = PackageRepositoryFactory.Default.CreateRepository(@"C:\code\OpenRPA\packages"); publicrepo = PackageRepositoryFactory.Default.CreateRepository("https://www.nuget.org/api/v2/"); repo = PackageRepositoryFactory.Default.CreateRepository("https://packages.nuget.org/api/v2"); #else repo = PackageRepositoryFactory.Default.CreateRepository("https://packages.nuget.org/api/v2"); #endif logger.Updated += () => { Logs = logger.Logs; }; RepositoryPath = Environment.CurrentDirectory + @"\Packages"; InstallPath = Environment.CurrentDirectory + @"\OpenRPA"; // TargetFramework = new System.Runtime.Versioning.FrameworkName(".NETFramework, Version=4.0"); TargetFramework = new System.Runtime.Versioning.FrameworkName(".NETFramework", new Version("4.6.2")); // TargetFramework20 = new System.Runtime.Versioning.FrameworkName(".NETStandard", new Version("2.0")); LoadPackages(); }
private static PermissionSet GetNamedPermissionSet(string targetZone, ITaskItem[] dependencies, string targetFrameworkMoniker) { FrameworkNameVersioning fn = null; if (!string.IsNullOrEmpty(targetFrameworkMoniker)) { fn = new FrameworkNameVersioning(targetFrameworkMoniker); } else { fn = new FrameworkNameVersioning(".NETFramework", s_dotNet40Version); } int majorVersion = fn.Version.Major; if (majorVersion == Fx2MajorVersion) { return(SecurityUtilities.XmlToPermissionSet((GetXmlElement(targetZone, majorVersion)))); } else if (majorVersion == Fx3MajorVersion) { return(SecurityUtilities.XmlToPermissionSet((GetXmlElement(targetZone, majorVersion)))); } else { return(SecurityUtilities.XmlToPermissionSet((GetXmlElement(targetZone, fn)))); } }
private static bool IsSupportedVersion(FrameworkName frameworkName) { // Look under the following registry to get the list of supported keys, and check for matching // identifier and version. // HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v4.0.30319\SKUs\[TFM] try { var name = new FrameworkName(frameworkName.Identifier, frameworkName.Version); var runtime = Environment.Version; var runtimeVersion = runtime.Major + "." + runtime.Minor + "." + runtime.Build; string path = @"SOFTWARE\Microsoft\.NETFramework\v" + runtimeVersion + @"\SKUs"; var baseKey = Registry.LocalMachine.OpenSubKey(path); foreach (string subKey in baseKey.GetSubKeyNames()) { try { var subKeyName = CreateFrameworkName(subKey); var supportedName = new FrameworkName(subKeyName.Identifier, subKeyName.Version); if (String.Equals(name.FullName, supportedName.FullName, StringComparison.OrdinalIgnoreCase)) { return(true); } } catch { continue; } } } catch { } return(false); }
/// <summary> /// Checks what is the target framework version and initializes the targetFrameworkName /// </summary> private static void InitializeTargetFrameworkName() { string targetFrameworkMoniker = ConfigTargetFrameworkMoniker; // Check if web.config exists, and if not, assume 4.0 if (!WebConfigExists) { s_targetFrameworkName = FrameworkNameV40; ValidateCompilerVersionFor40AndAbove(); } else if (targetFrameworkMoniker == null) { if (BuildManagerHost.SupportsMultiTargeting) { // We check for null because the user could have specified // an empty string. // TargetFrameworkMoniker was not specified in config, // so we need to check codedom settings. InitializeTargetFrameworkNameFor20Or35(); } else { // We are running in a 4.0 application pool or in the aspnet_compiler, // but the target framework moniker is not specified. // Assume it is 4.0 so that the application can run. s_targetFrameworkName = FrameworkNameV40; } } else { // The targetFrameworkMonike is specified, so we need to validate it. InitializeTargetFrameworkNameFor40AndAbove(targetFrameworkMoniker); } }
public void TestGeneralFrameworkMonikerNonExistentOverrideError() { MockEngine engine = new MockEngine(); GetReferenceAssemblyPaths getReferencePaths = new GetReferenceAssemblyPaths(); getReferencePaths.BuildEngine = engine; // Make a framework which does not exist, intentional misspelling of framework getReferencePaths.TargetFrameworkMoniker = ".NetFramewok, Version=v99.0"; try { Environment.SetEnvironmentVariable("MSBUILDWARNONNOREFERENCEASSEMBLYDIRECTORY", "1"); bool success = getReferencePaths.Execute(); Assert.True(success); } finally { Environment.SetEnvironmentVariable("MSBUILDWARNONNOREFERENCEASSEMBLYDIRECTORY", null); } string[] returnedPaths = getReferencePaths.ReferenceAssemblyPaths; Assert.Equal(0, returnedPaths.Length); string displayName = getReferencePaths.TargetFrameworkMonikerDisplayName; Assert.Null(displayName); FrameworkNameVersioning frameworkMoniker = new FrameworkNameVersioning(getReferencePaths.TargetFrameworkMoniker); string message = ResourceUtilities.FormatResourceString("GetReferenceAssemblyPaths.NoReferenceAssemblyDirectoryFound", frameworkMoniker.ToString()); engine.AssertLogContains("WARNING MSB3644: " + message); }
private static Version GetFrameworkNameVersion(FrameworkName name) { if (name == null) { return(null); } return(name.Version); }
private static CompatibleFramework GetSubsetCompatFramework(FrameworkNameVersioning frameworkName) { CompatibleFramework compat = GetFullCompatFramework(frameworkName); compat.Profile = frameworkName.Profile; return(compat); }
static IEnumerable <T> GetCompatibleItems <T>(System.Runtime.Versioning.FrameworkName targetFramework, IEnumerable <T> items) where T : IFrameworkTargetable { IEnumerable <T> compatibleItems; if (VersionUtility.TryGetCompatibleItems(targetFramework, items, out compatibleItems)) { return(compatibleItems); } return(Enumerable.Empty <T>()); }
public Updates() { TargetFramework = new System.Runtime.Versioning.FrameworkName(".NETFramework", new Version("4.6.2")); var cur = new System.IO.DirectoryInfo(Environment.CurrentDirectory); RepositoryPath = cur.Parent.FullName + @"\Packages"; // InstallPath = cur.Parent.FullName + @"\OpenRPA"; InstallPath = cur.Parent.FullName; Updater.OpenRPAPackageManager.Instance.Destinationfolder = InstallPath; }
/// <summary> /// Defines whether this node is valid node for painting the refererence icon. /// </summary> /// <returns></returns> public /*protected, but public for FSharp.Project.dll*/ override bool CanShowDefaultIcon() { if (this.referencedProjectGuid == Guid.Empty || this.ProjectMgr == null || this.ProjectMgr.IsClosed || this.isNodeValid) { return(false); } // For multitargeting, we need to find the target framework moniker for the // reference we are adding, and display a warning icon if the reference targets a higher // framework then what we have. IVsSolution vsSolution = this.ProjectMgr.GetService(typeof(SVsSolution)) as IVsSolution; IVsHierarchy projHier = null; var hr = vsSolution.GetProjectOfGuid(this.ReferencedProjectGuid, out projHier); //Debug.Assert(hr == VSConstants.S_OK, "GetProjectOfGuid was not able to locate a project from a project reference"); if (hr == VSConstants.S_OK) { object otargetFrameworkMoniker = null; hr = projHier.GetProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID4.VSHPROPID_TargetFrameworkMoniker, out otargetFrameworkMoniker); if (!ErrorHandler.Succeeded(hr)) { // Safety check return(false); } if (hr == VSConstants.S_OK) { var thisFrameworkName = new System.Runtime.Versioning.FrameworkName(GetTargetFrameworkMoniker()); var frameworkName = new System.Runtime.Versioning.FrameworkName((string)otargetFrameworkMoniker); if (thisFrameworkName.Version < frameworkName.Version) { return(false); } } } IVsHierarchy hierarchy = null; hierarchy = VsShellUtilities.GetHierarchy(this.ProjectMgr.Site, this.referencedProjectGuid); if (hierarchy == null) { return(false); } //If the Project is unloaded return false if (this.ReferencedProject == null) { return(false); } return(!String.IsNullOrEmpty(this.referencedProjectFullPath) && FSSafe.File.SafeExists(this.referencedProjectFullPath)); }
public void TestGeneralFrameworkMonikerGoodWithInvalidCharInIncludePath() { string tempDirectory = Path.Combine(Path.GetTempPath(), "TestGeneralFrameworkMonikerGoodWithInvalidCharInIncludePath"); string framework41Directory = Path.Combine(tempDirectory, Path.Combine("MyFramework", "v4.1") + Path.DirectorySeparatorChar); string redistListDirectory = Path.Combine(framework41Directory, "RedistList"); string redistListFile = Path.Combine(redistListDirectory, "FrameworkList.xml"); try { Directory.CreateDirectory(framework41Directory); Directory.CreateDirectory(redistListDirectory); string redistListContents = "<FileList Redist='Microsoft-Windows-CLRCoreComp' IncludeFramework='v4.*' Name='Chained oh noes'>" + "<File AssemblyName='System.Xml' Version='2.0.0.0' PublicKeyToken='b03f5f7f11d50a3a' Culture='Neutral' FileVersion='2.0.50727.208' InGAC='true' />" + "<File AssemblyName='Microsoft.Build.Engine' Version='2.0.0.0' PublicKeyToken='b03f5f7f11d50a3a' Culture='Neutral' FileVersion='2.0.50727.208' InGAC='true' />" + "</FileList >"; File.WriteAllText(redistListFile, redistListContents); string targetFrameworkMoniker = "MyFramework, Version=v4.1"; MockEngine engine = new MockEngine(); GetReferenceAssemblyPaths getReferencePaths = new GetReferenceAssemblyPaths(); getReferencePaths.BuildEngine = engine; getReferencePaths.TargetFrameworkMoniker = targetFrameworkMoniker; getReferencePaths.RootPath = tempDirectory; getReferencePaths.Execute(); string[] returnedPaths = getReferencePaths.ReferenceAssemblyPaths; Assert.Empty(returnedPaths); string displayName = getReferencePaths.TargetFrameworkMonikerDisplayName; Assert.Null(displayName); FrameworkNameVersioning frameworkMoniker = new FrameworkNameVersioning(getReferencePaths.TargetFrameworkMoniker); if (NativeMethodsShared.IsWindows) { engine.AssertLogContains("MSB3643"); } else { // Since under Unix there are no invalid characters, we don't fail in the incorrect path // and go through to actually looking for the directory string message = ResourceUtilities.FormatResourceStringStripCodeAndKeyword( "GetReferenceAssemblyPaths.NoReferenceAssemblyDirectoryFound", frameworkMoniker.ToString()); engine.AssertLogContains(message); } } finally { if (Directory.Exists(framework41Directory)) { FileUtilities.DeleteWithoutTrailingBackslash(framework41Directory, true); } } }
public bool IsInFramework(string frameworkIdentifier, string frameworkVersion) { Version version = null; if (!string.IsNullOrEmpty(frameworkVersion)) { // CA1307:Specify StringComparison. Suppressed since a valid string representation of a version would be parsed correctly even if the the first character is not "v". if (frameworkVersion.StartsWith("v")) { System.Version.TryParse(frameworkVersion.Substring(1), out version); } else { System.Version.TryParse(frameworkVersion, out version); } } if (string.IsNullOrEmpty(frameworkIdentifier) && version != null) { throw new ArgumentNullException("frameworkIdentifier"); } Dictionary <string, RedistList> redistDictionary = new Dictionary <string, RedistList>(); foreach (string moniker in ToolLocationHelper.GetSupportedTargetFrameworks()) { FrameworkNameVersioning frameworkName = new FrameworkNameVersioning(moniker); if ((string.IsNullOrEmpty(frameworkIdentifier) || frameworkName.Identifier.Equals(frameworkIdentifier, StringComparison.OrdinalIgnoreCase)) && (version == null || frameworkName.Version == version)) { IList <string> paths = ToolLocationHelper.GetPathToReferenceAssemblies(frameworkName); foreach (string path in paths) { if (!redistDictionary.ContainsKey(path)) { redistDictionary.Add(path, RedistList.GetRedistListFromPath(path)); } } } } string fullName = GetFullName(AssemblyIdentity.FullNameFlags.Default); foreach (RedistList list in redistDictionary.Values) { if (list != null && list.IsFrameworkAssembly(fullName)) { return(true); } } return(false); }
async Task asyncInstallPackageDependencies(System.Runtime.Versioning.FrameworkName TargetFramework, IPackage Package) { if (Package == null) { throw new ArgumentNullException("Package", "Package cannot be null"); } await Task.Factory.StartNew(() => { InstallPackageDependencies(TargetFramework, Package); }); }
private CompatibleFramework GetFullCompatFramework(FrameworkNameVersioning frameworkName) { CompatibleFramework compat = new CompatibleFramework(); compat.Version = frameworkName.Version.ToString(); compat.SupportedRuntime = PatchCLRVersion(Util.GetClrVersion(frameworkName.Version.ToString())); compat.Profile = "Full"; return(compat); }
private static CompatibleFramework GetFullCompatFramework(FrameworkNameVersioning frameworkName) { var compat = new CompatibleFramework { Version = frameworkName.Version.ToString(), SupportedRuntime = PatchCLRVersion(Util.GetClrVersion(frameworkName.Version.ToString())), Profile = "Full" }; return(compat); }
private void DiscoverCompatFrameworks(string moniker) { if (!string.IsNullOrEmpty(moniker)) { var frameworkName = new FrameworkNameVersioning(moniker); if (frameworkName.Version.Major >= 4) { _compatibleFrameworks.Clear(); DiscoverCompatibleFrameworks(frameworkName); } } }
protected override void Invoke(object parameter) { if (parameter is RoutedEventArgs) { string frameworkVersion = new System.Runtime.Versioning.FrameworkName(AppDomain.CurrentDomain.SetupInformation.TargetFrameworkName).Version.ToString(); frameworkVersion = frameworkVersion.ToString().Replace(".", string.Empty); RoutedEventArgs eventArgs = parameter as RoutedEventArgs; Button button = eventArgs.OriginalSource as Button; if (AppDomain.CurrentDomain.BaseDirectory.Contains("Binaries_" + frameworkVersion)) { button.Visibility = Visibility.Visible; } } }
private void OpenSourceCode(Assembly assembly, string buttonName) { string[] projectpath = assembly.FullName.Split(','); var folder = projectpath[0].Split('.')[1].Replace("demos", ""); string frameworkVersion = ""; string project = ""; string root = ""; if (buttonName == "openvisualstudio") { frameworkVersion = new System.Runtime.Versioning.FrameworkName(AppDomain.CurrentDomain.SetupInformation.TargetFrameworkName).Version.ToString(); frameworkVersion = frameworkVersion.ToString().Replace(".", string.Empty); project = projectpath[0] + "_" + frameworkVersion + ".sln"; root = System.IO.Path.GetFullPath(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"..\\..\\" + folder + "\\" + project)); } else if (buttonName == "opengithub") { root = "https://github.com/syncfusion/wpf-demos/tree/master/" + folder; } if (!File.Exists(root) && buttonName == "openvisualstudio") { return; } try { var process = new ProcessStartInfo { FileName = root, UseShellExecute = true }; Process.Start(process); } catch (Exception exception) { if (Application.Current.Windows[0].DataContext != null) { var viewModel = Application.Current.Windows[0].DataContext as DemoBrowserViewModel; if (viewModel.SelectedProduct != null && viewModel.SelectedSample != null) { ErrorLogging.LogError("Product Sample\\" + viewModel.SelectedProduct.Product + "\\" + viewModel.SelectedSample.SampleName + "@@" + "Requested directory not found." + exception.Message + "\n" + exception.StackTrace + "\n" + exception.Source); } else if (viewModel.SelectedShowcaseSample != null) { ErrorLogging.LogError("Product ShowCase\\" + viewModel.SelectedShowcaseSample.SampleName + "\\" + viewModel.SelectedShowcaseSample.SampleName + "@@" + "Requested directory not found." + exception.Message + "\n" + exception.StackTrace + "\n" + exception.Source); } } } }
private void DiscoverCompatibleFrameworks(FrameworkNameVersioning frameworkName) { FrameworkNameVersioning installableFrameworkName = GetInstallableFrameworkName(frameworkName); // if profile is null or empty. if (string.IsNullOrEmpty(installableFrameworkName.Profile)) { _compatibleFrameworks.Add(GetFullCompatFramework(installableFrameworkName)); } else { _compatibleFrameworks.Add(GetSubsetCompatFramework(installableFrameworkName)); _compatibleFrameworks.Add(GetFullCompatFramework(installableFrameworkName)); } }
/// <summary> /// Returns true if the specified project targets .NET Framework 4 or later; otherwise returns false. /// .edmx files in projects that target .NET Framework 4 are EF v4 models. Projects that target /// .NET Framework 3.5 SP1 are EF 3.5 models. /// </summary> /// <param name="project"></param> /// <returns></returns> private bool IsEFv4ModelOrLater(Project project) { bool efv4ModelorLater = false; try { Property targetFrameworkMoniker = project.Properties.Item("TargetFrameworkMoniker"); System.Runtime.Versioning.FrameworkName frameworkName = new System.Runtime.Versioning. FrameworkName(targetFrameworkMoniker.Value.ToString()); efv4ModelorLater = (frameworkName.Version.Major >= 4); } catch { // Nothing to do. } return(efv4ModelorLater); }
/// <summary> /// Finds out what the known framework names and also the latest one /// </summary> private static void InitializeKnownAndLatestFrameworkNames() { IList <string> names = ToolLocationHelper.GetSupportedTargetFrameworks(); Version latestVersion = null; s_knownFrameworkNames = new List <FrameworkName>(); foreach (string name in names) { FrameworkName frameworkName = new FrameworkName(name); s_knownFrameworkNames.Add(frameworkName); Version version = GetFrameworkNameVersion(frameworkName); if (s_latestFrameworkName == null || latestVersion < version) { s_latestFrameworkName = frameworkName; latestVersion = version; } } }
private static IList <string> GetPathToReferenceAssemblies(FrameworkNameVersioning targetFrameworkMoniker) { IList <string> targetFrameworkPaths = null; try { targetFrameworkPaths = ToolLocationHelper.GetPathToReferenceAssemblies(targetFrameworkMoniker); // this returns the chained reference assemblies folders of the framework // ordered from highest to lowest version } catch (InvalidOperationException) { // The chained dirs does not exist // or could not read redistlist for chain } return(targetFrameworkPaths); }
/// <summary> /// codes from GetInstallableFrameworkForTargetFxInternal in /// env/vscore/package/FxMultiTargeting/FrameworkMultiTargetingInternal.cs /// </summary> private static FrameworkNameVersioning GetInstallableFrameworkName(FrameworkNameVersioning frameworkName) { string installableFramework = null; FrameworkNameVersioning installableFrameworkObj; IList <string> referenceAssemblyPaths = GetPathToReferenceAssemblies(frameworkName); if (referenceAssemblyPaths != null && referenceAssemblyPaths.Count > 0) { // the first one in the list is the reference assembly path for the requested TFM string referenceAssemblyPath = referenceAssemblyPaths[0]; // Get the redistlist file path string redistListFilePath = GetRedistListFilePath(referenceAssemblyPath); if (FileSystems.Default.FileExists(redistListFilePath)) { installableFramework = GetInstallableFramework(redistListFilePath); } } // If the installable framework value is not in the redist, there was no redist, or no matching FX we return the sent TFM, // this means frameworks that are installable themselves don't need to specify this property // and that all unknown frameworks are assumed to be installable. if (installableFramework == null) { installableFrameworkObj = frameworkName; } else { try { installableFrameworkObj = new FrameworkNameVersioning(installableFramework); } catch (ArgumentException) { // Redist list data was invalid, behave as if it was not defined. installableFrameworkObj = frameworkName; } } return(installableFrameworkObj); }
public void TestGeneralFrameworkMonikerGoodWithInvalidIncludePath() { string tempDirectory = Path.Combine(Path.GetTempPath(), "TestGeneralFrameworkMonikerGoodWithInvalidIncludePath"); string framework41Directory = Path.Combine(tempDirectory, "MyFramework\\v4.1\\"); string redistListDirectory = Path.Combine(framework41Directory, "RedistList"); string redistListFile = Path.Combine(redistListDirectory, "FrameworkList.xml"); try { Directory.CreateDirectory(framework41Directory); Directory.CreateDirectory(redistListDirectory); string redistListContents = "<FileList Redist='Microsoft-Windows-CLRCoreComp' IncludeFramework='..\\Mooses' Name='Chained oh noes'>" + "<File AssemblyName='System.Xml' Version='2.0.0.0' PublicKeyToken='b03f5f7f11d50a3a' Culture='Neutral' FileVersion='2.0.50727.208' InGAC='true' />" + "<File AssemblyName='Microsoft.Build.Engine' Version='2.0.0.0' PublicKeyToken='b03f5f7f11d50a3a' Culture='Neutral' FileVersion='2.0.50727.208' InGAC='true' />" + "</FileList >"; File.WriteAllText(redistListFile, redistListContents); string targetFrameworkMoniker = "MyFramework, Version=v4.1"; MockEngine engine = new MockEngine(); GetReferenceAssemblyPaths getReferencePaths = new GetReferenceAssemblyPaths(); getReferencePaths.BuildEngine = engine; getReferencePaths.TargetFrameworkMoniker = targetFrameworkMoniker; getReferencePaths.RootPath = tempDirectory; getReferencePaths.Execute(); string[] returnedPaths = getReferencePaths.ReferenceAssemblyPaths; Assert.Equal(0, returnedPaths.Length); string displayName = getReferencePaths.TargetFrameworkMonikerDisplayName; Assert.Null(displayName); FrameworkNameVersioning frameworkMoniker = new FrameworkNameVersioning(getReferencePaths.TargetFrameworkMoniker); string message = ResourceUtilities.FormatResourceString("GetReferenceAssemblyPaths.NoReferenceAssemblyDirectoryFound", frameworkMoniker.ToString()); engine.AssertLogContains(message); } finally { if (Directory.Exists(framework41Directory)) { Directory.Delete(framework41Directory, true); } } }
public void TestGeneralFrameworkMonikerNonExistent() { MockEngine engine = new MockEngine(); GetReferenceAssemblyPaths getReferencePaths = new GetReferenceAssemblyPaths(); getReferencePaths.BuildEngine = engine; // Make a framework which does not exist, intentional mispelling of framework getReferencePaths.TargetFrameworkMoniker = ".NetFramewok, Version=v99.0"; getReferencePaths.Execute(); string[] returnedPaths = getReferencePaths.ReferenceAssemblyPaths; Assert.Equal(0, returnedPaths.Length); string displayName = getReferencePaths.TargetFrameworkMonikerDisplayName; Assert.Null(displayName); FrameworkNameVersioning frameworkMoniker = new FrameworkNameVersioning(getReferencePaths.TargetFrameworkMoniker); string message = ResourceUtilities.FormatResourceString("GetReferenceAssemblyPaths.NoReferenceAssemblyDirectoryFound", frameworkMoniker.ToString()); engine.AssertLogContains(message); }
protected override void Invoke(object parameter) { if (this.AssociatedObject == null) { return; } if (DemoBrowserViewModel.IsStoreApp && AssociatedObject.Name == "opengithub") { AssociatedObject.Visibility = Visibility.Visible; } else if (!DemoBrowserViewModel.IsStoreApp && AssociatedObject.Name == "openvisualstudio") { string frameworkVersion = new System.Runtime.Versioning.FrameworkName(AppDomain.CurrentDomain.SetupInformation.TargetFrameworkName).Version.ToString(); frameworkVersion = frameworkVersion.ToString().Replace(".", string.Empty); if (AppDomain.CurrentDomain.BaseDirectory.Contains("Binaries_" + frameworkVersion)) { AssociatedObject.Visibility = Visibility.Visible; } } }
/// <summary> /// If the target framework moniker is set, generate the correct Paths. /// </summary> public override bool Execute() { FrameworkNameVersioning moniker = null; FrameworkNameVersioning monikerWithNoProfile = null; // Are we targeting a profile. bool targetingProfile = false; try { moniker = new FrameworkNameVersioning(TargetFrameworkMoniker); targetingProfile = !String.IsNullOrEmpty(moniker.Profile); // If we are targeting a profile we need to generate a set of reference assembly paths which describe where the full framework // exists, to do so we need to get the reference assembly location without the profile as part of the moniker. if (targetingProfile) { monikerWithNoProfile = new FrameworkNameVersioning(moniker.Identifier, moniker.Version); } // This is a very specific "hack" to ensure that when we're targeting certain .NET Framework versions that // WPF gets to rely on .NET FX 3.5 SP1 being installed on the build machine. // This only needs to occur when we are targeting a .NET FX prior to v4.0 if (!_bypassFrameworkInstallChecks && moniker.Identifier.Equals(".NETFramework", StringComparison.OrdinalIgnoreCase) && moniker.Version.Major < 4) { // We have not got a value for whether or not the 35 sentinel assembly has been found if (!s_net35SP1SentinelAssemblyFound.HasValue) { // get an assemblyname from the string representation of the sentinel assembly name AssemblyNameExtension sentinelAssemblyName = new AssemblyNameExtension(s_NET35SP1SentinelAssemblyName); string path = GlobalAssemblyCache.GetLocation(sentinelAssemblyName, SystemProcessorArchitecture.MSIL, runtimeVersion => "v2.0.50727", new Version("2.0.57027"), false, new FileExists(FileUtilities.FileExistsNoThrow), GlobalAssemblyCache.pathFromFusionName, GlobalAssemblyCache.gacEnumerator, false); s_net35SP1SentinelAssemblyFound = !String.IsNullOrEmpty(path); } // We did not find the SP1 sentinel assembly in the GAC. Therefore we must assume that SP1 isn't installed if (!s_net35SP1SentinelAssemblyFound.Value) { Log.LogErrorWithCodeFromResources("GetReferenceAssemblyPaths.NETFX35SP1NotIntstalled", TargetFrameworkMoniker); } } } catch (ArgumentException e) { Log.LogErrorWithCodeFromResources("GetReferenceAssemblyPaths.InvalidTargetFrameworkMoniker", TargetFrameworkMoniker, e.Message); return false; } try { _tfmPaths = GetPaths(_rootPath, moniker); if (_tfmPaths != null && _tfmPaths.Count > 0) { TargetFrameworkMonikerDisplayName = ToolLocationHelper.GetDisplayNameForTargetFrameworkDirectory(_tfmPaths[0], moniker); } // If there is a profile get the paths without the profile. // There is no point in generating the full framework paths if profile path could not be found. if (targetingProfile && _tfmPaths != null) { _tfmPathsNoProfile = GetPaths(_rootPath, monikerWithNoProfile); } // The path with out the profile is just the referecne assembly paths. if (!targetingProfile) { _tfmPathsNoProfile = _tfmPaths; } } catch (Exception e) { // The reason we need to do exception E here is because we are in a task and have the ability to log the message and give the user // feedback as to its cause, tasks if at all possible should not have exception leave them. Log.LogErrorWithCodeFromResources("GetReferenceAssemblyPaths.ProblemGeneratingReferencePaths", TargetFrameworkMoniker, e.Message); if (ExceptionHandling.IsCriticalException(e)) { throw; } _tfmPathsNoProfile = null; TargetFrameworkMonikerDisplayName = null; } return !Log.HasLoggedErrors; }
public void LegacyFramework35WithNo30Installed() { FrameworkNameVersioning frameworkName = new FrameworkNameVersioning("Anything", new Version("3.5")); LegacyFrameworkTestHelper legacyHelper = new LegacyFrameworkTestHelper(); legacyHelper.DotNetReferenceAssemblies35Installed = true; legacyHelper.DotNet35Installed = true; legacyHelper.DotNet20Installed = true; // Note no 3.0 IList<string> list = ToolLocationHelper.HandleLegacyDotNetFrameworkReferenceAssemblyPaths(legacyHelper.GetDotNetVersionToPathDelegate, legacyHelper.GetDotNetReferenceAssemblyDelegate, frameworkName); Assert.Equal(2, list.Count); Assert.True(list[0].Equals(LegacyFrameworkTestHelper.DotNet35ReferenceAssemblyPath, StringComparison.OrdinalIgnoreCase)); Assert.True(list[1].Equals(LegacyFrameworkTestHelper.DotNet35FrameworkPath, StringComparison.OrdinalIgnoreCase)); }
public void GetPathToReferenceAssembliesDefaultLocation99() { string targetFrameworkRootPath = Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "Reference Assemblies\\Microsoft\\Framework"); string targetFrameworkIdentifier = ".Net Framework"; Version targetFrameworkVersion = new Version("99.99"); FrameworkNameVersioning frameworkName = new FrameworkNameVersioning(targetFrameworkIdentifier, targetFrameworkVersion, String.Empty); IList<string> directories = ToolLocationHelper.GetPathToReferenceAssemblies(frameworkName); Assert.Equal(0, directories.Count); // "Expected the method to return no paths." }
public void GetPathToReferenceAssembliesNullArgumentGoodFrameworkNameEmptyRoot2() { Assert.Throws<ArgumentException>(() => { FrameworkNameVersioning frameworkName = new FrameworkNameVersioning("Ident", new Version("2.0")); ToolLocationHelper.GetPathToReferenceAssemblies(String.Empty, frameworkName); } ); }
public void DisplayNameGeneration() { string redistString40 = "<FileList Redist='Random' Name='MyFramework 4.0' >" + "<File AssemblyName='System' Version='4.0.0.0' PublicKeyToken='b77a5c561934e089' Culture='neutral' ProcessorArchitecture='MSIL' FileVersion='4.0.0.0' InGAC='false' />" + "</FileList >"; string redistString39 = "<FileList Redist='Random'>" + "<File AssemblyName='System' Version='4.0.0.0' PublicKeyToken='b77a5c561934e089' Culture='neutral' ProcessorArchitecture='MSIL' FileVersion='4.0.0.0' InGAC='false' />" + "</FileList >"; string tempDirectory = Path.Combine(Path.GetTempPath(), "DisplayNameGeneration"); string framework40Directory = Path.Combine(tempDirectory, "MyFramework\\v4.0\\"); string framework40redistDirectory = Path.Combine(framework40Directory, "RedistList"); string framework40RedistList = Path.Combine(framework40redistDirectory, "FrameworkList.xml"); string framework39Directory = Path.Combine(tempDirectory, "MyFramework\\v3.9\\Profile\\Client"); string framework39redistDirectory = Path.Combine(framework39Directory, "RedistList"); string framework39RedistList = Path.Combine(framework39redistDirectory, "FrameworkList.xml"); try { Directory.CreateDirectory(framework40redistDirectory); Directory.CreateDirectory(framework39redistDirectory); File.WriteAllText(framework39RedistList, redistString39); File.WriteAllText(framework40RedistList, redistString40); FrameworkNameVersioning frameworkName = new FrameworkNameVersioning("MyFramework", new Version("4.0")); string displayName40 = ToolLocationHelper.GetDisplayNameForTargetFrameworkDirectory(framework40Directory, frameworkName); frameworkName = new FrameworkNameVersioning("MyFramework", new Version("3.9"), "Client"); string displayName39 = ToolLocationHelper.GetDisplayNameForTargetFrameworkDirectory(framework39Directory, frameworkName); Assert.True(displayName40.Equals("MyFramework 4.0", StringComparison.OrdinalIgnoreCase)); Assert.True(displayName39.Equals("MyFramework v3.9 Client", StringComparison.OrdinalIgnoreCase)); } finally { if (Directory.Exists(framework40Directory)) { Directory.Delete(framework40Directory, true); } if (Directory.Exists(framework39Directory)) { Directory.Delete(framework39Directory, true); } } }
public void GenerateReferencAssemblyPathNoProfile() { string targetFrameworkRootPath = "c:\\Program Files\\Reference Assemblies\\Microsoft\\Framework"; string targetFrameworkIdentifier = "Compact Framework"; Version targetFrameworkVersion = new Version("1.0"); FrameworkNameVersioning frameworkName = new FrameworkNameVersioning(targetFrameworkIdentifier, targetFrameworkVersion, String.Empty); string expectedPath = Path.Combine(targetFrameworkRootPath, targetFrameworkIdentifier); expectedPath = Path.Combine(expectedPath, "v" + targetFrameworkVersion.ToString()); string path = FrameworkLocationHelper.GenerateReferenceAssemblyPath(targetFrameworkRootPath, frameworkName); Assert.True(String.Equals(expectedPath, path, StringComparison.InvariantCultureIgnoreCase)); }
public void LegacyFramework20Good() { FrameworkNameVersioning frameworkName = new FrameworkNameVersioning("Anything", new Version("2.0")); LegacyFrameworkTestHelper legacyHelper = new LegacyFrameworkTestHelper(); legacyHelper.DotNet20Installed = true; IList<string> list = ToolLocationHelper.HandleLegacyDotNetFrameworkReferenceAssemblyPaths(legacyHelper.GetDotNetVersionToPathDelegate, legacyHelper.GetDotNetReferenceAssemblyDelegate, frameworkName); Assert.IsTrue(list.Count == 1); Assert.AreEqual(LegacyFrameworkTestHelper.DotNet20FrameworkPath, list[0]); }
/// <summary> /// Finds out what the known framework names and also the latest one /// </summary> private static void InitializeKnownAndLatestFrameworkNames() { IList<string> names = ToolLocationHelper.GetSupportedTargetFrameworks(); Version latestVersion = null; s_knownFrameworkNames = new List<FrameworkName>(); foreach (string name in names) { FrameworkName frameworkName = new FrameworkName(name); s_knownFrameworkNames.Add(frameworkName); Version version = GetFrameworkNameVersion(frameworkName); if (s_latestFrameworkName == null || latestVersion < version) { s_latestFrameworkName = frameworkName; latestVersion = version; } } }
private static Version GetFrameworkNameVersion(FrameworkName name) { if (name == null) { return null; } return name.Version; }
/// <summary> /// Checks codedom settings to determine whether we are targeting 2.0 or 3.5. /// </summary> private static void InitializeTargetFrameworkNameFor20Or35() { string compilerVersion = GetCompilerVersionFor20Or35(); // Make sure the compiler version is either 2.0 or 3.5 if (CompilationUtil.IsCompilerVersion35(compilerVersion)) { s_targetFrameworkName = FrameworkNameV35; } else if (compilerVersion == "v2.0" || compilerVersion == null) { // If the compiler version is null, it means the user did not set it // in the codedom section. // We use 3.0 because it is not possible to distinguish between 2.0 and 3.0 // by just looking at web.config. s_targetFrameworkName = FrameworkNameV30; } else { throw new ConfigurationErrorsException(SR.GetString(SR.Compiler_version_20_35_required, s_configTargetFrameworkAttributeName)); } }
private static bool IsSupportedVersion(FrameworkName frameworkName) { // Look under the following registry to get the list of supported keys, and check for matching // identifier and version. // HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v4.0.30319\SKUs\[TFM] try { var name = new FrameworkName(frameworkName.Identifier, frameworkName.Version); var runtime = Environment.Version; var runtimeVersion = runtime.Major + "." + runtime.Minor + "." + runtime.Build; string path = @"SOFTWARE\Microsoft\.NETFramework\v" + runtimeVersion + @"\SKUs"; var baseKey = Registry.LocalMachine.OpenSubKey(path); foreach (string subKey in baseKey.GetSubKeyNames()) { try { var subKeyName = CreateFrameworkName(subKey); var supportedName = new FrameworkName(subKeyName.Identifier, subKeyName.Version); if (String.Equals(name.FullName, supportedName.FullName, StringComparison.OrdinalIgnoreCase)) { return true; } } catch { continue; } } } catch { } return false; }
/// <summary> /// Verifies that the moniker is valid, and that the version is 4.0 and above. /// </summary> private static void ValidateTargetFrameworkMoniker(string targetFrameworkMoniker) { CompilationSection compConfig = RuntimeConfig.GetAppConfig().Compilation; int lineNumber = compConfig.ElementInformation.LineNumber; string source = compConfig.ElementInformation.Source; try { string moniker = targetFrameworkMoniker; // Try treating it as a version, eg "4.0" first. Version v = GetVersion(targetFrameworkMoniker); if (v != null) { // If it is of the form "4.0", construct the full moniker string, // eg ".NETFramework,Version=v4.0" moniker = ".NETFramework,Version=v" + moniker; } s_targetFrameworkName = CreateFrameworkName(moniker); } catch (ArgumentException e) { throw new ConfigurationErrorsException(SR.GetString(SR.Invalid_target_framework_version, s_configTargetFrameworkAttributeName, targetFrameworkMoniker, e.Message), source, lineNumber); } Version ver = GetFrameworkNameVersion(s_targetFrameworkName); if (ver < Version40) { throw new ConfigurationErrorsException(SR.GetString(SR.Invalid_lower_target_version, s_configTargetFrameworkAttributeName), source, lineNumber); } // Check the specified version is no higher than the latest known framework for which we have // reference assemblies installed. Version latestVersion = GetFrameworkNameVersion(LatestFrameworkName); if (latestVersion != null && latestVersion >= ver) { // If the specified version is lower than the latest version installed, // we are fine. return; } // NOTE: This check is not entirely correct. See comments in GetInstalledTargetVersion(). // It might be possible that the actual installed (runtime) version is of a higher version, // but the reference assemblies are not installed, so latestFrameworkName might be lower. // In that case we also need to check the registry key. int majorVersion = ver.Major; Version installedTargetVersion = GetInstalledTargetVersion(majorVersion); if (installedTargetVersion != null && installedTargetVersion >= ver) { return; } if (IsSupportedVersion(s_targetFrameworkName)) { return; } // If the above checks failed, report that the version is invalid, higher than expected throw new ConfigurationErrorsException(SR.GetString(SR.Invalid_higher_target_version, s_configTargetFrameworkAttributeName), source, lineNumber); }
public bool IsInFramework(string frameworkIdentifier, string frameworkVersion) { Version version = null; if (!string.IsNullOrEmpty(frameworkVersion)) { // CA1307:Specify StringComparison. Suppressed since a valid string representation of a version would be parsed correctly even if the the first character is not "v". if (frameworkVersion.StartsWith("v")) { System.Version.TryParse(frameworkVersion.Substring(1), out version); } else { System.Version.TryParse(frameworkVersion, out version); } } if (string.IsNullOrEmpty(frameworkIdentifier) && version != null) { throw new ArgumentNullException("frameworkIdentifier"); } Dictionary<string, RedistList> redistDictionary = new Dictionary<string, RedistList>(); foreach (string moniker in ToolLocationHelper.GetSupportedTargetFrameworks()) { FrameworkNameVersioning frameworkName = new FrameworkNameVersioning(moniker); if ((string.IsNullOrEmpty(frameworkIdentifier) || frameworkName.Identifier.Equals(frameworkIdentifier, StringComparison.OrdinalIgnoreCase)) && (version == null || frameworkName.Version == version)) { IList<string> paths = ToolLocationHelper.GetPathToReferenceAssemblies(frameworkName); foreach (string path in paths) { if (!redistDictionary.ContainsKey(path)) { redistDictionary.Add(path, RedistList.GetRedistListFromPath(path)); } } } } string fullName = GetFullName(AssemblyIdentity.FullNameFlags.Default); foreach (RedistList list in redistDictionary.Values) { if (list != null && list.IsFrameworkAssembly(fullName)) return true; } return false; }
public void GenerateReferencAssemblyInvalidIdentifier() { string targetFrameworkRootPath = "c:\\Program Files\\Reference Assemblies\\Microsoft\\Framework"; string targetFrameworkIdentifier = "Compact Framework" + new String(Path.GetInvalidFileNameChars()); Version targetFrameworkVersion = new Version("1.0"); string targetFrameworkProfile = "PocketPC"; FrameworkNameVersioning frameworkName = new FrameworkNameVersioning(targetFrameworkIdentifier, targetFrameworkVersion, targetFrameworkProfile); string path = FrameworkLocationHelper.GenerateReferenceAssemblyPath(targetFrameworkRootPath, frameworkName); }
public void GetPathToReferenceAssembliesNullArgumentGoodFrameworkNameNullRoot() { FrameworkNameVersioning frameworkName = new FrameworkNameVersioning("Ident", new Version("2.0")); ToolLocationHelper.GetPathToReferenceAssemblies(null, frameworkName); }
private static XmlElement GetXmlElement(string targetZone, FrameworkNameVersioning fn) { IList<string> paths = ToolLocationHelper.GetPathToReferenceAssemblies(fn); // Is the targeted CLR even installed? if (paths.Count > 0) { // first one is always framework requested. string path = Path.Combine(paths[0], PermissionSetsFolder); // PermissionSets folder doesn't exit if (Directory.Exists(path)) { string[] files = Directory.GetFiles(path, "*.xml"); FileInfo[] filesInfo = new FileInfo[files.Length]; int indexFound = -1; // trim the extension. for (int i = 0; i < files.Length; i++) { filesInfo[i] = new FileInfo(files[i]); string fileInfoNoExt = Path.GetFileNameWithoutExtension(files[i]); if (string.Equals(fileInfoNoExt, targetZone, StringComparison.OrdinalIgnoreCase)) { indexFound = i; break; } } if (indexFound != -1) { string data = string.Empty; FileInfo resultFile = filesInfo[indexFound]; using (FileStream fs = resultFile.OpenRead()) { try { StreamReader sr = new StreamReader(fs); data = sr.ReadToEnd(); // fs.Position value will be the length of the stream. if (!string.IsNullOrEmpty(data)) { XmlDocument doc = new XmlDocument(); XmlReaderSettings xrSettings = new XmlReaderSettings(); xrSettings.DtdProcessing = DtdProcessing.Ignore; // http://msdn.microsoft.com/en-us/library/h2344bs2(v=vs.110).aspx // PermissionSets do not conform to document level, which is the default setting. xrSettings.ConformanceLevel = ConformanceLevel.Auto; try { fs.Position = 0; // Reset to 0 before using this stream in any other reader. using (XmlReader xr = XmlReader.Create(fs, xrSettings)) { doc.Load(xr); return (XmlElement)doc.DocumentElement; } } catch (Exception) { //continue. } } } catch (ArgumentException) { //continue. } } } } } return GetCurrentCLRPermissions(targetZone); }
public void LegacyFramework35ReferenceAssembliesNotInstalled() { FrameworkNameVersioning frameworkName = new FrameworkNameVersioning("Anything", new Version("3.5")); LegacyFrameworkTestHelper legacyHelper = new LegacyFrameworkTestHelper(); legacyHelper.DotNet35Installed = true; IList<string> list = ToolLocationHelper.HandleLegacyDotNetFrameworkReferenceAssemblyPaths(legacyHelper.GetDotNetVersionToPathDelegate, legacyHelper.GetDotNetReferenceAssemblyDelegate, frameworkName); Assert.IsTrue(list.Count == 0); }
/// <summary> /// Helper method to add a call to the AspNetCompiler task into the given target. /// </summary> private void AddTaskForAspNetCompiler ( ProjectTargetInstance target, ProjectInSolution project, string conditionDescribingValidConfigurations ) { // Add a call to the AspNetCompiler task, conditioned on having a valid Configuration. ProjectTaskInstance newTask = target.AddTask("AspNetCompiler", conditionDescribingValidConfigurations, null); newTask.SetParameter("VirtualPath", "$(" + GenerateSafePropertyName(project, "AspNetVirtualPath") + ")"); newTask.SetParameter("PhysicalPath", "$(" + GenerateSafePropertyName(project, "AspNetPhysicalPath") + ")"); newTask.SetParameter("TargetPath", "$(" + GenerateSafePropertyName(project, "AspNetTargetPath") + ")"); newTask.SetParameter("Force", "$(" + GenerateSafePropertyName(project, "AspNetForce") + ")"); newTask.SetParameter("Updateable", "$(" + GenerateSafePropertyName(project, "AspNetUpdateable") + ")"); newTask.SetParameter("Debug", "$(" + GenerateSafePropertyName(project, "AspNetDebug") + ")"); newTask.SetParameter("KeyFile", "$(" + GenerateSafePropertyName(project, "AspNetKeyFile") + ")"); newTask.SetParameter("KeyContainer", "$(" + GenerateSafePropertyName(project, "AspNetKeyContainer") + ")"); newTask.SetParameter("DelaySign", "$(" + GenerateSafePropertyName(project, "AspNetDelaySign") + ")"); newTask.SetParameter("AllowPartiallyTrustedCallers", "$(" + GenerateSafePropertyName(project, "AspNetAPTCA") + ")"); newTask.SetParameter("FixedNames", "$(" + GenerateSafePropertyName(project, "AspNetFixedNames") + ")"); bool isDotNetFramework = false; // generate the target .NET Framework version based on the passed in TargetFrameworkMoniker. try { FrameworkName targetFramework = new FrameworkName(project.TargetFrameworkMoniker); if (String.Equals(targetFramework.Identifier, ".NETFramework", StringComparison.OrdinalIgnoreCase)) { isDotNetFramework = true; // As of .NET Framework 4.0, there are only two versions of aspnet_compiler.exe: 2.0 and 4.0. If // the TargetFrameworkVersion is less than 4.0, use the 2.0 version. Otherwise, just use the 4.0 // version of the executable, so that if say FV 4.1 is passed in, we don't throw an error. if (targetFramework.Version.Major >= 4) { newTask.SetParameter ( "ToolPath", FrameworkLocationHelper.GetPathToDotNetFramework(_version40) ); if (targetFramework.Version > _version40) { _loggingService.LogComment(_projectBuildEventContext, MessageImportance.Low, "AspNetCompiler.TargetingHigherFrameworksDefaultsTo40", project.ProjectName, targetFramework.Version.ToString()); } } else { string pathTo20 = FrameworkLocationHelper.GetPathToDotNetFramework(_version20); ProjectFileErrorUtilities.VerifyThrowInvalidProjectFile(pathTo20 != null, "SubCategoryForSolutionParsingErrors", new BuildEventFileInfo(_solutionFile.FullPath), "AspNetCompiler.20NotInstalled"); newTask.SetParameter ( "ToolPath", pathTo20 ); } } } catch (Exception e) { if (ExceptionHandling.NotExpectedException(e)) { throw; } else { ProjectFileErrorUtilities.ThrowInvalidProjectFile ( new BuildEventFileInfo(_solutionFile.FullPath), e, "AspNetCompiler.InvalidTargetFrameworkMonikerFromException", project.ProjectName, project.TargetFrameworkMoniker, e.Message ); } } if (!isDotNetFramework) { ProjectFileErrorUtilities.VerifyThrowInvalidProjectFile ( false, "SubCategoryForSolutionParsingErrors", new BuildEventFileInfo(_solutionFile.FullPath), "AspNetCompiler.InvalidTargetFrameworkMonikerNotDotNET", project.ProjectName, project.TargetFrameworkMoniker ); } }
public void GenerateReferencAssemblyPathTooLong() { Assert.Throws<InvalidOperationException>(() => { string pathTooLong = new String('a', 500); string targetFrameworkRootPath = "c:\\Program Files\\Reference Assemblies\\Microsoft\\Framework"; string targetFrameworkIdentifier = "Compact Framework" + pathTooLong; Version targetFrameworkVersion = new Version("1.0"); string targetFrameworkProfile = "PocketPC"; FrameworkNameVersioning frameworkName = new FrameworkNameVersioning(targetFrameworkIdentifier, targetFrameworkVersion, targetFrameworkProfile); string path = FrameworkLocationHelper.GenerateReferenceAssemblyPath(targetFrameworkRootPath, frameworkName); } ); }
private static PermissionSet GetNamedPermissionSet(string targetZone, ITaskItem[] dependencies, string targetFrameworkMoniker) { FrameworkNameVersioning fn = null; if (!string.IsNullOrEmpty(targetFrameworkMoniker)) { fn = new FrameworkNameVersioning(targetFrameworkMoniker); } else { fn = new FrameworkNameVersioning(".NETFramework", s_dotNet40Version); } int majorVersion = fn.Version.Major; if (majorVersion == Fx2MajorVersion) { return SecurityUtilities.XmlToPermissionSet((GetXmlElement(targetZone, majorVersion))); } else if (majorVersion == Fx3MajorVersion) { return SecurityUtilities.XmlToPermissionSet((GetXmlElement(targetZone, majorVersion))); } else { return SecurityUtilities.XmlToPermissionSet((GetXmlElement(targetZone, fn))); } }
public void GetPathToReferenceAssembliesWithRootCircularReference() { string redistString41 = "<FileList Redist='Random' IncludeFramework='v4.0'>" + "<File AssemblyName='System' Version='4.0.0.0' PublicKeyToken='b77a5c561934e089' Culture='neutral' ProcessorArchitecture='MSIL' FileVersion='4.0.0.0' InGAC='false' />" + "</FileList >"; string redistString40 = "<FileList Redist='Random' IncludeFramework='v4.1'>" + "<File AssemblyName='System' Version='4.0.0.0' PublicKeyToken='b77a5c561934e089' Culture='neutral' ProcessorArchitecture='MSIL' FileVersion='4.0.0.0' InGAC='false' />" + "</FileList >"; string tempDirectory = Path.Combine(Path.GetTempPath(), "GetPathToReferenceAssembliesWithRootGoodWithChain"); string framework41Directory = Path.Combine(tempDirectory, "MyFramework\\v4.1\\"); string framework41redistDirectory = Path.Combine(framework41Directory, "RedistList"); string framework41RedistList = Path.Combine(framework41redistDirectory, "FrameworkList.xml"); string framework40Directory = Path.Combine(tempDirectory, "MyFramework\\v4.0\\"); string framework40redistDirectory = Path.Combine(framework40Directory, "RedistList"); string framework40RedistList = Path.Combine(framework40redistDirectory, "FrameworkList.xml"); try { Directory.CreateDirectory(framework41redistDirectory); Directory.CreateDirectory(framework40redistDirectory); File.WriteAllText(framework40RedistList, redistString40); File.WriteAllText(framework41RedistList, redistString41); FrameworkNameVersioning frameworkName = new FrameworkNameVersioning("MyFramework", new Version("4.1")); IList<string> directories = ToolLocationHelper.GetPathToReferenceAssemblies(tempDirectory, frameworkName); Assert.Equal(2, directories.Count); // "Expected the method to return two paths." Assert.True(String.Equals(directories[0], framework41Directory, StringComparison.OrdinalIgnoreCase), "Expected first entry to be first in chain but it was" + directories[0]); Assert.True(String.Equals(directories[1], framework40Directory, StringComparison.OrdinalIgnoreCase), "Expected first entry to be second in chain but it was" + directories[1]); } finally { if (Directory.Exists(framework41Directory)) { Directory.Delete(framework41Directory, true); } if (Directory.Exists(framework40Directory)) { Directory.Delete(framework40Directory, true); } } }
public void GetPathToReferenceAssembliesDefaultLocation45() { FrameworkNameVersioning frameworkName = null; IList<string> directories = null; if (ToolLocationHelper.GetPathToDotNetFrameworkReferenceAssemblies(TargetDotNetFrameworkVersion.Version45) != null) { frameworkName = new FrameworkNameVersioning(".NETFramework", new Version("4.5")); directories = ToolLocationHelper.GetPathToReferenceAssemblies(frameworkName); Assert.Equal(1, directories.Count); // "Expected the method to return one path." string referenceAssemblyPath = ToolLocationHelper.GetPathToDotNetFrameworkReferenceAssemblies(TargetDotNetFrameworkVersion.Version45); Assert.True(String.Equals(directories[0], referenceAssemblyPath, StringComparison.OrdinalIgnoreCase), "Expected referenceassembly directory to be " + referenceAssemblyPath + " but it was " + directories[0]); } // else // "Ignored because v4.5 did not seem to be installed" }
public void TestGeneralFrameworkMonikerGoodWithInvalidCharInIncludePath() { string tempDirectory = Path.Combine(Path.GetTempPath(), "TestGeneralFrameworkMonikerGoodWithInvalidCharInIncludePath"); string framework41Directory = Path.Combine(tempDirectory, "MyFramework\\v4.1\\"); string redistListDirectory = Path.Combine(framework41Directory, "RedistList"); string redistListFile = Path.Combine(redistListDirectory, "FrameworkList.xml"); try { Directory.CreateDirectory(framework41Directory); Directory.CreateDirectory(redistListDirectory); string redistListContents = "<FileList Redist='Microsoft-Windows-CLRCoreComp' IncludeFramework='v4.*' Name='Chained oh noes'>" + "<File AssemblyName='System.Xml' Version='2.0.0.0' PublicKeyToken='b03f5f7f11d50a3a' Culture='Neutral' FileVersion='2.0.50727.208' InGAC='true' />" + "<File AssemblyName='Microsoft.Build.Engine' Version='2.0.0.0' PublicKeyToken='b03f5f7f11d50a3a' Culture='Neutral' FileVersion='2.0.50727.208' InGAC='true' />" + "</FileList >"; File.WriteAllText(redistListFile, redistListContents); string targetFrameworkMoniker = "MyFramework, Version=v4.1"; MockEngine engine = new MockEngine(); GetReferenceAssemblyPaths getReferencePaths = new GetReferenceAssemblyPaths(); getReferencePaths.BuildEngine = engine; getReferencePaths.TargetFrameworkMoniker = targetFrameworkMoniker; getReferencePaths.RootPath = tempDirectory; getReferencePaths.Execute(); string[] returnedPaths = getReferencePaths.ReferenceAssemblyPaths; Assert.Equal(0, returnedPaths.Length); string displayName = getReferencePaths.TargetFrameworkMonikerDisplayName; Assert.Null(displayName); FrameworkNameVersioning frameworkMoniker = new FrameworkNameVersioning(getReferencePaths.TargetFrameworkMoniker); engine.AssertLogContains("MSB3643"); } finally { if (Directory.Exists(framework41Directory)) { Directory.Delete(framework41Directory, true); } } }
public void LegacyFramework35Good() { FrameworkNameVersioning frameworkName = new FrameworkNameVersioning("Anything", new Version("3.5")); LegacyFrameworkTestHelper legacyHelper = new LegacyFrameworkTestHelper(); legacyHelper.DotNetReferenceAssemblies35Installed = true; legacyHelper.DotNetReferenceAssemblies30Installed = true; legacyHelper.DotNet30Installed = true; legacyHelper.DotNet35Installed = true; legacyHelper.DotNet20Installed = true; IList<string> list = ToolLocationHelper.HandleLegacyDotNetFrameworkReferenceAssemblyPaths(legacyHelper.GetDotNetVersionToPathDelegate, legacyHelper.GetDotNetReferenceAssemblyDelegate, frameworkName); Assert.Equal(5, list.Count); Assert.Equal(LegacyFrameworkTestHelper.DotNet35ReferenceAssemblyPath, list[0]); Assert.Equal(LegacyFrameworkTestHelper.DotNet35FrameworkPath, list[1]); Assert.Equal(LegacyFrameworkTestHelper.DotNet30ReferenceAssemblyPath, list[2]); Assert.Equal(LegacyFrameworkTestHelper.DotNet30FrameworkPath, list[3]); Assert.Equal(LegacyFrameworkTestHelper.DotNet20FrameworkPath, list[4]); }
public void TestGeneralFrameworkMonikerGoodWithRootWithProfile() { string tempDirectory = Path.Combine(Path.GetTempPath(), "TestGeneralFrameworkMonikerGoodWithRootWithProfile"); string framework41Directory = Path.Combine(tempDirectory, "MyFramework\\v4.1\\Profile\\Client"); string redistListDirectory = Path.Combine(framework41Directory, "RedistList"); string redistListFile = Path.Combine(redistListDirectory, "FrameworkList.xml"); try { Directory.CreateDirectory(framework41Directory); Directory.CreateDirectory(redistListDirectory); string redistListContents = "<FileList Redist='Microsoft-Windows-CLRCoreComp' Name='.NET Framework 4.1 Client'>" + "<File AssemblyName='System.Xml' Version='2.0.0.0' PublicKeyToken='b03f5f7f11d50a3a' Culture='Neutral' FileVersion='2.0.50727.208' InGAC='true' />" + "<File AssemblyName='Microsoft.Build.Engine' Version='2.0.0.0' PublicKeyToken='b03f5f7f11d50a3a' Culture='Neutral' FileVersion='2.0.50727.208' InGAC='true' />" + "</FileList >"; File.WriteAllText(redistListFile, redistListContents); FrameworkNameVersioning name = new FrameworkNameVersioning("MyFramework", new Version("4.1"), "Client"); string targetFrameworkMoniker = name.FullName; MockEngine engine = new MockEngine(); GetReferenceAssemblyPaths getReferencePaths = new GetReferenceAssemblyPaths(); getReferencePaths.BuildEngine = engine; getReferencePaths.TargetFrameworkMoniker = targetFrameworkMoniker; getReferencePaths.RootPath = tempDirectory; getReferencePaths.Execute(); string[] returnedPaths = getReferencePaths.ReferenceAssemblyPaths; string displayName = getReferencePaths.TargetFrameworkMonikerDisplayName; Assert.Equal(1, returnedPaths.Length); Assert.True(returnedPaths[0].Equals(framework41Directory + "\\", StringComparison.OrdinalIgnoreCase)); Assert.True(displayName.Equals(".NET Framework 4.1 Client", StringComparison.OrdinalIgnoreCase)); } finally { if (Directory.Exists(framework41Directory)) { Directory.Delete(framework41Directory, true); } } }
public void LegacyFramework40DotNetReferenceAssemblyDirectoryNotInstalled() { FrameworkNameVersioning frameworkName = new FrameworkNameVersioning("Anything", new Version("4.0")); LegacyFrameworkTestHelper legacyHelper = new LegacyFrameworkTestHelper(); legacyHelper.DotNet40Installed = true; IList<string> list = ToolLocationHelper.HandleLegacyDotNetFrameworkReferenceAssemblyPaths(legacyHelper.GetDotNetVersionToPathDelegate, legacyHelper.GetDotNetReferenceAssemblyDelegate, frameworkName); Assert.Equal(0, list.Count); }
/// <summary> /// Generate the set of chained reference assembly paths /// </summary> private IList<String> GetPaths(string rootPath, FrameworkNameVersioning frameworkmoniker) { IList<String> pathsToReturn = null; if (String.IsNullOrEmpty(rootPath)) { pathsToReturn = ToolLocationHelper.GetPathToReferenceAssemblies(frameworkmoniker); } else { pathsToReturn = ToolLocationHelper.GetPathToReferenceAssemblies(rootPath, frameworkmoniker); } // No reference assembly paths could be found, log a warning as there could be future errors which may be confusing because of this. if (pathsToReturn.Count == 0) { Log.LogWarningWithCodeFromResources("GetReferenceAssemblyPaths.NoReferenceAssemblyDirectoryFound", frameworkmoniker.ToString()); } return pathsToReturn; }
/// <summary> /// Execute the task. /// </summary> /// <param name="fileExists">Delegate used for checking for the existence of a file.</param> /// <param name="directoryExists">Delegate used for checking for the existence of a directory.</param> /// <param name="getDirectories">Delegate used for finding directories.</param> /// <param name="getAssemblyName">Delegate used for finding fusion names of assemblyFiles.</param> /// <param name="getAssemblyMetadata">Delegate used for finding dependencies of a file.</param> /// <param name="getRegistrySubKeyNames">Used to get registry subkey names.</param> /// <param name="getRegistrySubKeyDefaultValue">Used to get registry default values.</param> /// <param name="getLastWriteTime">Delegate used to get the last write time.</param> /// <returns>True if there was success.</returns> internal bool Execute ( FileExists fileExists, DirectoryExists directoryExists, GetDirectories getDirectories, GetAssemblyName getAssemblyName, GetAssemblyMetadata getAssemblyMetadata, GetRegistrySubKeyNames getRegistrySubKeyNames, GetRegistrySubKeyDefaultValue getRegistrySubKeyDefaultValue, GetLastWriteTime getLastWriteTime, GetAssemblyRuntimeVersion getRuntimeVersion, OpenBaseKey openBaseKey, GetAssemblyPathInGac getAssemblyPathInGac, IsWinMDFile isWinMDFile, ReadMachineTypeFromPEHeader readMachineTypeFromPEHeader ) { bool success = true; #if (!STANDALONEBUILD) using (new CodeMarkerStartEnd(CodeMarkerEvent.perfMSBuildResolveAssemblyReferenceBegin, CodeMarkerEvent.perfMSBuildResolveAssemblyReferenceEnd)) #endif { try { FrameworkNameVersioning frameworkMoniker = null; if (!String.IsNullOrEmpty(_targetedFrameworkMoniker)) { try { frameworkMoniker = new FrameworkNameVersioning(_targetedFrameworkMoniker); } catch (ArgumentException) { // The exception doesn't contain the bad value, so log it ourselves Log.LogErrorWithCodeFromResources("ResolveAssemblyReference.InvalidParameter", "TargetFrameworkMoniker", _targetedFrameworkMoniker, String.Empty); return false; } } Version targetedRuntimeVersion = SetTargetedRuntimeVersion(_targetedRuntimeVersionRawValue); // Log task inputs. LogInputs(); if (!VerifyInputConditions()) { return false; } _logVerboseSearchResults = Environment.GetEnvironmentVariable("MSBUILDLOGVERBOSERARSEARCHRESULTS") != null; // Loop through all the target framework directories that were passed in, // and ensure that they all have a trailing slash. This is necessary // for the string comparisons we will do later on. if (_targetFrameworkDirectories != null) { for (int i = 0; i < _targetFrameworkDirectories.Length; i++) { _targetFrameworkDirectories[i] = FileUtilities.EnsureTrailingSlash(_targetFrameworkDirectories[i]); } } // Validate the contents of the InstalledAssemblyTables parameter. AssemblyTableInfo[] installedAssemblyTableInfo = GetInstalledAssemblyTableInfo(_ignoreDefaultInstalledAssemblyTables, _installedAssemblyTables, new GetListPath(RedistList.GetRedistListPathsFromDisk), TargetFrameworkDirectories); AssemblyTableInfo[] whiteListSubsetTableInfo = null; InstalledAssemblies installedAssemblies = null; RedistList redistList = null; if (installedAssemblyTableInfo != null && installedAssemblyTableInfo.Length > 0) { redistList = RedistList.GetRedistList(installedAssemblyTableInfo); } Hashtable blackList = null; // The name of the subset if it is generated or the name of the profile. This will be used for error messages and logging. string subsetOrProfileName = null; // Are we targeting a profile bool targetingProfile = !String.IsNullOrEmpty(ProfileName) && ((FullFrameworkFolders.Length > 0) || (FullFrameworkAssemblyTables.Length > 0)); bool targetingSubset = false; List<Exception> whiteListErrors = new List<Exception>(); List<string> whiteListErrorFilesNames = new List<string>(); // Check for partial success in GetRedistList and log any tolerated exceptions. if (redistList != null && redistList.Count > 0 || targetingProfile || ShouldUseSubsetBlackList()) { // If we are not targeting a dev 10 profile and we have the required components to generate a orcas style subset, do so if (!targetingProfile && ShouldUseSubsetBlackList()) { // Based in the target framework subset names find the paths to the files SubsetListFinder whiteList = new SubsetListFinder(_targetFrameworkSubsets); whiteListSubsetTableInfo = GetInstalledAssemblyTableInfo(IgnoreDefaultInstalledAssemblySubsetTables, InstalledAssemblySubsetTables, new GetListPath(whiteList.GetSubsetListPathsFromDisk), TargetFrameworkDirectories); if (whiteListSubsetTableInfo.Length > 0 && (redistList != null && redistList.Count > 0)) { blackList = redistList.GenerateBlackList(whiteListSubsetTableInfo, whiteListErrors, whiteListErrorFilesNames); } else { Log.LogWarningWithCodeFromResources("ResolveAssemblyReference.NoSubsetsFound"); } // Could get into this situation if the redist list files were full of junk and no assemblies were read in. if (blackList == null) { Log.LogWarningWithCodeFromResources("ResolveAssemblyReference.NoRedistAssembliesToGenerateExclusionList"); } subsetOrProfileName = GenerateSubSetName(_targetFrameworkSubsets, _installedAssemblySubsetTables); targetingSubset = true; } else { // We are targeting a profile if (targetingProfile) { // When targeting a profile we want the redist list to be the full framework redist list, since this is what should be used // when unifying assemblies ect. AssemblyTableInfo[] fullRedistAssemblyTableInfo = null; RedistList fullFrameworkRedistList = null; HandleProfile(installedAssemblyTableInfo /*This is the table info related to the profile*/, out fullRedistAssemblyTableInfo, out blackList, out fullFrameworkRedistList); // Make sure the redist list and the installedAsemblyTableInfo structures point to the full framework, we replace the installedAssemblyTableInfo // which contained the information about the profile redist files with the one from the full framework because when doing anything with the RAR cache // we want to use the full frameworks redist list. Essentailly after generating the exclusion list the job of the profile redist list is done. redistList = fullFrameworkRedistList; // Save the profile redist list file locations as the whiteList whiteListSubsetTableInfo = installedAssemblyTableInfo; // Set the installed assembly table to the full redist list values installedAssemblyTableInfo = fullRedistAssemblyTableInfo; subsetOrProfileName = _profileName; } } if (redistList != null && redistList.Count > 0) { installedAssemblies = new InstalledAssemblies(redistList); } } // Print out any errors reading the redist list. if (redistList != null) { // Some files may have been skipped. Log warnings for these. for (int i = 0; i < redistList.Errors.Length; ++i) { Exception e = redistList.Errors[i]; string filename = redistList.ErrorFileNames[i]; // Give the user a warning about the bad file (or files). Log.LogWarningWithCodeFromResources("ResolveAssemblyReference.InvalidInstalledAssemblyTablesFile", filename, RedistList.RedistListFolder, e.Message); } // Some files may have been skipped. Log warnings for these. for (int i = 0; i < whiteListErrors.Count; ++i) { Exception e = whiteListErrors[i]; string filename = whiteListErrorFilesNames[i]; // Give the user a warning about the bad file (or files). Log.LogWarningWithCodeFromResources("ResolveAssemblyReference.InvalidInstalledAssemblySubsetTablesFile", filename, SubsetListFinder.SubsetListFolder, e.Message); } } // Load any prior saved state. ReadStateFile(); _cache.SetGetLastWriteTime(getLastWriteTime); _cache.SetInstalledAssemblyInformation(installedAssemblyTableInfo); // Cache delegates. getAssemblyName = _cache.CacheDelegate(getAssemblyName); getAssemblyMetadata = _cache.CacheDelegate(getAssemblyMetadata); fileExists = _cache.CacheDelegate(fileExists); getDirectories = _cache.CacheDelegate(getDirectories); getRuntimeVersion = _cache.CacheDelegate(getRuntimeVersion); _projectTargetFramework = FrameworkVersionFromString(_projectTargetFrameworkAsString); // Filter out all Assemblies that have SubType!='', or higher framework FilterBySubtypeAndTargetFramework(); // Compute the set of bindingRedirect remappings. DependentAssembly[] appConfigRemappedAssemblies = null; if (FindDependencies) { try { appConfigRemappedAssemblies = GetAssemblyRemappingsFromAppConfig(); } catch (AppConfigException e) { Log.LogErrorWithCodeFromResources(null, e.FileName, e.Line, e.Column, 0, 0, "ResolveAssemblyReference.InvalidAppConfig", AppConfigFile, e.Message); return false; } } SystemProcessorArchitecture processorArchitecture = TargetProcessorArchitectureToEnumeration(_targetProcessorArchitecture); // Start the table of dependencies with all of the primary references. ReferenceTable dependencyTable = new ReferenceTable ( BuildEngine, _findDependencies, _findSatellites, _findSerializationAssemblies, _findRelatedFiles, _searchPaths, _allowedAssemblyExtensions, _relatedFileExtensions, _candidateAssemblyFiles, _resolvedSDKReferences, _targetFrameworkDirectories, installedAssemblies, processorArchitecture, fileExists, directoryExists, getDirectories, getAssemblyName, getAssemblyMetadata, getRegistrySubKeyNames, getRegistrySubKeyDefaultValue, openBaseKey, getRuntimeVersion, targetedRuntimeVersion, _projectTargetFramework, frameworkMoniker, Log, _latestTargetFrameworkDirectories, _copyLocalDependenciesWhenParentReferenceInGac, DoNotCopyLocalIfInGac, getAssemblyPathInGac, isWinMDFile, _ignoreVersionForFrameworkReferences, readMachineTypeFromPEHeader, _warnOrErrorOnTargetArchitectureMismatch, _ignoreTargetFrameworkAttributeVersionMismatch, _unresolveFrameworkAssembliesFromHigherFrameworks ); // If AutoUnify, then compute the set of assembly remappings. ArrayList generalResolutionExceptions = new ArrayList(); subsetOrProfileName = targetingSubset && String.IsNullOrEmpty(_targetedFrameworkMoniker) ? subsetOrProfileName : _targetedFrameworkMoniker; bool excludedReferencesExist = false; DependentAssembly[] autoUnifiedRemappedAssemblies = null; AssemblyNameReference[] autoUnifiedRemappedAssemblyReferences = null; if (AutoUnify && FindDependencies) { // Compute all dependencies. dependencyTable.ComputeClosure ( // Use any app.config specified binding redirects so that later when we output suggested redirects // for the GenerateBindingRedirects target, we don't suggest ones that the user already wrote appConfigRemappedAssemblies, _assemblyFiles, _assemblyNames, generalResolutionExceptions ); try { excludedReferencesExist = false; if (redistList != null && redistList.Count > 0) { excludedReferencesExist = dependencyTable.MarkReferencesForExclusion(blackList); } } catch (InvalidOperationException e) { Log.LogErrorWithCodeFromResources("ResolveAssemblyReference.ProblemDeterminingFrameworkMembership", e.Message); return false; } if (excludedReferencesExist) { dependencyTable.RemoveReferencesMarkedForExclusion(true /* Remove the reference and do not warn*/, subsetOrProfileName); } // Based on the closure, get a table of ideal remappings needed to // produce zero conflicts. dependencyTable.ResolveConflicts ( out autoUnifiedRemappedAssemblies, out autoUnifiedRemappedAssemblyReferences ); } DependentAssembly[] allRemappedAssemblies = CombineRemappedAssemblies(appConfigRemappedAssemblies, autoUnifiedRemappedAssemblies); // Compute all dependencies. dependencyTable.ComputeClosure(allRemappedAssemblies, _assemblyFiles, _assemblyNames, generalResolutionExceptions); try { excludedReferencesExist = false; if (redistList != null && redistList.Count > 0) { excludedReferencesExist = dependencyTable.MarkReferencesForExclusion(blackList); } } catch (InvalidOperationException e) { Log.LogErrorWithCodeFromResources("ResolveAssemblyReference.ProblemDeterminingFrameworkMembership", e.Message); return false; } if (excludedReferencesExist) { dependencyTable.RemoveReferencesMarkedForExclusion(false /* Remove the reference and warn*/, subsetOrProfileName); } // Resolve any conflicts. DependentAssembly[] idealAssemblyRemappings = null; AssemblyNameReference[] idealAssemblyRemappingsIdentities = null; dependencyTable.ResolveConflicts ( out idealAssemblyRemappings, out idealAssemblyRemappingsIdentities ); // Build the output tables. dependencyTable.GetReferenceItems ( out _resolvedFiles, out _resolvedDependencyFiles, out _relatedFiles, out _satelliteFiles, out _serializationAssemblyFiles, out _scatterFiles, out _copyLocalFiles ); // If we're not finding dependencies, then don't suggest redirects (they're only about dependencies). if (FindDependencies) { // Build the table of suggested redirects. If we're auto-unifying, we want to output all the // assemblies that we auto-unified so that GenerateBindingRedirects can consume them, // not just the required ones for build to succeed DependentAssembly[] remappings = AutoUnify ? autoUnifiedRemappedAssemblies : idealAssemblyRemappings; AssemblyNameReference[] remappedReferences = AutoUnify ? autoUnifiedRemappedAssemblyReferences : idealAssemblyRemappingsIdentities; PopulateSuggestedRedirects(remappings, remappedReferences); } bool useSystemRuntime = false; foreach (var reference in dependencyTable.References.Keys) { if (string.Equals(SystemRuntimeAssemblyName, reference.Name, StringComparison.OrdinalIgnoreCase)) { useSystemRuntime = true; break; } } if (!useSystemRuntime && !FindDependencies) { // when we are not producing the dependency graph look for direct dependencies of primary references. foreach (var resolvedReference in dependencyTable.References.Values) { var rawDependencies = GetDependencies(resolvedReference, fileExists, getAssemblyMetadata); if (rawDependencies != null) { foreach (var dependentReference in rawDependencies) { if (string.Equals(SystemRuntimeAssemblyName, dependentReference.Name, StringComparison.OrdinalIgnoreCase)) { useSystemRuntime = true; break; } } } if (useSystemRuntime) { break; } } } this.DependsOnSystemRuntime = useSystemRuntime.ToString(); WriteStateFile(); // Save the new state out and put into the file exists if it is actually on disk. if (_stateFile != null && fileExists(_stateFile)) { _filesWritten.Add(new TaskItem(_stateFile)); } // Log the results. success = LogResults(dependencyTable, idealAssemblyRemappings, idealAssemblyRemappingsIdentities, generalResolutionExceptions); DumpTargetProfileLists(installedAssemblyTableInfo, whiteListSubsetTableInfo, dependencyTable); if (processorArchitecture != SystemProcessorArchitecture.None && _warnOrErrorOnTargetArchitectureMismatch != WarnOrErrorOnTargetArchitectureMismatchBehavior.None) { foreach (ITaskItem item in _resolvedFiles) { AssemblyNameExtension assemblyName = null; if (fileExists(item.ItemSpec) && !Reference.IsFrameworkFile(item.ItemSpec, _targetFrameworkDirectories)) { try { assemblyName = getAssemblyName(item.ItemSpec); } catch (System.IO.FileLoadException) { // Its pretty hard to get here, you need an assembly that contains a valid reference // to a dependent assembly that, in turn, throws a FileLoadException during GetAssemblyName. // Still it happened once, with an older version of the CLR. // ...falling through and relying on the targetAssemblyName==null behavior below... } catch (System.IO.FileNotFoundException) { // Its pretty hard to get here, also since we do a file existence check right before calling this method so it can only happen if the file got deleted between that check and this call. } catch (UnauthorizedAccessException) { } catch (BadImageFormatException) { } } if (assemblyName != null) { SystemProcessorArchitecture assemblyArch = assemblyName.ProcessorArchitecture; // If the assembly is MSIL or none it can work anywhere so there does not need to be any warning ect. if (assemblyArch == SystemProcessorArchitecture.MSIL || assemblyArch == SystemProcessorArchitecture.None) { continue; } if (processorArchitecture != assemblyArch) { if (_warnOrErrorOnTargetArchitectureMismatch == WarnOrErrorOnTargetArchitectureMismatchBehavior.Error) { Log.LogErrorWithCodeFromResources("ResolveAssemblyReference.MismatchBetweenTargetedAndReferencedArch", ProcessorArchitectureToString(processorArchitecture), item.GetMetadata("OriginalItemSpec"), ProcessorArchitectureToString(assemblyArch)); } else { Log.LogWarningWithCodeFromResources("ResolveAssemblyReference.MismatchBetweenTargetedAndReferencedArch", ProcessorArchitectureToString(processorArchitecture), item.GetMetadata("OriginalItemSpec"), ProcessorArchitectureToString(assemblyArch)); } } } } } return success && !Log.HasLoggedErrors; } catch (ArgumentException e) { Log.LogErrorWithCodeFromResources("General.InvalidArgument", e.Message); } // InvalidParameterValueException is thrown inside RAR when we find a specific parameter // has an invalid value. It's then caught up here so that we can abort the task. catch (InvalidParameterValueException e) { Log.LogErrorWithCodeFromResources(null, "", 0, 0, 0, 0, "ResolveAssemblyReference.InvalidParameter", e.ParamName, e.ActualValue, e.Message); } } return success && !Log.HasLoggedErrors; }