Beispiel #1
0
 public IEnumerable <PackageVerifierIssue> Validate(PackageAnalysisContext context)
 {
     AssemblyAttributesDataHelper.SetAssemblyAttributesData(context);
     foreach (var assemblyData in context.AssemblyData)
     {
         if (!HasDescriptionAttribute(assemblyData.Value.AssemblyAttributes))
         {
             yield return(PackageIssueFactory.AssemblyMissingDescriptionAttribute(assemblyData.Key));
         }
     }
 }
Beispiel #2
0
        public IEnumerable <PackageVerifierIssue> Validate(PackageAnalysisContext context)
        {
            if (context.Metadata.PackageTypes.Any(p => p == Constants.DotNetTool))
            {
                // Skip for dotnet global tool packages which contain assemblies from other teams and projects
                yield break;
            }

            AssemblyAttributesDataHelper.SetAssemblyAttributesData(context);
            foreach (var assemblyData in context.AssemblyData)
            {
                var assemblyInformationalVersionAttribute = assemblyData.Value.AssemblyAttributes.SingleOrDefault(a =>
                                                                                                                  a.AttributeType.FullName.Equals(
                                                                                                                      typeof(AssemblyInformationalVersionAttribute).FullName,
                                                                                                                      StringComparison.Ordinal));

                var infoVersion = assemblyInformationalVersionAttribute?.ConstructorArguments[0].Value?.ToString();

                if (!NuGetVersion.TryParse(infoVersion, out var assemblyInformationalNuGetVersion) ||
                    !VersionEquals(context.Metadata.Version, assemblyInformationalNuGetVersion))
                {
                    yield return(PackageIssueFactory.AssemblyInformationalVersionDoesNotMatchPackageVersion(
                                     assemblyData.Key,
                                     infoVersion,
                                     context.Metadata.Version,
                                     context.Metadata.Id));
                }

                var assemblyFileVersionAttribute = assemblyData.Value.AssemblyAttributes.SingleOrDefault(a =>
                                                                                                         a.AttributeType.FullName.Equals(
                                                                                                             typeof(AssemblyFileVersionAttribute).FullName,
                                                                                                             StringComparison.Ordinal));

                var assemblyFileNuGetVersion = new NuGetVersion(assemblyFileVersionAttribute.ConstructorArguments[0].Value.ToString());
                if (!VersionEquals(context.Metadata.Version, assemblyFileNuGetVersion))
                {
                    yield return(PackageIssueFactory.AssemblyFileVersionDoesNotMatchPackageVersion(
                                     assemblyData.Key,
                                     assemblyFileNuGetVersion,
                                     context.Metadata.Version,
                                     context.Metadata.Id));
                }

                var assemblyVersion = assemblyData.Value.AssemblyName.Version;
                if (!context.Metadata.Version.Version.Equals(assemblyVersion))
                {
                    yield return(PackageIssueFactory.AssemblyVersionDoesNotMatchPackageVersion(
                                     assemblyData.Key,
                                     assemblyVersion,
                                     context.Metadata.Version.Version,
                                     context.Metadata.Id));
                }
            }
        }
Beispiel #3
0
        public IEnumerable <PackageVerifierIssue> Validate(PackageAnalysisContext context)
        {
            if (!context.Metadata.PackageTypes.Any(p => p == Constants.DotNetTool))
            {
                yield break;
            }

            var packageFiles = context.PackageReader.GetFiles();
            var manifests    = packageFiles?.Where(f => Path.GetFileName(f).Equals(ToolManifestFileName, StringComparison.Ordinal)) ?? Enumerable.Empty <string>();

            if (packageFiles == null || manifests.Count() == 0)
            {
                yield return(PackageIssueFactory.DotNetToolMustHaveManifest(Constants.DotNetTool.Name, ToolManifestFileName));

                yield break;
            }

            foreach (var manifestPath in manifests)
            {
                var manifestDir = Path.GetDirectoryName(manifestPath).Replace('\\', '/');

                var manifestStream = context.PackageReader.GetStream(manifestPath);
                var manifest       = XDocument.Load(manifestStream);

                AssemblyAttributesDataHelper.SetAssemblyAttributesData(context);

                var commands = manifest.Descendants("Command");
                foreach (var command in commands)
                {
                    var name = command.Attribute("Name");
                    if (string.IsNullOrEmpty(name?.Value))
                    {
                        yield return(PackageIssueFactory.DotNetToolMalformedManifest(manifestPath, "Missing Name"));

                        continue;
                    }

                    var entryPoint = command.Attribute("EntryPoint");
                    if (entryPoint?.Value == null)
                    {
                        yield return(PackageIssueFactory.DotNetToolMalformedManifest(manifestPath, "Missing EntryPoint"));

                        continue;
                    }

                    var entryPointPath = manifestDir + '/' + entryPoint.Value;
                    if (!packageFiles.Any(a => a.Equals(entryPointPath, StringComparison.Ordinal)))
                    {
                        yield return(PackageIssueFactory.DotNetToolMissingEntryPoint(manifestPath, entryPoint.Value));
                    }
                }
            }
        }
 public IEnumerable <PackageVerifierIssue> Validate(PackageAnalysisContext context)
 {
     AssemblyAttributesDataHelper.SetAssemblyAttributesData(context);
     foreach (var assemblyData in context.AssemblyData)
     {
         var fileName         = Path.GetFileNameWithoutExtension(assemblyData.Key);
         var isSourcesPackage = fileName.EndsWith(".Sources", StringComparison.OrdinalIgnoreCase);
         if (!isSourcesPackage && !HasCommitHashInMetadataAttribute(assemblyData.Value.AssemblyAttributes))
         {
             yield return(PackageIssueFactory.AssemblyMissingHashAttribute(assemblyData.Key));
         }
     }
 }
        public IEnumerable <PackageVerifierIssue> Validate(PackageAnalysisContext context)
        {
            AssemblyAttributesDataHelper.SetAssemblyAttributesData(context);
            foreach (var assemblyData in context.AssemblyData)
            {
                if (!HasAttrWithArg(assemblyData.Value.AssemblyAttributes, typeof(AssemblyFileVersionAttribute).FullName))
                {
                    yield return(PackageIssueFactory.AssemblyMissingFileVersionAttribute(assemblyData.Key));
                }

                if (!HasAttrWithArg(assemblyData.Value.AssemblyAttributes, typeof(AssemblyInformationalVersionAttribute).FullName))
                {
                    yield return(PackageIssueFactory.AssemblyMissingInformationalVersionAttribute(assemblyData.Key));
                }
            }
        }
Beispiel #6
0
        public IEnumerable <PackageVerifierIssue> Validate(PackageAnalysisContext context)
        {
            if (context.Metadata.IsDotNetToolPackage())
            {
                yield break;
            }

            AssemblyAttributesDataHelper.SetAssemblyAttributesData(context);
            foreach (var assemblyData in context.AssemblyData)
            {
                if (!HasNeutralResourcesLanguageAttribute(assemblyData.Value.AssemblyAttributes))
                {
                    yield return(PackageIssueFactory.AssemblyMissingNeutralResourcesLanguageAttribute(assemblyData.Key));
                }
            }
        }