Beispiel #1
0
        internal IEnumerable <Assembly> LoadAssembliesAndBindLoader()
        {
            var list = new List <Assembly>();

            list.AddRange(_loader.LoadAssemblies(LoaderPaths));

            _loader.RegisterAssemblyResolve(
                list.Select(t => Path.GetDirectoryName(new Uri(t.CodeBase).LocalPath)).Distinct()
                );

            list.AddRange(
                _loader.LoadAssemblies(PackageReferences.Select(pkg => pkg.ResolveAssembly()))
                );
            return(list);
        }
Beispiel #2
0
        public override bool Execute()
        {
            var log = new MSBuildLogger(Log);

            log.LogDebug($"(in) ProjectUniqueName '{ProjectUniqueName}'");
            log.LogDebug($"(in) TargetFrameworks '{TargetFrameworks}'");
            log.LogDebug($"(in) PackageReferences '{string.Join(";", PackageReferences.Select(p => p.ItemSpec))}'");

            var entries = new List <ITaskItem>();
            var seenIds = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

            foreach (var msbuildItem in PackageReferences)
            {
                var packageId = msbuildItem.ItemSpec;

                if (string.IsNullOrEmpty(packageId) || !seenIds.Add(packageId))
                {
                    // Skip empty or already processed ids
                    continue;
                }

                var properties = new Dictionary <string, string>();
                properties.Add("ProjectUniqueName", ProjectUniqueName);
                properties.Add("Type", "Dependency");
                properties.Add("Id", packageId);
                BuildTasksUtility.CopyPropertyIfExists(msbuildItem, properties, "Version", "VersionRange");
                BuildTasksUtility.CopyPropertyIfExists(msbuildItem, properties, "VersionOverride");

                if (!string.IsNullOrEmpty(TargetFrameworks))
                {
                    properties.Add("TargetFrameworks", TargetFrameworks);
                }

                BuildTasksUtility.CopyPropertyIfExists(msbuildItem, properties, "IncludeAssets");
                BuildTasksUtility.CopyPropertyIfExists(msbuildItem, properties, "ExcludeAssets");
                BuildTasksUtility.CopyPropertyIfExists(msbuildItem, properties, "PrivateAssets");
                BuildTasksUtility.CopyPropertyIfExists(msbuildItem, properties, "NoWarn");
                BuildTasksUtility.CopyPropertyIfExists(msbuildItem, properties, "IsImplicitlyDefined");
                BuildTasksUtility.CopyPropertyIfExists(msbuildItem, properties, "GeneratePathProperty");
                BuildTasksUtility.CopyPropertyIfExists(msbuildItem, properties, "Aliases");

                entries.Add(new TaskItem(Guid.NewGuid().ToString(), properties));
            }

            RestoreGraphItems = entries.ToArray();

            return(true);
        }
        public override bool Execute()
        {
            string[] packageFolders = PackageFolders.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Select(i => i.Trim()).Where(i => !String.IsNullOrWhiteSpace(i)).ToArray();

            foreach (PackageReferenceTaskItem packageReference in PackageReferences.Select(i => new PackageReferenceTaskItem(i)))
            {
                if (String.IsNullOrWhiteSpace(packageReference.Sha512))
                {
                    Log.LogMessageFromText($"Cannot validate package reference '{packageReference.Name}' because it does not have a SHA512 associated with it.", MessageImportance.Low);
                    continue;
                }

                string packageDirectory = packageFolders.Select(i => Path.Combine(i, packageReference.PackagePath)).FirstOrDefault(Directory.Exists);

                if (packageDirectory == null)
                {
                    Log.LogErrorFromText("ND1001", $"The package '{packageReference.Name}' does not exist in any of the specified package folders '{PackageFolders}'.  Ensure that the packages for this project have been restored and were not deleted.");
                    continue;
                }

                string hashFilePath = Path.Combine(packageDirectory, packageReference.Hashfile);

                if (!File.Exists(hashFilePath))
                {
                    Log.LogErrorFromText("ND1002", $"The package '{packageReference.Name}' does not have a hash file at '{hashFilePath}'.  Ensure that the package was properly restored and that it has not been deleted.");
                    continue;
                }

                string actualHash = File.ReadAllText(hashFilePath).Trim();

                if (!String.Equals(packageReference.Sha512, actualHash))
                {
                    Log.LogErrorFromText("ND1003", $"The package reference '{packageReference.Name}' has an expected hash of '{packageReference.Sha512}' which does not match the hash of the package '{actualHash}' according to NuGet's hash file '{hashFilePath}'.  This can occur if you are downloading a different package then expected.  Verify that the feeds you are using contain the correct package.  In some cases, users modify packages and upload them with the same ID and version of an existing package.");
                }
            }

            return(!Log.HasLoggedErrors);
        }
 public IEnumerable <IPackage> GetPackages(Func <PackageReferenceContext, IPackage> projectFactoryFunc) => PackageReferences.Select(projectFactoryFunc);