Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8a8f2d4

Browse files
authored
Make Microsoft feeds the default (#24098)
1 parent 5eb9ae4 commit 8a8f2d4

13 files changed

Lines changed: 114 additions & 49 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,6 @@ StartupProfileData-NonInteractive
101101

102102
# Ignore logfiles
103103
logfile/*
104+
105+
# Ignore nuget.config because it is dynamically generated
106+
nuget.config

.pipelines/templates/insert-nuget-config-azfeed.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ steps:
55
- pwsh: |
66
$configPath = "${env:NugetConfigDir}/nuget.config"
77
Import-Module ${{ parameters.repoRoot }}/build.psm1 -Force
8-
New-NugetConfigFile -NugetFeedUrl $(PowerShellCore_PublicPackages) -UserName $(AzDevopsFeedUserNameKVPAT) -ClearTextPAT $(mscodehubPackageReadPat) -FeedName AzDevOpsFeed -Destination "${env:NugetConfigDir}"
8+
9+
$powerShellPublicPackages = [NugetPackageSource] @{Url = '$(PowerShellCore_PublicPackages)'; Name= 'AzDevOpsFeed'}
10+
11+
New-NugetConfigFile -NugetPackageSource $powerShellPublicPackages -UserName $(AzDevopsFeedUserNameKVPAT) -ClearTextPAT $(mscodehubPackageReadPat) -Destination "${env:NugetConfigDir}"
912
if(-not (Test-Path $configPath))
1013
{
1114
throw "nuget.config is not created"
@@ -20,8 +23,11 @@ steps:
2023
- pwsh: |
2124
$configPath = "${env:NugetConfigDir}/nuget.config"
2225
Import-Module ${{ parameters.repoRoot }}/build.psm1 -Force
23-
New-NugetConfigFile -NugetFeedUrl $(PowerShellCore_PublicPackages) -UserName $(AzDevopsFeedUserNameKVPAT) -ClearTextPAT $(mscodehubPackageReadPat) -FeedName AzDevOpsFeed -Destination "${env:NugetConfigDir}"
24-
if(-not (Test-Path $configPath))
26+
27+
$powerShellPublicPackages = [NugetPackageSource] @{Url = '$(PowerShellCore_PublicPackages)'; Name= 'AzDevOpsFeed'}
28+
29+
New-NugetConfigFile -NugetPackageSource $powerShellPublicPackages -UserName $(AzDevopsFeedUserNameKVPAT) -ClearTextPAT $(mscodehubPackageReadPat) -Destination "${env:NugetConfigDir}"
30+
if (-not (Test-Path $configPath))
2531
{
2632
throw "nuget.config is not created"
2733
}

.vsts-ci/windows/templates/windows-packaging.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ jobs:
5050
5151
- template: /tools/releaseBuild/azureDevOps/templates/insert-nuget-config-azfeed.yml
5252

53+
- pwsh: |
54+
Import-Module .\tools\ci.psm1
55+
Switch-PSNugetConfig -Source Public
56+
displayName: Switch to public feeds
57+
condition: succeeded()
58+
workingDirectory: $(repoPath)
59+
5360
- pwsh: |
5461
Import-Module .\tools\ci.psm1
5562
Invoke-CIInstall -SkipUser

build.psm1

Lines changed: 78 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,9 @@ function Start-PSBuild {
307307
# it's useful for development, to do a quick changes in the engine
308308
[switch]$SMAOnly,
309309

310+
# Use nuget.org instead of the PowerShell specific feed
311+
[switch]$UseNuGetOrg,
312+
310313
# These runtimes must match those in project.json
311314
# We do not use ValidateScript since we want tab completion
312315
# If this parameter is not provided it will get determined automatically.
@@ -362,6 +365,12 @@ function Start-PSBuild {
362365
}
363366
}
364367

368+
if ($UseNuGetOrg) {
369+
Switch-PSNugetConfig -Source Public
370+
} else {
371+
Write-Verbose -Message "Using default feeds which are Microsoft, use `-UseNuGetOrg` to switch to Public feeds" -Verbose
372+
}
373+
365374
function Stop-DevPowerShell {
366375
Get-Process pwsh* |
367376
Where-Object {
@@ -718,6 +727,29 @@ Fix steps:
718727
}
719728
}
720729

730+
function Switch-PSNugetConfig {
731+
param(
732+
[ValidateSet('Public', 'Private')]
733+
[string] $Source = 'Public'
734+
)
735+
736+
if ( $Source -eq 'Public') {
737+
$dotnetSdk = [NugetPackageSource] @{Url = 'https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet9/nuget/v2'; Name = 'dotnet' }
738+
$gallery = [NugetPackageSource] @{Url = 'https://www.powershellgallery.com/api/v2/'; Name = 'psgallery' }
739+
$nugetorg = [NugetPackageSource] @{Url = 'https://api.nuget.org/v3/index.json'; Name = 'nuget.org' }
740+
741+
New-NugetConfigFile -NugetPackageSource $nugetorg, $dotnetSdk -Destination "$PSScriptRoot/"
742+
New-NugetConfigFile -NugetPackageSource $gallery -Destination "$PSScriptRoot/src/Modules/"
743+
} elseif ( $Source -eq 'Private') {
744+
$powerShellPackages = [NugetPackageSource] @{Url = 'https://pkgs.dev.azure.com/powershell/PowerShell/_packaging/powershell/nuget/v3/index.json'; Name = 'powershell' }
745+
746+
New-NugetConfigFile -NugetPackageSource $powerShellPackages -Destination "$PSScriptRoot/"
747+
New-NugetConfigFile -NugetPackageSource $powerShellPackages -Destination "$PSScriptRoot/src/Modules/"
748+
} else {
749+
throw "Unknown source: $Source"
750+
}
751+
}
752+
721753
function Test-ShouldGenerateExperimentalFeatures
722754
{
723755
param(
@@ -1284,9 +1316,14 @@ function Start-PSPester {
12841316
[Parameter(ParameterSetName='Wait', Mandatory=$true,
12851317
HelpMessage='Wait for the debugger to attach to PowerShell before Pester starts. Debug builds only!')]
12861318
[switch]$Wait,
1287-
[switch]$SkipTestToolBuild
1319+
[switch]$SkipTestToolBuild,
1320+
[switch]$UseNuGetOrg
12881321
)
12891322

1323+
if ($UseNuGetOrg) {
1324+
Switch-PSNugetConfig -Source Public
1325+
}
1326+
12901327
if (-not (Get-Module -ListAvailable -Name $Pester -ErrorAction SilentlyContinue | Where-Object { $_.Version -ge "4.2" } ))
12911328
{
12921329
Restore-PSPester
@@ -3394,36 +3431,67 @@ function New-TestPackage
33943431
[System.IO.Compression.ZipFile]::CreateFromDirectory($packageRoot, $packagePath)
33953432
}
33963433

3397-
function New-NugetConfigFile
3398-
{
3434+
class NugetPackageSource {
3435+
[string] $Url
3436+
[string] $Name
3437+
}
3438+
3439+
function New-NugetConfigFile {
33993440
param(
3400-
[Parameter(Mandatory=$true)] [string] $NugetFeedUrl,
3401-
[Parameter(Mandatory=$true)] [string] $FeedName,
3402-
[Parameter(Mandatory=$true)] [string] $UserName,
3403-
[Parameter(Mandatory=$true)] [string] $ClearTextPAT,
3404-
[Parameter(Mandatory=$true)] [string] $Destination
3441+
[Parameter(Mandatory = $true, ParameterSetName ='user')]
3442+
[Parameter(Mandatory = $true, ParameterSetName ='nouser')]
3443+
[NugetPackageSource[]] $NugetPackageSource,
3444+
3445+
[Parameter(Mandatory = $true)] [string] $Destination,
3446+
3447+
[Parameter(Mandatory = $true, ParameterSetName = 'user')]
3448+
[string] $UserName,
3449+
3450+
[Parameter(Mandatory = $true, ParameterSetName = 'user')]
3451+
[string] $ClearTextPAT
34053452
)
34063453

3407-
$nugetConfigTemplate = @'
3454+
$nugetConfigHeaderTemplate = @'
34083455
<?xml version="1.0" encoding="utf-8"?>
34093456
<configuration>
34103457
<packageSources>
34113458
<clear />
3459+
'@
3460+
3461+
$nugetPackageSourceTemplate = @'
34123462
<add key="[FEEDNAME]" value="[FEED]" />
3463+
'@
3464+
$nugetPackageSourceFooterTemplate = @'
34133465
</packageSources>
34143466
<disabledPackageSources>
34153467
<clear />
34163468
</disabledPackageSources>
3469+
'@
3470+
$nugetCredentialsTemplate = @'
34173471
<packageSourceCredentials>
34183472
<[FEEDNAME]>
34193473
<add key="Username" value="[USERNAME]" />
34203474
<add key="ClearTextPassword" value="[PASSWORD]" />
34213475
</[FEEDNAME]>
34223476
</packageSourceCredentials>
3477+
'@
3478+
$nugetConfigFooterTemplate = @'
34233479
</configuration>
34243480
'@
3481+
$content = $nugetConfigHeaderTemplate
3482+
3483+
[NugetPackageSource]$source = $null
3484+
foreach ($source in $NugetPackageSource) {
3485+
$content += $nugetPackageSourceTemplate.Replace('[FEED]', $source.Url).Replace('[FEEDNAME]', $source.Name)
3486+
}
3487+
3488+
$content += $nugetPackageSourceFooterTemplate
3489+
3490+
if ($UserName -or $ClearTextPAT) {
3491+
$content += $nugetCredentialsTemplate.Replace('[USERNAME]', $UserName).Replace('[PASSWORD]', $ClearTextPAT)
3492+
}
34253493

3426-
$content = $nugetConfigTemplate.Replace('[FEED]', $NugetFeedUrl).Replace('[FEEDNAME]', $FeedName).Replace('[USERNAME]', $UserName).Replace('[PASSWORD]', $ClearTextPAT)
3494+
$content += $nugetConfigFooterTemplate
34273495

34283496
Set-Content -Path (Join-Path $Destination 'nuget.config') -Value $content -Force
34293497
}

docs/building/linux.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ The build module works on a best-effort basis for other distributions.
1212

1313
Using Git requires it to be set up correctly;
1414
refer to the [Working with the PowerShell Repository](../git/README.md),
15-
[README](../../README.md), and [Contributing Guidelines](../../.github/CONTRIBUTING.md).
15+
[Readme](../../README.md), and [Contributing Guidelines](../../.github/CONTRIBUTING.md).
1616

1717
**This guide assumes that you have recursively cloned the PowerShell repository and `cd`ed into it.**
1818

@@ -63,7 +63,7 @@ If you have followed the toolchain setup section above, you should have PowerShe
6363

6464
```powershell
6565
Import-Module ./build.psm1
66-
Start-PSBuild
66+
Start-PSBuild -UseNuGetOrg
6767
```
6868

6969
Congratulations! If everything went right, PowerShell is now built.
@@ -72,4 +72,4 @@ The `Start-PSBuild` script will output the location of the executable:
7272
`./src/powershell-unix/bin/Debug/net6.0/linux-x64/publish/pwsh`.
7373

7474
You should now be running the PowerShell Core that you just built, if you run the above executable.
75-
You can run our cross-platform Pester tests with `Start-PSPester`, and our xUnit tests with `Start-PSxUnit`.
75+
You can run our cross-platform Pester tests with `Start-PSPester -UseNuGetOrg`, and our xUnit tests with `Start-PSxUnit`.

docs/building/macos.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ We cannot do this for you in the build module due to #[847][].
3434

3535
## Build using our module
3636

37-
Start a PowerShell session by running `pwsh`, and then use `Start-PSBuild` from the module.
37+
Start a PowerShell session by running `pwsh`, and then use `Start-PSBuild -UseNuGetOrg` from the module.
3838

3939
After building, PowerShell will be at `./src/powershell-unix/bin/Debug/net6.0/osx-x64/publish/pwsh`.

docs/building/windows-core.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ R2, though they should work anywhere the dependencies work.
1111
### Git Setup
1212

1313
Using Git requires it to be setup correctly; refer to the
14-
[README](../../README.md) and
14+
[Readme](../../README.md) and
1515
[Contributing Guidelines](../../.github/CONTRIBUTING.md).
1616

1717
This guide assumes that you have recursively cloned the PowerShell repository and `cd`ed into it.
@@ -56,7 +56,7 @@ We maintain a [PowerShell module](../../build.psm1) with the function `Start-PSB
5656

5757
```powershell
5858
Import-Module ./build.psm1
59-
Start-PSBuild -Clean -PSModuleRestore
59+
Start-PSBuild -Clean -PSModuleRestore -UseNuGetOrg
6060
```
6161

6262
Congratulations! If everything went right, PowerShell is now built and executable as `./src/powershell-win-core/bin/Debug/net6.0/win7-x64/publish/pwsh.exe`.
@@ -77,7 +77,7 @@ You can run our cross-platform Pester tests with `Start-PSPester`.
7777

7878
```powershell
7979
Import-Module ./build.psm1
80-
Start-PSPester
80+
Start-PSPester -UseNuGetOrg
8181
```
8282

8383
## Building in Visual Studio

nuget.config

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
<configuration>
33
<packageSources>
44
<clear />
5-
<add key="dotnet" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet9/nuget/v2" />
6-
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
5+
<add key="powershell" value="https://pkgs.dev.azure.com/powershell/PowerShell/_packaging/powershell/nuget/v3/index.json" />
76
</packageSources>
87
<disabledPackageSources>
98
<clear />

src/Modules/nuget.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<configuration>
33
<packageSources>
44
<clear />
5-
<add key="PSGallery" value="https://www.powershellgallery.com/api/v2/" />
5+
<add key="powershell" value="https://pkgs.dev.azure.com/powershell/PowerShell/_packaging/powershell/nuget/v3/index.json" />
66
</packageSources>
77
<disabledPackageSources>
88
<clear />

test/hosting/NuGet.Config

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)