src/Microsoft.PackageManagement.MetaProvider.PowerShell/PowerShellMetaProvider.cs
/// <summary>
/// If we cannot use psget to get swidtag information, we will try to fill in some of the information
/// </summary>
/// <param name="packageProvider"></param>
/// <param name="psModuleInfo"></param>
If we cannot use psget to get swidtag information, we will try to fill in some of the information
If we cannot use psget to get swidtag information we will try to fill in some of the information
private void ProvideSwidTagInformation(PackageProvider packageProvider, PSModuleInfo psModuleInfo)
        {
            if (packageProvider == null || psModuleInfo == null)
            {
                return;
            }
            packageProvider.VersionScheme = "MultiPartNumeric";
            Microsoft.PackageManagement.Internal.Packaging.SoftwareMetadata softwareMetadata = new Microsoft.PackageManagement.Internal.Packaging.SoftwareMetadata();
            bool changed = false;
            var type = psModuleInfo.GetType();
            if (!string.IsNullOrWhiteSpace(psModuleInfo.Description))
            {
                softwareMetadata.Description = psModuleInfo.Description;
                changed = true;
            }
            if (!string.IsNullOrWhiteSpace(psModuleInfo.Copyright))
            {
                softwareMetadata.AddAttribute("copyright", psModuleInfo.Copyright);
                changed = true;
            }
            var tagsProperty = type.GetProperty("Tags");
            bool isV5 = tagsProperty != null;
            if (isV5)
            {
                var tags = tagsProperty.GetValue(psModuleInfo);
                if (tags is IEnumerable<string> && (tags as IEnumerable<string>).Any())
                {
                    softwareMetadata.AddAttribute("tags", string.Join(" ", (tags as IEnumerable<string>).Distinct()));
                    changed = true;
                }
                var releaseNotes = type.GetProperty("ReleaseNotes").GetValue(psModuleInfo);
                if (releaseNotes is string && !string.IsNullOrWhiteSpace(type.GetProperty("ReleaseNotes").GetValue(psModuleInfo) as string))
                {
                    softwareMetadata.AddAttribute("tags", string.Join(" ", (tags as IEnumerable<string>).Distinct()));
                    changed = true;
                }
            }
            if (changed)
            {
                packageProvider.AddElement(softwareMetadata);
            }
            if (isV5)
            {
                var iconUri = type.GetProperty("IconUri").GetValue(psModuleInfo);
                if (iconUri is Uri)
                {
                    packageProvider.AddLink(iconUri as Uri, "icon");
                }
                var licenseUri = type.GetProperty("LicenseUri").GetValue(psModuleInfo);
                if (licenseUri is Uri)
                {
                    packageProvider.AddLink(licenseUri as Uri, "license");
                }
                var projectUri = type.GetProperty("ProjectUri").GetValue(psModuleInfo);
                if (projectUri is Uri)
                {
                    packageProvider.AddLink(projectUri as Uri, "project");
                }
            }
            if (!string.IsNullOrWhiteSpace(psModuleInfo.Author))
            {
                packageProvider.AddEntity(psModuleInfo.Author, null, "author");
            }
            if (!string.IsNullOrWhiteSpace(psModuleInfo.CompanyName))
            {
                packageProvider.AddEntity(psModuleInfo.CompanyName, null, "owner");
            }        
        }
private void ProvideSwidTagInformation ( PackageProvider packageProvider , PSModuleInfo psModuleInfo ) { if ( packageProvider == null || psModuleInfo == null ) { return ; } packageProvider . VersionScheme = " " ; Microsoft . PackageManagement . Internal . Packaging . SoftwareMetadata softwareMetadata = new Microsoft . PackageManagement . Internal . Packaging . SoftwareMetadata ( ) ; bool changed = false ; var type = psModuleInfo . GetType ( ) ; if ( ! string . IsNullOrWhiteSpace ( psModuleInfo . Description ) ) { softwareMetadata . Description = psModuleInfo . Description ; changed = true ; } if ( ! string . IsNullOrWhiteSpace ( psModuleInfo . Copyright ) ) { softwareMetadata . AddAttribute ( " " , psModuleInfo . Copyright ) ; changed = true ; } var tagsProperty = type . GetProperty ( " " ) ; bool isV5 = tagsProperty != null ; if ( isV5 ) { var tags = tagsProperty . GetValue ( psModuleInfo ) ; if ( tags is IEnumerable < string > && ( tags as IEnumerable < string > ) . Any ( ) ) { softwareMetadata . AddAttribute ( " " , string . Join ( " " , ( tags as IEnumerable < string > ) . Distinct ( ) ) ) ; changed = true ; } var releaseNotes = type . GetProperty ( " " ) . GetValue ( psModuleInfo ) ; if ( releaseNotes is string && ! string . IsNullOrWhiteSpace ( type . GetProperty ( " " ) . GetValue ( psModuleInfo ) as string ) ) { softwareMetadata . AddAttribute ( " " , string . Join ( " " , ( tags as IEnumerable < string > ) . Distinct ( ) ) ) ; changed = true ; } } if ( changed ) { packageProvider . AddElement ( softwareMetadata ) ; } if ( isV5 ) { var iconUri = type . GetProperty ( " " ) . GetValue ( psModuleInfo ) ; if ( iconUri is Uri ) { packageProvider . AddLink ( iconUri as Uri , " " ) ; } var licenseUri = type . GetProperty ( " " ) . GetValue ( psModuleInfo ) ; if ( licenseUri is Uri ) { packageProvider . AddLink ( licenseUri as Uri , " " ) ; } var projectUri = type . GetProperty ( " " ) . GetValue ( psModuleInfo ) ; if ( projectUri is Uri ) { packageProvider . AddLink ( projectUri as Uri , " " ) ; } } if ( ! string . IsNullOrWhiteSpace ( psModuleInfo . Author ) ) { packageProvider . AddEntity ( psModuleInfo . Author , null , " " ) ; } if ( ! string . IsNullOrWhiteSpace ( psModuleInfo . CompanyName ) ) { packageProvider . AddEntity ( psModuleInfo . CompanyName , null , " " ) ; } }
If we cannot use psget to get swidtag information, we will try to fill in some of the information
If we cannot use psget to get swidtag information we will try to fill in some of the information
// introduced in ps 2.0 // introduced in ps 3.0 // tags is introduced in ps 5.0 // introduced in ps 5.0 // check that we have something in tags // check that we have something in releasenotes // introduced in ps 5.0 // introduced in ps 5.0 // introduced in ps 5.0 // introduced in ps 3.0 // introduced in ps 3.0
packageProvider
PackageProvider
None
psModuleInfo
PSModuleInfo
None