CreateLocalNuget.ps1 (3535B)
1 # Copyright (c) Microsoft Corporation. All rights reserved. 2 # Licensed under the MIT License. 3 4 <# 5 .SYNOPSIS 6 Creates a local Microsoft.WindowsPackageManager.Utils nuget package and add it to a local nuget feed. 7 #> 8 9 [CmdletBinding()] 10 param ( 11 [Parameter(Mandatory)] 12 [ValidateSet("Debug", "Release", "ReleaseStatic")] 13 [string] 14 $Configuration, 15 16 [Parameter(Mandatory)] 17 [string] 18 $NugetVersion, 19 20 [string] 21 $BuildRoot = "", 22 23 [string] 24 $LocalNugetSource = "" 25 ) 26 27 if ($BuildRoot -eq "") 28 { 29 $BuildRoot = "$PSScriptRoot\..\.."; 30 } 31 32 $local:repoPath = "$PSScriptRoot\..\..\..\" 33 34 # Create all directories and copy files in location expected from the nuspec. 35 # The paths contains 'release' but it whatever configuration the param is. 36 $local:nugetWorkingDir = "$PSScriptRoot\NugetFiles" 37 $local:x64NugetPath = "$nugetWorkingDir\Build.x64release\src\x64\Release\WinGetUtil" 38 $local:x86NugetPath = "$nugetWorkingDir\Build.x86release\src\x86\Release\WinGetUtil" 39 $local:manifestsNugetPath = "$nugetWorkingDir\Build.x64release\schemas\JSON\manifests" 40 $local:interopNugetPath = "$nugetWorkingDir\Build.x64release\src\WinGetUtilInterop\bin\Release\netstandard2.1" 41 $local:targetsNugetPath = "$nugetWorkingDir\Build.x64release\src\WinGetUtilInterop\build" 42 43 Write-Host "Prepare nuget files" 44 if (Test-Path $nugetWorkingDir) 45 { 46 Remove-Item $nugetWorkingDir -Recurse 47 } 48 New-Item $nugetWorkingDir -ItemType directory | Out-Null 49 New-Item $x64NugetPath -ItemType directory | Out-Null 50 New-Item $x86NugetPath -ItemType directory | Out-Null 51 New-Item $manifestsNugetPath -ItemType directory | Out-Null 52 New-Item $interopNugetPath -ItemType directory | Out-Null 53 New-Item $targetsNugetPath -ItemType directory | Out-Null 54 55 function CopyFile([string]$in, [string]$out) 56 { 57 $copyErrors = $null 58 Copy-Item $in $out -Force -ErrorVariable copyErrors -ErrorAction SilentlyContinue 59 $copyErrors | ForEach-Object { Write-Warning $_ } 60 } 61 62 CopyFile "$BuildRoot\x64\$Configuration\WinGetUtil\WinGetUtil.dll" "$x64NugetPath\WinGetUtil.dll" 63 CopyFile "$BuildRoot\x64\$Configuration\WinGetUtil\WinGetUtil.pdb" "$x64NugetPath\WinGetUtil.pdb" 64 CopyFile "$BuildRoot\x86\$Configuration\WinGetUtil\WinGetUtil.dll" "$x86NugetPath\WinGetUtil.dll" 65 CopyFile "$BuildRoot\x86\$Configuration\WinGetUtil\WinGetUtil.pdb" "$x86NugetPath\WinGetUtil.pdb" 66 CopyFile "$repoPath\src\WinGetUtilInterop\bin\$Configuration\netstandard2.1\WinGetUtilInterop.dll" "$interopNugetPath\WinGetUtilInterop.dll" 67 CopyFile "$repoPath\src\WinGetUtilInterop\bin\$Configuration\netstandard2.1\WinGetUtilInterop.pdb" "$interopNugetPath\WinGetUtilInterop.pdb" 68 CopyFile "$repoPath\src\WinGetUtilInterop\build\Microsoft.WindowsPackageManager.Utils.targets" "$targetsNugetPath\Microsoft.WindowsPackageManager.Utils.targets" 69 CopyFile "$PSScriptRoot\WinGetUtilDev.nuspec" "$nugetWorkingDir\WinGetUtilDev.nuspec" 70 Copy-Item "$repoPath\schemas\JSON\manifests" $manifestsNugetPath -Recurse 71 72 # Create nuget 73 Write-Host "Creating nuget package" 74 $local:result = nuget pack .\NugetFiles\WinGetUtilDev.nuspec -Version $NugetVersion -OutputDirectory NugetOut 75 $local:outFile = $result -match "nupkg" 76 $outFile = $outFile[0] 77 $outFile = $outFile.Substring($outFile.IndexOf("'") + 1, $outFile.LastIndexOf("'") - $outFile.IndexOf("'") - 1) 78 Write-Host "Created $outFile" 79 80 if ($LocalNugetSource -ne "") 81 { 82 Write-Host "Adding $outFile to local nuget feed" 83 nuget add $outFile -Source $LocalNugetSource 84 } 85