Skip to content
This repository was archived by the owner on Jun 13, 2024. It is now read-only.

Refactor Nuget operations out of Publish-PSArtifactUtility function #444

Merged
merged 8 commits into from
Mar 22, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
return file paths from nuspec and nupkg functions.
  • Loading branch information
Benny1007 committed Mar 15, 2019
commit 6801a239fd2d68f7703749ab7174fb73e7216332
13 changes: 10 additions & 3 deletions src/PowerShellGet/private/functions/New-NugetPackage.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function New-NugetPackage {
[Parameter()]
[string]$OutputPath = $NugetPackageRoot,

[Parameter(ParameterSetName = "UseNuget")]
[Parameter(Mandatory = $true, ParameterSetName = "UseNuget")]
[string]$NugetExePath,

[Parameter(ParameterSetName = "UseDotnetCli")]
Expand All @@ -26,6 +26,7 @@ function New-NugetPackage {
throw "NugetPackageRoot $NugetPackageRoot does not exist"
}


if ($PSCmdlet.ParameterSetName -eq "UseNuget") {
if (-Not(Test-Path -Path $NuGetExePath)) {
throw "Nuget.exe does not exist at $NugetExePath, provide a valid path to nuget.exe"
Expand Down Expand Up @@ -96,13 +97,19 @@ function New-NugetPackage {
}

if (-Not ($process.ExitCode -eq 0 )) {
$stdOut = $process.StandardOut.ReadToEnd()
$stdOut = $process.StandardOutput.ReadToEnd()
throw "dotnet cli failed to pack $stdOut"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still does not allow inspecting the temporary created project file. This makes it a bit magical when trying to understand what got uploaded to a repository as part of the publish process.

@Benny1007 @edyoung

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overwrite the outputpath variable and then you would know where the artifact resides.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, was missing a question mark off the last comment! would need to pass this through from the public function.

}

}

$stdOut = $process.StandardOutput.ReadLine()
[xml]$nuspecXml = Get-Content -Path $NuspecPath
$version = $nuspecXml.package.metadata.version
$id = $nuspecXml.package.metadata.id
$nupkgFullFile = Join-Path $OutputPath -ChildPath "$id.$version.nupkg"

$stdOut = $process.StandardOutput.ReadToEnd()

Write-Verbose -Message $stdOut
Write-Output $nupkgFullFile
}
7 changes: 4 additions & 3 deletions src/PowerShellGet/private/functions/New-NuspecFile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ function New-NuspecFile {
tags = $Tags
}

if ($LicenseUrl) { $metaDataElement.Add("licenseUrl", $LicenseUrl) }
if ($ProjectUrl) { $metaDataElement.Add("projectUrl", $ProjectUrl) }
if ($IconUrl) { $metaDataElement.Add("iconUrl", $IconUrl) }
if ($LicenseUrl) { $metaDataElementsHash.Add("licenseUrl", $LicenseUrl) }
if ($ProjectUrl) { $metaDataElementsHash.Add("projectUrl", $ProjectUrl) }
if ($IconUrl) { $metaDataElementsHash.Add("iconUrl", $IconUrl) }

foreach ($key in $metaDataElementsHash.Keys) {
$element = $xml.CreateElement($key, $nameSpaceUri)
Expand All @@ -89,6 +89,7 @@ function New-NuspecFile {
$metaDataElement.AppendChild($element) | Out-Null
}


if ($Dependencies) {
$dependenciesElement = $xml.CreateElement("dependencies", $nameSpaceUri)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,13 +377,12 @@ function Publish-PSArtifactUtility {

try {
if ($DotnetCommandPath) {
New-NugetPackage -NuspecPath $NuspecFullName -NugetPackageRoot $NugetPackageRoot -UseDotnetCli -Verbose:$VerbosePreference
$NupkgFullName = New-NugetPackage -NuspecPath $NuspecFullName -NugetPackageRoot $NugetPackageRoot -UseDotnetCli -Verbose:$VerbosePreference
}
elseif ($NuGetExePath) {
New-NugetPackage -NuspecPath $NuspecFullName -NugetPackageRoot $NugetPackageRoot -NugetExePath $NuGetExePath -Verbose:$VerbosePreference
$NupkgFullName = New-NugetPackage -NuspecPath $NuspecFullName -NugetPackageRoot $NugetPackageRoot -NugetExePath $NuGetExePath -Verbose:$VerbosePreference
}

$NupkgFullName = Join-Path -Path $NugetPackageRoot -ChildPath "$Name.$Version.nupkg"
Write-Verbose -Message "Successfully created nuget package at $NupkgFullName"
}
catch {
Expand Down