Execute() public method

public Execute ( ) : bool
return bool
        public void HigherVersionDirectDependenciesFalse()
        {
            MockEngine e = new MockEngine();

            TaskItem item = new TaskItem("DependsOnFoo45Framework");

            ITaskItem[] items = new ITaskItem[]
            {
                item
            };

            ResolveAssemblyReference t = new ResolveAssemblyReference();
            t.BuildEngine = e;
            t.Assemblies = items;
            t.FindDependencies = false;
            t.TargetFrameworkMoniker = "Foo, Version=4.0";
            t.TargetFrameworkMonikerDisplayName = "Foo";
            t.SearchPaths = new string[] { @"c:\Frameworks\" };
            Assert.True(t.Execute(fileExists, directoryExists, getDirectories, getAssemblyName, getAssemblyMetadata, getRegistrySubKeyNames, getRegistrySubKeyDefaultValue, getLastWriteTime, getRuntimeVersion, openBaseKey, checkIfAssemblyIsInGac, isWinMDFile, readMachineTypeFromPEHeader));


            Assert.Equal(0, e.Warnings); // "No warning expected in this scenario."
            Assert.Equal(0, e.Errors); // "No errors expected in this scenario."
            Assert.Equal(1, t.ResolvedFiles.Length);
            Assert.Equal(0, t.ResolvedDependencyFiles.Length);
            Assert.True(ContainsItem(t.ResolvedFiles, @"c:\Frameworks\DependsOnFoo45Framework.dll")); // "Expected to find assembly, but didn't."
        }
Example #2
0
        public void Regress313086_Part1_MscorlibAsRawFilename()
        {
            ResolveAssemblyReference t = new ResolveAssemblyReference();

            t.BuildEngine = new MockEngine();

            t.Assemblies = new ITaskItem[]
            {
                new TaskItem(typeof(object).Module.FullyQualifiedName.ToLower())
            };

            t.SearchPaths = new string[]
            {
                @"{RawFileName}"
            };

            t.TargetFrameworkDirectories = new string[] { Path.GetDirectoryName(typeof(object).Module.FullyQualifiedName) };

            t.Execute();

            Assert.Equal(1, t.ResolvedFiles.Length);
        }
        /// <summary>
        /// Resolve a single assembly using the provided search paths and setting the targetframework directories.
        /// </summary>
        private static AssemblyResolutionResult ResolveAssembly(string assemblyName, IList<string> searchPaths, IList<string> targetFrameworkDirectories, bool checkDependencies) {
            ResolveAssemblyReference rar = new ResolveAssemblyReference();
            MockEngine engine = new MockEngine();
            rar.BuildEngine = engine;
            if (searchPaths != null) {
                rar.SearchPaths = searchPaths.ToArray();
            }
            if (targetFrameworkDirectories != null) {
                rar.TargetFrameworkDirectories = targetFrameworkDirectories.ToArray();
            }
            rar.Assemblies = new ITaskItem[] {
                new TaskItem(assemblyName),
            };
            rar.Silent = true;
            rar.Execute();

            AssemblyResolutionResult result = new AssemblyResolutionResult();

            List<string> resolvedFiles = new List<string>();
            foreach (ITaskItem item in rar.ResolvedFiles) {
                resolvedFiles.Add(item.ItemSpec);
            }
            if (checkDependencies) {
                CheckOutOfRangeDependencies(assemblyName);
            }
            result.ResolvedFiles = resolvedFiles.ToArray();
            result.Warnings = engine.Warnings;
            result.Errors = engine.Errors;
            return result;
        }
Example #4
0
        public void ResolveToGACSpecificVersion()
        {
            ResolveAssemblyReference t = new ResolveAssemblyReference();
            MockEngine engine = new MockEngine();
            t.BuildEngine = engine;

            TaskItem item = new TaskItem("System");
            item.SetMetadata("SpecificVersion", "true");
            t.Assemblies = new ITaskItem[] { item };
            t.SearchPaths = new string[] { "{GAC}" };
            t.TargetedRuntimeVersion = new Version("0.5.0.0").ToString();
            bool succeeded = t.Execute();
            Assert.True(succeeded);
            Assert.Equal(1, t.ResolvedFiles.Length);
        }
Example #5
0
        public void ResolveToGAC()
        {
            ResolveAssemblyReference t = new ResolveAssemblyReference();
            MockEngine engine = new MockEngine();
            t.BuildEngine = engine;

            t.Assemblies = new ITaskItem[] { new TaskItem("System") };
            t.TargetedRuntimeVersion = typeof(Object).Assembly.ImageRuntimeVersion;
            t.SearchPaths = new string[] { "{GAC}" };
            bool succeeded = t.Execute();
            Assert.True(succeeded);
            Assert.Equal(1, t.ResolvedFiles.Length);
        }
Example #6
0
        public void NonExistentReference()
        {
            ResolveAssemblyReference t = new ResolveAssemblyReference();

            t.BuildEngine = new MockEngine();
            t.Assemblies = new ITaskItem[] {
                new TaskItem("System.Xml"), new TaskItem("System.Nonexistent")
            };
            t.SearchPaths = new string[] { Path.GetDirectoryName(typeof(object).Module.FullyQualifiedName), "{AssemblyFolders}", "{HintPathFromItem}", "{RawFileName}" };
            t.Execute();
            Assert.Equal(1, t.ResolvedFiles.Length);
            Assert.Equal(0, String.Compare(ToolLocationHelper.GetPathToDotNetFrameworkFile("System.Xml.dll", TargetDotNetFrameworkVersion.Version45), t.ResolvedFiles[0].ItemSpec, StringComparison.OrdinalIgnoreCase));
        }
        /// <summary>
        /// Execute the task. Without confirming that the number of files resolved with and without find dependencies is identical. 
        /// This is because profiles could cause the number of primary references to be different.
        /// </summary>
        protected static bool Execute(ResolveAssemblyReference t, bool buildConsistencyCheck)
        {
            string tempPath = Path.GetTempPath();
            string redistListPath = Path.Combine(tempPath, Guid.NewGuid() + ".xml");
            string rarCacheFile = Path.Combine(tempPath, Guid.NewGuid() + ".RarCache");
            s_existentFiles.Add(rarCacheFile);

            bool succeeded = false;

            try
            {
                // Set the InstalledAssemblyTables parameter.
                if (t.InstalledAssemblyTables.Length == 0)
                {
                    File.WriteAllText(redistListPath, REDISTLIST);
                    t.InstalledAssemblyTables = new ITaskItem[] { new TaskItem(redistListPath) };
                }

                // First, run it in loading-a-project mode.
                t.Silent = true;
                t.FindDependencies = false;
                t.FindSatellites = false;
                t.FindSerializationAssemblies = false;
                t.FindRelatedFiles = false;
                t.StateFile = null;
                t.Execute(fileExists, directoryExists, getDirectories, getAssemblyName, getAssemblyMetadata, getRegistrySubKeyNames, getRegistrySubKeyDefaultValue, getLastWriteTime, getRuntimeVersion, openBaseKey, checkIfAssemblyIsInGac, isWinMDFile, readMachineTypeFromPEHeader);

                // A few checks. These should always be true or it may be a perf issue for project load.
                ITaskItem[] loadModeResolvedFiles = new TaskItem[0];
                if (t.ResolvedFiles != null)
                {
                    loadModeResolvedFiles = (ITaskItem[])t.ResolvedFiles.Clone();
                }
                Assert.Equal(0, t.ResolvedDependencyFiles.Length);
                Assert.Equal(0, t.SatelliteFiles.Length);
                Assert.Equal(0, t.RelatedFiles.Length);
                Assert.Equal(0, t.SuggestedRedirects.Length);
                Assert.Equal(0, t.FilesWritten.Length);

                // Now, run it in building-a-project mode.
                MockEngine e = (MockEngine)t.BuildEngine;
                e.Warnings = 0;
                e.Errors = 0;
                e.Log = "";
                t.Silent = false;
                t.FindDependencies = true;
                t.FindSatellites = true;
                t.FindSerializationAssemblies = true;
                t.FindRelatedFiles = true;
                string cache = rarCacheFile;
                t.StateFile = cache;
                File.Delete(t.StateFile);
                succeeded = t.Execute(fileExists, directoryExists, getDirectories, getAssemblyName, getAssemblyMetadata, getRegistrySubKeyNames, getRegistrySubKeyDefaultValue, getLastWriteTime, getRuntimeVersion, openBaseKey, checkIfAssemblyIsInGac, isWinMDFile, readMachineTypeFromPEHeader);
                if (FileUtilities.FileExistsNoThrow(t.StateFile))
                {
                    Assert.Equal(1, t.FilesWritten.Length);
                    Assert.True(t.FilesWritten[0].ItemSpec.Equals(cache, StringComparison.OrdinalIgnoreCase));
                }

                File.Delete(t.StateFile);

                if (buildConsistencyCheck)
                {
                    // Some consistency checks between load mode and build mode.
                    Assert.Equal(loadModeResolvedFiles.Length, t.ResolvedFiles.Length);
                    for (int i = 0; i < loadModeResolvedFiles.Length; i++)
                    {
                        Assert.Equal(loadModeResolvedFiles[i].ItemSpec, t.ResolvedFiles[i].ItemSpec);
                        Assert.Equal(loadModeResolvedFiles[i].GetMetadata("CopyLocal"), t.ResolvedFiles[i].GetMetadata("CopyLocal"));
                        Assert.Equal(loadModeResolvedFiles[i].GetMetadata("ResolvedFrom"), t.ResolvedFiles[i].GetMetadata("ResolvedFrom"));
                    }
                }

                // Check attributes on resolve files.
                for (int i = 0; i < t.ResolvedFiles.Length; i++)
                {
                    // OriginalItemSpec attribute on resolved items is to support VS in figuring out which
                    // project file reference caused a particular resolved file.
                    string originalItemSpec = t.ResolvedFiles[i].GetMetadata("OriginalItemSpec");
                    Assert.True(ContainsItem(t.Assemblies, originalItemSpec) || ContainsItem(t.AssemblyFiles, originalItemSpec)); //                         "Expected to find OriginalItemSpec in Assemblies or AssemblyFiles task parameters"
                }
            }
            finally
            {
                s_existentFiles.Remove(rarCacheFile);
                if (File.Exists(redistListPath))
                {
                    FileUtilities.DeleteNoThrow(redistListPath);
                }

                if (File.Exists(rarCacheFile))
                {
                    FileUtilities.DeleteNoThrow(rarCacheFile);
                }
            }
            return succeeded;
        }
        public virtual VsResolvedAssemblyPath[] Resolve(IEnumerable<string> assemblies)
        {
            if (assemblies == null)
            {
                throw new ArgumentNullException("assemblies");
            }

            // Resolve references WITHOUT invoking MSBuild to avoid re-entrancy problems.
            const bool projectDtar = true;
            var rar = new ResolveAssemblyReference();
            var engine = new MockEngine(EnableLogging);
            rar.BuildEngine = engine;

            // first set common properties/items then if projectDtar then set additional projectDtar properties
            ITaskItem[] assemblyItems = assemblies.Select(assembly => new TaskItem(assembly)).ToArray();
            rar.Assemblies = assemblyItems;
            rar.SearchPaths = rarInputs.PdtarSearchPaths;

            rar.TargetFrameworkDirectories = rarInputs.TargetFrameworkDirectories;
            rar.AllowedAssemblyExtensions = rarInputs.AllowedAssemblyExtensions;
            rar.TargetProcessorArchitecture = rarInputs.TargetProcessorArchitecture;
            rar.TargetFrameworkVersion = rarInputs.TargetFrameworkVersion;
            rar.TargetFrameworkMoniker = rarInputs.TargetFrameworkMoniker;
            rar.TargetFrameworkMonikerDisplayName = rarInputs.TargetFrameworkMonikerDisplayName;
            rar.TargetedRuntimeVersion = rarInputs.TargetedRuntimeVersion;
            rar.FullFrameworkFolders = rarInputs.FullFrameworkFolders;
            rar.LatestTargetFrameworkDirectories = rarInputs.LatestTargetFrameworkDirectories;
            rar.FullTargetFrameworkSubsetNames = rarInputs.FullTargetFrameworkSubsetNames;
            rar.FullFrameworkAssemblyTables = rarInputs.FullFrameworkAssemblyTables;
            rar.IgnoreDefaultInstalledAssemblySubsetTables = rarInputs.IgnoreDefaultInstalledAssemblySubsetTables;
            rar.ProfileName = rarInputs.ProfileName;

            rar.Silent = !EnableLogging;
            rar.FindDependencies = true;
            rar.AutoUnify = false;
            rar.FindSatellites = false;
            rar.FindSerializationAssemblies = false;
            rar.FindRelatedFiles = false;

            // This set needs to be kept in sync with the set of project instance data that
            // is populated into RarInputs
            if (projectDtar)
            {
                // set project dtar specific properties 
                rar.CandidateAssemblyFiles = rarInputs.CandidateAssemblyFiles;
                rar.StateFile = rarInputs.StateFile;
                rar.InstalledAssemblySubsetTables = rarInputs.InstalledAssemblySubsetTables;
                rar.TargetFrameworkSubsets = rarInputs.TargetFrameworkSubsets;
            }

            IEnumerable<VsResolvedAssemblyPath> results;

            try
            {
                rar.Execute();
                results = FilterResults(rar.ResolvedFiles).Select(pair => new VsResolvedAssemblyPath
                {
                    bstrOrigAssemblySpec = pair.Key,
                    bstrResolvedAssemblyPath = pair.Value
                });
            }
            catch (Exception ex)
            {
                if (ErrorHandler.IsCriticalException(ex))
                {
                    throw;
                }

                engine.RecordRARExecutionException(ex);
                results = Enumerable.Empty<VsResolvedAssemblyPath>();
            }
            finally
            {
                if (EnableLogging)
                {
                    WriteLogFile(engine, projectDtar, assemblies);
                }
            }

            return results.ToArray();
        }