diff --git a/src/code/InstallHelper.cs b/src/code/InstallHelper.cs index 35fea684c..1df6b3192 100644 --- a/src/code/InstallHelper.cs +++ b/src/code/InstallHelper.cs @@ -540,6 +540,10 @@ private List InstallPackage( } moduleManifestVersion = parsedMetadataHashtable["ModuleVersion"] as string; + pkg.CompanyName = parsedMetadataHashtable["CompanyName"] as string; + pkg.Copyright = parsedMetadataHashtable["Copyright"] as string; + pkg.ReleaseNotes = parsedMetadataHashtable["ReleaseNotes"] as string; + pkg.RepositorySourceLocation = repoUri; // Accept License verification if (!_savePkg && !CallAcceptLicense(pkg, moduleManifest, tempInstallPath, newVersion)) @@ -553,6 +557,28 @@ private List InstallPackage( continue; } } + else + { + // is script + if (!PSScriptFileInfo.TryTestPSScriptFile( + scriptFileInfoPath: scriptPath, + out PSScriptFileInfo parsedScript, + out ErrorRecord[] errors, + out string[] _)) + { + foreach (ErrorRecord parseError in errors) + { + WriteError(parseError); + } + + continue; + } + + pkg.CompanyName = parsedScript.ScriptMetadataComment.CompanyName; + pkg.Copyright = parsedScript.ScriptMetadataComment.Copyright; + pkg.ReleaseNotes = parsedScript.ScriptMetadataComment.ReleaseNotes; + pkg.RepositorySourceLocation = repoUri; + } // Delete the extra nupkg related files that are not needed and not part of the module/script DeleteExtraneousFiles(pkgIdentity, tempDirNameVersion); diff --git a/src/code/PSResourceInfo.cs b/src/code/PSResourceInfo.cs index 6d1523cc4..ca6057002 100644 --- a/src/code/PSResourceInfo.cs +++ b/src/code/PSResourceInfo.cs @@ -234,8 +234,8 @@ public sealed class PSResourceInfo public Dictionary AdditionalMetadata { get; } public string Author { get; } - public string CompanyName { get; } - public string Copyright { get; } + public string CompanyName { get; internal set; } + public string Copyright { get; internal set; } public Dependency[] Dependencies { get; } public string Description { get; } public Uri IconUri { get; } @@ -250,9 +250,9 @@ public sealed class PSResourceInfo public string Prerelease { get; } public Uri ProjectUri { get; } public DateTime? PublishedDate { get; } - public string ReleaseNotes { get; } + public string ReleaseNotes { get; internal set; } public string Repository { get; } - public string RepositorySourceLocation { get; } + public string RepositorySourceLocation { get; internal set; } public string[] Tags { get; } public ResourceType Type { get; } public DateTime? UpdatedDate { get; } diff --git a/test/InstallPSResource.Tests.ps1 b/test/InstallPSResource.Tests.ps1 index e2666efb0..50cc1ee8c 100644 --- a/test/InstallPSResource.Tests.ps1 +++ b/test/InstallPSResource.Tests.ps1 @@ -9,6 +9,7 @@ Describe 'Test Install-PSResource for Module' { BeforeAll { $PSGalleryName = Get-PSGalleryName $NuGetGalleryName = Get-NuGetGalleryName + $PSGalleryUri = Get-PSGalleryLocation $testModuleName = "test_module" $testModuleName2 = "TestModule99" $testScriptName = "test_script" @@ -173,6 +174,17 @@ Describe 'Test Install-PSResource for Module' { $pkg.Version | Should -Be "5.0.0.0" } + It "Install resource with companyname, copyright and repository source location and validate" { + Install-PSResource -Name $testModuleName -Version "5.2.5-alpha001" -Repository PSGallery -TrustRepository + $pkg = Get-PSResource $testModuleName + $pkg.Version | Should -Be "5.2.5" + $pkg.Prerelease | Should -Be "alpha001" + + $pkg.CompanyName | Should -Be "Anam" + $pkg.Copyright | Should -Be "(c) Anam Navied. All rights reserved." + $pkg.RepositorySourceLocation | Should -Be $PSGalleryUri + } + # Windows only It "Install resource under CurrentUser scope - Windows only" -Skip:(!(Get-IsWindows)) { Install-PSResource -Name $testModuleName -Repository $PSGalleryName -TrustRepository -Scope CurrentUser