GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Merged PR 5667: Add function to create a new nuget.config file (#8170) · TravisEz13/PowerShell@ea3c016

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • build.psm1
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎build.psm1‎

Copy file name to clipboardExpand all lines: build.psm1
+104-1Lines changed: 104 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,8 @@ function Start-PSBuild {
472472
Push-Location $PSScriptRoot
473473
try {
474474
# Excluded sqlite3 folder is due to this Roslyn issue: https://github.com/dotnet/roslyn/issues/23060
475-
git clean -fdx --exclude .vs/PowerShell/v15/Server/sqlite3
475+
# Excluded src/Modules/nuget.config as this is required for release build.
476+
git clean -fdx --exclude .vs/PowerShell/v15/Server/sqlite3 --exclude src/Modules/nuget.config
476477
} finally {
477478
Pop-Location
478479
}
@@ -3243,3 +3244,105 @@ $script:RESX_TEMPLATE = @'
32433244
{0}
32443245
</root>
32453246
'@
3247+
3248+
function New-TestPackage
3249+
{
3250+
[CmdletBinding()]
3251+
param(
3252+
[Parameter(Mandatory = $true)]
3253+
[string] $Destination
3254+
)
3255+
3256+
if (Test-Path $Destination -PathType Leaf)
3257+
{
3258+
throw "Destination: '$Destination' is not a directory or does not exist."
3259+
}
3260+
else
3261+
{
3262+
$null = New-Item -Path $Destination -ItemType Directory -Force
3263+
Write-Verbose -Message "Creating destination folder: $Destination"
3264+
}
3265+
3266+
$rootFolder = $env:TEMP
3267+
3268+
if (-not $rootFolder -and $env:TF_BUILD) {
3269+
$rootFolder = $env:AGENT_WORKFOLDER
3270+
}
3271+
3272+
Write-Verbose -Verbose "RootFolder: $rootFolder"
3273+
3274+
$packageRoot = Join-Path $rootFolder ('TestPackage-' + (new-guid))
3275+
$null = New-Item -ItemType Directory -Path $packageRoot -Force
3276+
$packagePath = Join-Path $Destination "TestPackage.zip"
3277+
Write-Verbose -Verbose "PackagePath: $packagePath"
3278+
3279+
# Build test tools so they are placed in appropriate folders under 'test' then copy to package root.
3280+
$null = Publish-PSTestTools
3281+
$powerShellTestRoot = Join-Path $PSScriptRoot 'test'
3282+
Copy-Item $powerShellTestRoot -Recurse -Destination $packageRoot -Force
3283+
Write-Verbose -Message "Copied test directory"
3284+
3285+
# Copy assests folder to package root for wix related tests.
3286+
$assetsPath = Join-Path $PSScriptRoot 'assets'
3287+
Copy-Item $assetsPath -Recurse -Destination $packageRoot -Force
3288+
Write-Verbose -Message "Copied assests directory"
3289+
3290+
# Create expected folder structure for resx files in package root.
3291+
$srcRootForResx = New-Item -Path "$packageRoot/src" -Force -ItemType Directory
3292+
3293+
$resourceDirectories = Get-ChildItem -Recurse "$PSScriptRoot/src" -Directory -Filter 'resources'
3294+
3295+
$resourceDirectories | ForEach-Object {
3296+
$directoryFullName = $_.FullName
3297+
3298+
$partToRemove = Join-Path $PSScriptRoot "src"
3299+
3300+
$assemblyPart = $directoryFullName.Replace($partToRemove, '')
3301+
$assemblyPart = $assemblyPart.TrimStart([io.path]::DirectorySeparatorChar)
3302+
$resxDestPath = Join-Path $srcRootForResx $assemblyPart
3303+
$null = New-Item -Path $resxDestPath -Force -ItemType Directory
3304+
Write-Verbose -Message "Created resx directory : $resxDestPath"
3305+
Copy-Item -Path "$directoryFullName\*" -Recurse $resxDestPath -Force
3306+
}
3307+
3308+
Add-Type -AssemblyName System.IO.Compression.FileSystem
3309+
3310+
if(Test-Path $packagePath)
3311+
{
3312+
Remove-Item -Path $packagePath -Force
3313+
}
3314+
3315+
[System.IO.Compression.ZipFile]::CreateFromDirectory($packageRoot, $packagePath)
3316+
}
3317+
3318+
function New-NugetConfigFile
3319+
{
3320+
param(
3321+
[Parameter(Mandatory=$true)] [string] $NugetFeedUrl,
3322+
[Parameter(Mandatory=$true)] [string] $FeedName,
3323+
[Parameter(Mandatory=$true)] [string] $UserName,
3324+
[Parameter(Mandatory=$true)] [string] $ClearTextPAT,
3325+
[Parameter(Mandatory=$true)] [string] $Destination
3326+
)
3327+
3328+
$nugetConfigTemplate = @'
3329+
<?xml version="1.0" encoding="utf-8"?>
3330+
<configuration>
3331+
<packageSources>
3332+
<clear />
3333+
<add key="[FEEDNAME]" value="[FEED]" />
3334+
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
3335+
</packageSources>
3336+
<packageSourceCredentials>
3337+
<[FEEDNAME]>
3338+
<add key="Username" value="[USERNAME]" />
3339+
<add key="ClearTextPassword" value="[PASSWORD]" />
3340+
</[FEEDNAME]>
3341+
</packageSourceCredentials>
3342+
</configuration>
3343+
'@
3344+
3345+
$content = $nugetConfigTemplate.Replace('[FEED]', $NugetFeedUrl).Replace('[FEEDNAME]', $FeedName).Replace('[USERNAME]', $UserName).Replace('[PASSWORD]', $ClearTextPAT)
3346+
3347+
Set-Content -Path (Join-Path $Destination 'nuget.config') -Value $content -Force
3348+
}

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.