Skip to content

Commit cd9649b

Browse files
committed
fix denpendencies for powershell core
1 parent 727e46c commit cd9649b

File tree

8 files changed

+105
-58
lines changed

8 files changed

+105
-58
lines changed

Dockerfile

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ RUN powershell -command Install-Module -Name Pester -Force -SkipPublisherCheck
88
ADD . /data
99
WORKDIR /data
1010

11+
RUN dotnet restore "./test/example/example.csproj"
12+
1113
# run tests when running the container
1214
CMD powershell -command Invoke-Pester ./NuGetMetadata.Tests.ps1 -OutputFile test/results/results.xml -OutputFormat NUnitXml
1315

NuGetMetadata.Tests.ps1

-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
Remove-Module NuGetMetadata -ErrorAction SilentlyContinue
21
Import-Module "./NuGetMetadata.psm1"
32

43
$filePath = @{
@@ -91,7 +90,6 @@ Describe "Get-ZipFileEntryContent" {
9190
# Pester cannot mock .Open()
9291
# so we make a stub that always throws
9392
Add-Type -AssemblyName "System.IO.Compression"
94-
Add-Type -AssemblyName "System.IO.Compression.FileSystem"
9593
$zipFile = [System.IO.Compression.ZipFile]::OpenRead($filePath.absolute)
9694
$obj = $zipFile.Entries[0]
9795
$obj | Add-Member -MemberType ScriptMethod -Name Open -Value { throw "this method always throw an exception" } -Force

NuGetMetadata.psm1

+9-25
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
#assemblies loaded in the manifest:
22
Add-Type -AssemblyName "System.IO.Compression"
3-
Add-Type -AssemblyName "System.IO.Compression.FileSystem"
43

5-
6-
#::string -> XmlDocument
74
function Get-NuGetMetadata {
85
[CmdletBinding(
96
DefaultParameterSetName = 'Path'
@@ -13,16 +10,11 @@ function Get-NuGetMetadata {
1310
[string]$Path,
1411

1512
[Parameter(ParameterSetName = 'ConfigPath')]
16-
[string]$ConfigPath,
17-
18-
[Parameter(ParameterSetName = 'Path')]
19-
[switch]$NoRecurse
13+
[string]$ConfigPath
2014
)
21-
2215
BEGIN {
2316
$GCIparam = @{
2417
Path = $Path
25-
Recurse = !$NoRecurse
2618
}
2719

2820
$sln = Get-ChildItem -Filter '*.sln' @GCIparam
@@ -78,7 +70,7 @@ function Get-NupkgMetadata {
7870
Get-ZipFileEntry |
7971
SelectMatchingFullName -Pattern $EntryPattern |
8072
Get-ZipFileEntryContent |
81-
GetXmlMetadata
73+
GetNuGetPackageMetadata
8274
}
8375
else {
8476
Write-Error -Message "Path '$p' not found"
@@ -146,7 +138,7 @@ function GetPackageNameVersion {
146138
if (Test-Path $Path) {
147139
$xml = [xml](Get-Content $Path)
148140
Select-Xml -Xml $xml -XPath '//PackageReference' |
149-
Select-Object -ExpandProperty Node |
141+
select -ExpandProperty Node |
150142
ForEach-Object {
151143
$output = [PSCustomObject]@{
152144
Name = $_.Include
@@ -175,17 +167,9 @@ function GetNuGetPackageDirectory {
175167
Param(
176168
[Parameter(
177169
Mandatory = $true,
178-
ValueFromPipelineByPropertyName = $true
179-
)]
180-
[ValidateNotNullOrEmpty()]
181-
[string]$Name,
182-
183-
[Parameter(
184-
Mandatory = $true,
185-
ValueFromPipelineByPropertyName = $true
170+
ValueFromPipeline = $true
186171
)]
187-
[ValidateNotNullOrEmpty()]
188-
[string]$Version
172+
[PSCustomObject]$NameVersion
189173
)
190174
BEGIN {
191175
#todo: add logic here, for NuGet.config n stuff
@@ -194,7 +178,7 @@ function GetNuGetPackageDirectory {
194178
PROCESS {
195179
Write-Verbose "GetNuGetPackageDirectory input: $Path"
196180
$output = [PSCustomObject]@{
197-
Path = "$NuGetDefaultFolder\$Name\$Version"
181+
Path = "$NuGetDefaultFolder\$($NameVersion.Name)\$($NameVersion.Version)"
198182
}
199183
Write-Verbose "GetNuGetPackageDirectory output: $output"
200184
$output
@@ -258,7 +242,7 @@ function Get-ZipFileEntryContent {
258242
$deflateStream = $file.Open()
259243
$streamReader = New-Object System.IO.StreamReader($deflateStream)
260244
$fileContent = $streamReader.ReadToEnd()
261-
Write-Output $fileContent
245+
$fileContent
262246
}
263247
catch {
264248
WriteExceptionAsError $_
@@ -272,8 +256,8 @@ function Get-ZipFileEntryContent {
272256
END {}
273257
}
274258

275-
#::string[] -> XmlDocument
276-
function GetXmlMetadata {
259+
#::XmlDocument -> XmlDocument
260+
function GetNuGetPackageMetadata {
277261
Param(
278262
[Parameter(
279263
Mandatory = $true,

test/example/Nuget.config

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<config>
4+
<add key="repositoryPath" value="../packages" />
5+
</config>
6+
</configuration>

test/packages/2.2.0/xunit.2.2.0.nupkg

2.06 KB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DoB9o+x3erv1DGP+pSvrIC1pWg+23LeeG8nOGVldoF+qeWNqQbabc5jLfUWW4zLOsNZfvgHcmJIKuRcZMgoV+w==

test/packages/2.2.0/xunit.nuspec

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
3+
<metadata minClientVersion="2.12">
4+
<id>xunit</id>
5+
<version>2.2.0</version>
6+
<title>xUnit.net</title>
7+
<authors>James Newkirk,Brad Wilson</authors>
8+
<owners>James Newkirk,Brad Wilson</owners>
9+
<requireLicenseAcceptance>false</requireLicenseAcceptance>
10+
<licenseUrl>https://raw.githubusercontent.com/xunit/xunit/master/license.txt</licenseUrl>
11+
<projectUrl>https://github.com/xunit/xunit</projectUrl>
12+
<iconUrl>https://raw.githubusercontent.com/xunit/media/master/logo-512-transparent.png</iconUrl>
13+
<description>xUnit.net is a developer testing framework, built to support Test Driven Development, with a design goal of extreme simplicity and alignment with framework features.
14+
15+
Installing this package installs xunit.core and xunit.assert.</description>
16+
<summary>xUnit.net is a developer testing framework, built to support Test Driven Development.</summary>
17+
<language>en-US</language>
18+
<dependencies>
19+
<dependency id="xunit.core" version="[2.2.0]" />
20+
<dependency id="xunit.assert" version="[2.2.0]" />
21+
</dependencies>
22+
</metadata>
23+
</package>

0 commit comments

Comments
 (0)