From 809dbf7aef3b4f2de1e94b68e14df5c1f0f9e461 Mon Sep 17 00:00:00 2001 From: Chidozie Ononiwu Date: Fri, 17 Jul 2026 15:31:51 -0700 Subject: [PATCH 01/18] Enforce CFSClean for Network Isolation --- eng/common/pipelines/templates/1es-redirect.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/eng/common/pipelines/templates/1es-redirect.yml b/eng/common/pipelines/templates/1es-redirect.yml index 7711cb6d7a1..00be16b2438 100644 --- a/eng/common/pipelines/templates/1es-redirect.yml +++ b/eng/common/pipelines/templates/1es-redirect.yml @@ -27,6 +27,7 @@ extends: parameters: settings: skipBuildTagsForGitHubPullRequests: true + networkIsolationPolicy: Permissive, CFSClean sdl: codeql: compiled: From 3f9de49983c0c05f260944dfb9fe20a88eea354f Mon Sep 17 00:00:00 2001 From: Chidozie Ononiwu Date: Fri, 17 Jul 2026 15:59:58 -0700 Subject: [PATCH 02/18] Add Nuget config targeting devOps feed --- NuGet.Config | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 NuGet.Config diff --git a/NuGet.Config b/NuGet.Config new file mode 100644 index 00000000000..c679a5601f0 --- /dev/null +++ b/NuGet.Config @@ -0,0 +1,11 @@ + + + + + + + + + + + From 02d5dd5f3ee58cd738af1db30aa398cdeec292ce Mon Sep 17 00:00:00 2001 From: Chidozie Ononiwu Date: Fri, 17 Jul 2026 16:34:48 -0700 Subject: [PATCH 03/18] Authenticate to Dev Feed for Java and Python --- .../templates/steps/auth-dev-feed.yml | 49 +++++++++++++++++++ .../templates/steps/maven-authenticate.yml | 17 +++++++ .../pipelines/templates/steps/build-step.yml | 4 ++ 3 files changed, 70 insertions(+) create mode 100644 eng/common/pipelines/templates/steps/auth-dev-feed.yml create mode 100644 eng/common/pipelines/templates/steps/maven-authenticate.yml diff --git a/eng/common/pipelines/templates/steps/auth-dev-feed.yml b/eng/common/pipelines/templates/steps/auth-dev-feed.yml new file mode 100644 index 00000000000..464136b3dc7 --- /dev/null +++ b/eng/common/pipelines/templates/steps/auth-dev-feed.yml @@ -0,0 +1,49 @@ +parameters: + DevFeedName: 'public/azure-sdk-for-python' + EnableTwineAuth: true + EnablePipAuth: true + EnableUvAuth: true + +steps: + - pwsh: | + # For safety default to publishing to the private feed. + # Publish to https://dev.azure.com/azure-sdk/internal/_packaging?_a=feed&feed=azure-sdk-for-python-pr + $devopsFeedName = 'internal/azure-sdk-for-python-pr' + if ('$(Build.Repository.Name)' -eq 'Azure/azure-sdk-for-python') { + # Publish to https://dev.azure.com/azure-sdk/public/_packaging?_a=feed&feed=azure-sdk-for-python + $devopsFeedName = '${{ parameters.DevFeedName }}' + } + echo "##vso[task.setvariable variable=DevFeedName]$devopsFeedName" + echo "Using DevopsFeed = $devopsFeedName" + displayName: Setup DevOpsFeedName + + - ${{ if eq(parameters.EnableTwineAuth, true) }}: + - task: TwineAuthenticate@0 + displayName: 'Twine Authenticate to feed' + inputs: + artifactFeeds: $(DevFeedName) + + - ${{ if eq(parameters.EnablePipAuth, true) }}: + - task: PipAuthenticate@1 + displayName: 'Pip Authenticate to feed' + inputs: + artifactFeeds: $(DevFeedName) + onlyAddExtraIndex: false + + - ${{ if eq(parameters.EnableUvAuth, true) }}: + - pwsh: | + if ($env:PIP_INDEX_URL) { + Write-Host "Found pip index URL: $($env:PIP_INDEX_URL)" + # UV_DEFAULT_INDEX is the canonical replacement for the deprecated UV_INDEX_URL (uv 0.4.23+). + # PIP_INDEX_URL is set by PipAuthenticate@1 and contains embedded credentials, which uv + # will use for Basic auth against the ADO feed (and its PyPI upstream) per astral-sh/uv#12651. + Write-Host "##vso[task.setvariable variable=UV_DEFAULT_INDEX]$($env:PIP_INDEX_URL)" + # Disable keyring so uv uses the URL-embedded credentials directly. + Write-Host "##vso[task.setvariable variable=UV_KEYRING_PROVIDER]disabled" + } else { + Write-Host "##[warning]PIP_INDEX_URL not set - uv will fall back to public PyPI." + } + # Force any managed Python downloads to go directly to GitHub releases + # rather than the default CDN (releases.astral.sh). + Write-Host "##vso[task.setvariable variable=UV_PYTHON_INSTALL_MIRROR]https://github.com/astral-sh/python-build-standalone/releases/download" + displayName: 'Configure UV Authentication' diff --git a/eng/common/pipelines/templates/steps/maven-authenticate.yml b/eng/common/pipelines/templates/steps/maven-authenticate.yml new file mode 100644 index 00000000000..f03caee204f --- /dev/null +++ b/eng/common/pipelines/templates/steps/maven-authenticate.yml @@ -0,0 +1,17 @@ +parameters: + SourceDirectory: $(Build.SourcesDirectory) + +steps: + # Copy mirror settings to default Maven location so all requests go through CFS + - pwsh: | + $m2Dir = if ($env:USERPROFILE) { "$env:USERPROFILE\.m2" } else { "$HOME/.m2" } + New-Item -ItemType Directory -Force -Path $m2Dir | Out-Null + Copy-Item -Path "${{ parameters.SourceDirectory }}/eng/settings.xml" -Destination "$m2Dir/settings.xml" + displayName: 'Setup Maven mirror settings' + + # Authenticate with Azure Artifacts feeds + # MavenAuthenticate adds entries to ~/.m2/settings.xml matching mirror id 'azure-sdk-for-java' + - task: MavenAuthenticate@0 + displayName: 'Maven Authenticate' + inputs: + artifactsFeeds: 'azure-sdk-for-java' diff --git a/eng/emitters/pipelines/templates/steps/build-step.yml b/eng/emitters/pipelines/templates/steps/build-step.yml index d723de94d4b..a0888cd13cb 100644 --- a/eng/emitters/pipelines/templates/steps/build-step.yml +++ b/eng/emitters/pipelines/templates/steps/build-step.yml @@ -61,6 +61,10 @@ steps: - template: /eng/common/pipelines/templates/steps/create-authenticated-npmrc.yml + - template: /eng/common/pipelines/templates/steps/auth-dev-feed.yml + + - template: /eng/common/pipelines/templates/steps/maven-authenticate.yml + - task: NodeTool@0 displayName: Install Node.js retryCountOnTaskFailure: 3 From 51a68a490e285b26dbb5db1eacd5976843df6406 Mon Sep 17 00:00:00 2001 From: Chidozie Ononiwu Date: Mon, 20 Jul 2026 11:55:31 -0700 Subject: [PATCH 04/18] Add maven-authenticate settings.xml --- .../pipelines/templates/steps/auth-dev-feed.yml | 2 +- eng/settings.xml | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 eng/settings.xml diff --git a/eng/common/pipelines/templates/steps/auth-dev-feed.yml b/eng/common/pipelines/templates/steps/auth-dev-feed.yml index 464136b3dc7..cd8fa23e67e 100644 --- a/eng/common/pipelines/templates/steps/auth-dev-feed.yml +++ b/eng/common/pipelines/templates/steps/auth-dev-feed.yml @@ -9,7 +9,7 @@ steps: # For safety default to publishing to the private feed. # Publish to https://dev.azure.com/azure-sdk/internal/_packaging?_a=feed&feed=azure-sdk-for-python-pr $devopsFeedName = 'internal/azure-sdk-for-python-pr' - if ('$(Build.Repository.Name)' -eq 'Azure/azure-sdk-for-python') { + if (-not ('$(Build.Repository.Name)').EndsWith('-pr')) { # Publish to https://dev.azure.com/azure-sdk/public/_packaging?_a=feed&feed=azure-sdk-for-python $devopsFeedName = '${{ parameters.DevFeedName }}' } diff --git a/eng/settings.xml b/eng/settings.xml new file mode 100644 index 00000000000..b1941716f65 --- /dev/null +++ b/eng/settings.xml @@ -0,0 +1,13 @@ + + + + azure-sdk-for-java + Azure Artifacts Maven Mirror + https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-java/maven/v1 + external:* + + + From 4cd3d1f0daf653c8b69123ad14aa94c98fa064f1 Mon Sep 17 00:00:00 2001 From: Chidozie Ononiwu Date: Mon, 20 Jul 2026 14:41:35 -0700 Subject: [PATCH 05/18] Update ExternalTypeReferenceResolverTests does not probe external feeds --- .../ExternalTypeReferenceResolverTests.cs | 61 ++++++++++++++----- 1 file changed, 46 insertions(+), 15 deletions(-) diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Utilities/ExternalTypeReferenceResolverTests.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Utilities/ExternalTypeReferenceResolverTests.cs index 65966107ab2..c722e206285 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Utilities/ExternalTypeReferenceResolverTests.cs +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Utilities/ExternalTypeReferenceResolverTests.cs @@ -21,6 +21,7 @@ public class ExternalTypeReferenceResolverTests { private string? _tempDirectory; private string? _projectDir; + private string? _nugetCacheDir; private string? _originalNugetPackageDir; [SetUp] @@ -28,14 +29,18 @@ public void Setup() { _tempDirectory = Path.Combine(Path.GetTempPath(), "TestArtifacts", Guid.NewGuid().ToString()); _projectDir = Path.Combine(_tempDirectory, "ProjectDir"); - var nugetCacheDir = Path.Combine(_tempDirectory, "NuGetCache"); + _nugetCacheDir = Path.Combine(_tempDirectory, "NuGetCache"); Directory.CreateDirectory(Path.Combine(_projectDir, "src")); - Directory.CreateDirectory(nugetCacheDir); + Directory.CreateDirectory(_nugetCacheDir); + + // Ensure these tests are fully isolated from machine/user NuGet settings and never probe + // external feeds when package lookup falls through to source probing. + WriteLocalNuGetConfig(_projectDir, _nugetCacheDir); _originalNugetPackageDir = Environment.GetEnvironmentVariable("NUGET_PACKAGES", EnvironmentVariableTarget.Process); - Environment.SetEnvironmentVariable("NUGET_PACKAGES", nugetCacheDir, EnvironmentVariableTarget.Process); + Environment.SetEnvironmentVariable("NUGET_PACKAGES", _nugetCacheDir, EnvironmentVariableTarget.Process); - ExternalTypeReferenceResolver.Reset(); + ResetResolverIfInitialized(); MockHelpers.LoadMockGenerator( outputPath: _projectDir, configuration: "{}"); @@ -44,7 +49,7 @@ public void Setup() [TearDown] public void Cleanup() { - ExternalTypeReferenceResolver.Reset(); + ResetResolverIfInitialized(); Directory.Delete(_tempDirectory!, true); Environment.SetEnvironmentVariable("NUGET_PACKAGES", _originalNugetPackageDir, EnvironmentVariableTarget.Process); } @@ -65,10 +70,9 @@ public void TryResolve_ReturnsNullWhenPackageMissing() [Test] public void TryResolve_LoadsTypeFromNuGetCache() { - var nugetCacheDir = Path.Combine(_tempDirectory!, "NuGetCache"); const string pkgName = "Test.External.Loadable"; const string typeName = "Test.External.Loadable.LoadableType"; - CreateFakeNuGetPackage(nugetCacheDir, pkgName, "1.2.3"); + CreateFakeNuGetPackage(_nugetCacheDir!, pkgName, "1.2.3"); var external = new InputExternalTypeMetadata(typeName, pkgName, null); @@ -81,14 +85,13 @@ public void TryResolve_LoadsTypeFromNuGetCache() [Test] public void TryResolve_PrefersHighestCachedVersionAtOrAboveMinVersion() { - var nugetCacheDir = Path.Combine(_tempDirectory!, "NuGetCache"); const string pkgName = "Test.MultiVersion.Package"; const string typeName = "Test.MultiVersion.Package.SomeType"; // Create three cached versions; MinVersion=2.0.0 must skip 1.0.0 and pick 3.0.0 (highest >= MinVersion). - CreateFakeNuGetPackage(nugetCacheDir, pkgName, "1.0.0"); - CreateFakeNuGetPackage(nugetCacheDir, pkgName, "2.5.0"); - CreateFakeNuGetPackage(nugetCacheDir, pkgName, "3.0.0"); + CreateFakeNuGetPackage(_nugetCacheDir!, pkgName, "1.0.0"); + CreateFakeNuGetPackage(_nugetCacheDir!, pkgName, "2.5.0"); + CreateFakeNuGetPackage(_nugetCacheDir!, pkgName, "3.0.0"); var external = new InputExternalTypeMetadata(typeName, pkgName, "2.0.0"); var resolved = ExternalTypeReferenceResolver.TryResolve(external); @@ -105,10 +108,9 @@ public void TryResolve_PrefersHighestCachedVersionAtOrAboveMinVersion() [Test] public void TryResolve_AddsMetadataReferenceOnce() { - var nugetCacheDir = Path.Combine(_tempDirectory!, "NuGetCache"); const string pkgName = "Test.MetadataRef.Package"; const string typeName = "Test.MetadataRef.Package.RefType"; - CreateFakeNuGetPackage(nugetCacheDir, pkgName, "1.0.0"); + CreateFakeNuGetPackage(_nugetCacheDir!, pkgName, "1.0.0"); var external = new InputExternalTypeMetadata(typeName, pkgName, null); @@ -216,10 +218,9 @@ public void TryResolve_ReportsFailureReasonWhenTypeMissingFromAssembly() [Test] public async Task ResolveAllAsync_ResolvesExternalTypesFromInputLibrary() { - var nugetCacheDir = Path.Combine(_tempDirectory!, "NuGetCache"); const string pkgName = "Test.PreWalk.Package"; const string typeName = "Test.PreWalk.Package.PreWalkType"; - CreateFakeNuGetPackage(nugetCacheDir, pkgName, "1.0.0"); + CreateFakeNuGetPackage(_nugetCacheDir!, pkgName, "1.0.0"); var external = new InputExternalTypeMetadata(typeName, pkgName, null); var unionWithExternal = InputFactory.Union( @@ -274,5 +275,35 @@ private static string CreateFakeNuGetPackage( return FakeNuGetPackage.Create( nugetCacheDir, packageName, version, source, referencedAssemblyPaths, dependencies); } + + private static void WriteLocalNuGetConfig(string projectDir, string nugetCacheDir) + { + var nugetConfigPath = Path.Combine(projectDir, "NuGet.Config"); + var normalizedCachePath = nugetCacheDir.Replace("\\", "/"); + var config = $@" + + + + + + + + +"; + + File.WriteAllText(nugetConfigPath, config); + } + + private static void ResetResolverIfInitialized() + { + try + { + ExternalTypeReferenceResolver.Reset(); + } + catch (InvalidOperationException) + { + // CodeModelGenerator may not be initialized yet when this fixture runs in isolation. + } + } } } From 1b80f3c06acdb681dfd9d642b73bd45961722181 Mon Sep 17 00:00:00 2001 From: Chidozie Ononiwu Date: Mon, 20 Jul 2026 14:53:41 -0700 Subject: [PATCH 06/18] Authenticate to DevOps feed in test-step --- eng/emitters/pipelines/templates/steps/test-step.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/eng/emitters/pipelines/templates/steps/test-step.yml b/eng/emitters/pipelines/templates/steps/test-step.yml index 59a2beb5689..1e35605d82a 100644 --- a/eng/emitters/pipelines/templates/steps/test-step.yml +++ b/eng/emitters/pipelines/templates/steps/test-step.yml @@ -53,6 +53,12 @@ steps: - template: /eng/common/pipelines/templates/steps/create-authenticated-npmrc.yml + - ${{ if eq(parameters.LanguageShortName, 'python') }}: + - template: /eng/common/pipelines/templates/steps/auth-dev-feed.yml + + - ${{ if eq(parameters.LanguageShortName, 'java') }}: + - template: /eng/common/pipelines/templates/steps/maven-authenticate.yml + - download: current artifact: ${{ parameters.BuildArtifactName }} displayName: Download build artifacts From a3bee3c85e2acfecc2aa15737ea6c948e798fe8e Mon Sep 17 00:00:00 2001 From: Chidozie Ononiwu Date: Mon, 20 Jul 2026 16:14:39 -0700 Subject: [PATCH 07/18] Ensure nuget restore runs before tests and nuget config is used --- .../templates/steps/auth-dev-feed.yml | 52 +++++++++---------- .../templates/steps/maven-authenticate.yml | 6 +-- .../pipelines/templates/steps/test-step.yml | 4 +- eng/tsp-core/pipelines/templates/install.yml | 2 +- .../eng/scripts/Build-Packages.ps1 | 3 +- .../eng/scripts/Test-Packages.ps1 | 8 ++- packages/typespec-vs/scripts/build.ts | 14 ++++- .../src/Microsoft.TypeSpec.VS.csproj | 2 + 8 files changed, 55 insertions(+), 36 deletions(-) diff --git a/eng/common/pipelines/templates/steps/auth-dev-feed.yml b/eng/common/pipelines/templates/steps/auth-dev-feed.yml index cd8fa23e67e..fc2396c8448 100644 --- a/eng/common/pipelines/templates/steps/auth-dev-feed.yml +++ b/eng/common/pipelines/templates/steps/auth-dev-feed.yml @@ -1,5 +1,5 @@ parameters: - DevFeedName: 'public/azure-sdk-for-python' + DevFeedName: "public/azure-sdk-for-python" EnableTwineAuth: true EnablePipAuth: true EnableUvAuth: true @@ -18,32 +18,32 @@ steps: displayName: Setup DevOpsFeedName - ${{ if eq(parameters.EnableTwineAuth, true) }}: - - task: TwineAuthenticate@0 - displayName: 'Twine Authenticate to feed' - inputs: - artifactFeeds: $(DevFeedName) + - task: TwineAuthenticate@0 + displayName: "Twine Authenticate to feed" + inputs: + artifactFeeds: $(DevFeedName) - ${{ if eq(parameters.EnablePipAuth, true) }}: - - task: PipAuthenticate@1 - displayName: 'Pip Authenticate to feed' - inputs: - artifactFeeds: $(DevFeedName) - onlyAddExtraIndex: false + - task: PipAuthenticate@1 + displayName: "Pip Authenticate to feed" + inputs: + artifactFeeds: $(DevFeedName) + onlyAddExtraIndex: false - ${{ if eq(parameters.EnableUvAuth, true) }}: - - pwsh: | - if ($env:PIP_INDEX_URL) { - Write-Host "Found pip index URL: $($env:PIP_INDEX_URL)" - # UV_DEFAULT_INDEX is the canonical replacement for the deprecated UV_INDEX_URL (uv 0.4.23+). - # PIP_INDEX_URL is set by PipAuthenticate@1 and contains embedded credentials, which uv - # will use for Basic auth against the ADO feed (and its PyPI upstream) per astral-sh/uv#12651. - Write-Host "##vso[task.setvariable variable=UV_DEFAULT_INDEX]$($env:PIP_INDEX_URL)" - # Disable keyring so uv uses the URL-embedded credentials directly. - Write-Host "##vso[task.setvariable variable=UV_KEYRING_PROVIDER]disabled" - } else { - Write-Host "##[warning]PIP_INDEX_URL not set - uv will fall back to public PyPI." - } - # Force any managed Python downloads to go directly to GitHub releases - # rather than the default CDN (releases.astral.sh). - Write-Host "##vso[task.setvariable variable=UV_PYTHON_INSTALL_MIRROR]https://github.com/astral-sh/python-build-standalone/releases/download" - displayName: 'Configure UV Authentication' + - pwsh: | + if ($env:PIP_INDEX_URL) { + Write-Host "Found pip index URL: $($env:PIP_INDEX_URL)" + # UV_DEFAULT_INDEX is the canonical replacement for the deprecated UV_INDEX_URL (uv 0.4.23+). + # PIP_INDEX_URL is set by PipAuthenticate@1 and contains embedded credentials, which uv + # will use for Basic auth against the ADO feed (and its PyPI upstream) per astral-sh/uv#12651. + Write-Host "##vso[task.setvariable variable=UV_DEFAULT_INDEX]$($env:PIP_INDEX_URL)" + # Disable keyring so uv uses the URL-embedded credentials directly. + Write-Host "##vso[task.setvariable variable=UV_KEYRING_PROVIDER]disabled" + } else { + Write-Host "##[warning]PIP_INDEX_URL not set - uv will fall back to public PyPI." + } + # Force any managed Python downloads to go directly to GitHub releases + # rather than the default CDN (releases.astral.sh). + Write-Host "##vso[task.setvariable variable=UV_PYTHON_INSTALL_MIRROR]https://github.com/astral-sh/python-build-standalone/releases/download" + displayName: "Configure UV Authentication" diff --git a/eng/common/pipelines/templates/steps/maven-authenticate.yml b/eng/common/pipelines/templates/steps/maven-authenticate.yml index f03caee204f..1b84e984add 100644 --- a/eng/common/pipelines/templates/steps/maven-authenticate.yml +++ b/eng/common/pipelines/templates/steps/maven-authenticate.yml @@ -7,11 +7,11 @@ steps: $m2Dir = if ($env:USERPROFILE) { "$env:USERPROFILE\.m2" } else { "$HOME/.m2" } New-Item -ItemType Directory -Force -Path $m2Dir | Out-Null Copy-Item -Path "${{ parameters.SourceDirectory }}/eng/settings.xml" -Destination "$m2Dir/settings.xml" - displayName: 'Setup Maven mirror settings' + displayName: "Setup Maven mirror settings" # Authenticate with Azure Artifacts feeds # MavenAuthenticate adds entries to ~/.m2/settings.xml matching mirror id 'azure-sdk-for-java' - task: MavenAuthenticate@0 - displayName: 'Maven Authenticate' + displayName: "Maven Authenticate" inputs: - artifactsFeeds: 'azure-sdk-for-java' + artifactsFeeds: "azure-sdk-for-java" diff --git a/eng/emitters/pipelines/templates/steps/test-step.yml b/eng/emitters/pipelines/templates/steps/test-step.yml index 1e35605d82a..3a5dfb0687e 100644 --- a/eng/emitters/pipelines/templates/steps/test-step.yml +++ b/eng/emitters/pipelines/templates/steps/test-step.yml @@ -54,10 +54,10 @@ steps: - template: /eng/common/pipelines/templates/steps/create-authenticated-npmrc.yml - ${{ if eq(parameters.LanguageShortName, 'python') }}: - - template: /eng/common/pipelines/templates/steps/auth-dev-feed.yml + - template: /eng/common/pipelines/templates/steps/auth-dev-feed.yml - ${{ if eq(parameters.LanguageShortName, 'java') }}: - - template: /eng/common/pipelines/templates/steps/maven-authenticate.yml + - template: /eng/common/pipelines/templates/steps/maven-authenticate.yml - download: current artifact: ${{ parameters.BuildArtifactName }} diff --git a/eng/tsp-core/pipelines/templates/install.yml b/eng/tsp-core/pipelines/templates/install.yml index 7820c3a411a..0f5d4d05ec0 100644 --- a/eng/tsp-core/pipelines/templates/install.yml +++ b/eng/tsp-core/pipelines/templates/install.yml @@ -37,6 +37,6 @@ steps: retryCountOnTaskFailure: 3 - ${{ if parameters.useDotNet }}: - - script: dotnet restore + - script: dotnet restore --configfile "$(Build.SourcesDirectory)/NuGet.Config" displayName: Restore .NET Dependencies workingDirectory: packages/typespec-vs diff --git a/packages/http-client-csharp/eng/scripts/Build-Packages.ps1 b/packages/http-client-csharp/eng/scripts/Build-Packages.ps1 index e606da1c6f5..7f8a2150d1f 100644 --- a/packages/http-client-csharp/eng/scripts/Build-Packages.ps1 +++ b/packages/http-client-csharp/eng/scripts/Build-Packages.ps1 @@ -47,7 +47,8 @@ function Pack-And-Write-Info { ) $versionOption = $BuildNumber ? "/p:Version=$version" : "" - Invoke-LoggedCommand "dotnet pack ./$package/src/$package.csproj $versionOption -c Release -o $outputPath/packages" + $ciNugetAuditArg = $env:TF_BUILD ? "-p:NuGetAudit=false" : "" + Invoke-LoggedCommand "dotnet pack ./$package/src/$package.csproj $versionOption $ciNugetAuditArg -c Release -o $outputPath/packages" Write-PackageInfo -packageName $package -directoryPath "packages/http-client-csharp/generator/$package/src" -version $version } diff --git a/packages/http-client-csharp/eng/scripts/Test-Packages.ps1 b/packages/http-client-csharp/eng/scripts/Test-Packages.ps1 index bb0c24c43fe..82959cca970 100644 --- a/packages/http-client-csharp/eng/scripts/Test-Packages.ps1 +++ b/packages/http-client-csharp/eng/scripts/Test-Packages.ps1 @@ -24,8 +24,14 @@ try { # enforce cop static-analysis rules on the generator sources Invoke-LoggedCommand "./eng/scripts/Invoke-Cop.ps1" -GroupOutput + # Use the repo NuGet.Config explicitly so restore always targets the Azure DevOps feed. + $repoRoot = (Resolve-Path "$packageRoot/../..").Path + $nugetConfigPath = (Join-Path $repoRoot "NuGet.Config") + $ciNugetAuditArg = $env:TF_BUILD ? "-p:NuGetAudit=false" : "" + Invoke-LoggedCommand "dotnet nuget list source --configfile `"$nugetConfigPath`"" -GroupOutput + # test the generator - Invoke-LoggedCommand "dotnet test ./generator" -GroupOutput + Invoke-LoggedCommand "dotnet test ./generator -p:RestoreConfigFile=`"$nugetConfigPath`" $ciNugetAuditArg" -GroupOutput Invoke-LoggedCommand "./eng/scripts/Get-Spector-Coverage.ps1" -GroupOutput } diff --git a/packages/typespec-vs/scripts/build.ts b/packages/typespec-vs/scripts/build.ts index 04d508d2714..34cb07ae94e 100644 --- a/packages/typespec-vs/scripts/build.ts +++ b/packages/typespec-vs/scripts/build.ts @@ -34,7 +34,15 @@ async function main() { if (result.type === "dotnet") { await ensureDotnetVersion({ exitWithSuccessInDevBuilds: true }); await runDotnet( - ["build", "--configuration", "Release", `-p:Version=${version}`, "-clp:NoSummary"], + [ + "build", + "--configuration", + "Release", + `-p:Version=${version}`, + "-clp:NoSummary", + // Restore may fail with NU1900 when vulnerability feed is unavailable. + "-p:NuGetAudit=false", + ], { cwd: pkgRoot, }, @@ -58,7 +66,9 @@ async function buildWithMsbuild(msbuildPath: string, pkgRoot: string, version: s msbuildArgs.push("/restore"); } msbuildArgs.push(join(pkgRoot, "Microsoft.TypeSpec.VS.sln")); - const result = await run(msbuildPath, msbuildArgs, { throwOnNonZeroExit: false }); + const result = await run(msbuildPath, msbuildArgs, { + throwOnNonZeroExit: false, + }); process.exit(result.exitCode); } diff --git a/packages/typespec-vs/src/Microsoft.TypeSpec.VS.csproj b/packages/typespec-vs/src/Microsoft.TypeSpec.VS.csproj index b16fd2ccb28..201dae7155b 100644 --- a/packages/typespec-vs/src/Microsoft.TypeSpec.VS.csproj +++ b/packages/typespec-vs/src/Microsoft.TypeSpec.VS.csproj @@ -10,6 +10,8 @@ all + + false true 42.42.42 From 3490f68224cf553f17b5e15eac25ec20071160f0 Mon Sep 17 00:00:00 2001 From: Chidozie Ononiwu Date: Tue, 21 Jul 2026 12:23:09 -0700 Subject: [PATCH 08/18] Resolve issues raised in PR --- ...th-dev-feed.yml => pypi-auth-dev-feed.yml} | 0 .../pipelines/templates/steps/build-step.yml | 2 +- .../pipelines/templates/steps/test-step.yml | 2 +- eng/tsp-core/pipelines/pr-tools.yml | 2 + eng/tsp-core/pipelines/templates/install.yml | 2 +- NuGet.Config => nuget.config | 0 .../test/GeneratedCodeWorkspaceTests.cs | 1 + .../ExternalTypeReferenceResolverTests.cs | 38 +++++++++---------- .../src/Microsoft.TypeSpec.VS.csproj | 2 - 9 files changed, 25 insertions(+), 24 deletions(-) rename eng/common/pipelines/templates/steps/{auth-dev-feed.yml => pypi-auth-dev-feed.yml} (100%) rename NuGet.Config => nuget.config (100%) diff --git a/eng/common/pipelines/templates/steps/auth-dev-feed.yml b/eng/common/pipelines/templates/steps/pypi-auth-dev-feed.yml similarity index 100% rename from eng/common/pipelines/templates/steps/auth-dev-feed.yml rename to eng/common/pipelines/templates/steps/pypi-auth-dev-feed.yml diff --git a/eng/emitters/pipelines/templates/steps/build-step.yml b/eng/emitters/pipelines/templates/steps/build-step.yml index a0888cd13cb..778ec71ea3d 100644 --- a/eng/emitters/pipelines/templates/steps/build-step.yml +++ b/eng/emitters/pipelines/templates/steps/build-step.yml @@ -61,7 +61,7 @@ steps: - template: /eng/common/pipelines/templates/steps/create-authenticated-npmrc.yml - - template: /eng/common/pipelines/templates/steps/auth-dev-feed.yml + - template: /eng/common/pipelines/templates/steps/pypi-auth-dev-feed.yml - template: /eng/common/pipelines/templates/steps/maven-authenticate.yml diff --git a/eng/emitters/pipelines/templates/steps/test-step.yml b/eng/emitters/pipelines/templates/steps/test-step.yml index 3a5dfb0687e..001db869f2a 100644 --- a/eng/emitters/pipelines/templates/steps/test-step.yml +++ b/eng/emitters/pipelines/templates/steps/test-step.yml @@ -54,7 +54,7 @@ steps: - template: /eng/common/pipelines/templates/steps/create-authenticated-npmrc.yml - ${{ if eq(parameters.LanguageShortName, 'python') }}: - - template: /eng/common/pipelines/templates/steps/auth-dev-feed.yml + - template: /eng/common/pipelines/templates/steps/pypi-auth-dev-feed.yml - ${{ if eq(parameters.LanguageShortName, 'java') }}: - template: /eng/common/pipelines/templates/steps/maven-authenticate.yml diff --git a/eng/tsp-core/pipelines/pr-tools.yml b/eng/tsp-core/pipelines/pr-tools.yml index 371bcd46340..af7efb8d499 100644 --- a/eng/tsp-core/pipelines/pr-tools.yml +++ b/eng/tsp-core/pipelines/pr-tools.yml @@ -80,6 +80,8 @@ extends: displayName: Create TryIt comment dependsOn: tryit steps: + - template: /eng/common/pipelines/templates/steps/create-authenticated-npmrc.yml + - pwsh: | $curlCommand = 'curl -s -u :$(System.AccessToken) "$(System.TeamFoundationCollectionUri)/$(System.TeamProject)/_apis/build/builds/$(Build.BuildId)/artifacts?artifactName=vscode-extension"' $response = Invoke-Expression $curlCommand diff --git a/eng/tsp-core/pipelines/templates/install.yml b/eng/tsp-core/pipelines/templates/install.yml index 0f5d4d05ec0..825b27b1099 100644 --- a/eng/tsp-core/pipelines/templates/install.yml +++ b/eng/tsp-core/pipelines/templates/install.yml @@ -37,6 +37,6 @@ steps: retryCountOnTaskFailure: 3 - ${{ if parameters.useDotNet }}: - - script: dotnet restore --configfile "$(Build.SourcesDirectory)/NuGet.Config" + - script: dotnet restore --configfile "$(Build.SourcesDirectory)/nuget.config" displayName: Restore .NET Dependencies workingDirectory: packages/typespec-vs diff --git a/NuGet.Config b/nuget.config similarity index 100% rename from NuGet.Config rename to nuget.config diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/GeneratedCodeWorkspaceTests.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/GeneratedCodeWorkspaceTests.cs index 66ac281be15..b4eaa0446c3 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/GeneratedCodeWorkspaceTests.cs +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/GeneratedCodeWorkspaceTests.cs @@ -14,6 +14,7 @@ namespace Microsoft.TypeSpec.Generator.Tests { + [NonParallelizable] public class GeneratedCodeWorkspaceTests { private const string EvaluatedFrameworkTestCategory = "WithEvaluatedFrameworkValue"; diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Utilities/ExternalTypeReferenceResolverTests.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Utilities/ExternalTypeReferenceResolverTests.cs index c722e206285..b94a50c5836 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Utilities/ExternalTypeReferenceResolverTests.cs +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Utilities/ExternalTypeReferenceResolverTests.cs @@ -276,11 +276,11 @@ private static string CreateFakeNuGetPackage( nugetCacheDir, packageName, version, source, referencedAssemblyPaths, dependencies); } - private static void WriteLocalNuGetConfig(string projectDir, string nugetCacheDir) - { - var nugetConfigPath = Path.Combine(projectDir, "NuGet.Config"); - var normalizedCachePath = nugetCacheDir.Replace("\\", "/"); - var config = $@" + private static void WriteLocalNuGetConfig(string projectDir, string nugetCacheDir) + { + var nugetConfigPath = Path.Combine(projectDir, "NuGet.Config"); + var normalizedCachePath = nugetCacheDir.Replace("\\", "/"); + var config = $@" @@ -291,19 +291,19 @@ private static void WriteLocalNuGetConfig(string projectDir, string nugetCacheDi "; - File.WriteAllText(nugetConfigPath, config); - } - - private static void ResetResolverIfInitialized() - { - try - { - ExternalTypeReferenceResolver.Reset(); - } - catch (InvalidOperationException) - { - // CodeModelGenerator may not be initialized yet when this fixture runs in isolation. - } - } + File.WriteAllText(nugetConfigPath, config); + } + + private static void ResetResolverIfInitialized() + { + try + { + ExternalTypeReferenceResolver.Reset(); + } + catch (InvalidOperationException) + { + // CodeModelGenerator may not be initialized yet when this fixture runs in isolation. + } + } } } diff --git a/packages/typespec-vs/src/Microsoft.TypeSpec.VS.csproj b/packages/typespec-vs/src/Microsoft.TypeSpec.VS.csproj index 201dae7155b..b16fd2ccb28 100644 --- a/packages/typespec-vs/src/Microsoft.TypeSpec.VS.csproj +++ b/packages/typespec-vs/src/Microsoft.TypeSpec.VS.csproj @@ -10,8 +10,6 @@ all - - false true 42.42.42 From 7beec191f019031bbff6e0c0a4311e728491f185 Mon Sep 17 00:00:00 2001 From: Chidozie Ononiwu Date: Tue, 21 Jul 2026 13:10:14 -0700 Subject: [PATCH 09/18] Rename NuGet.Config to nuget.config --- packages/http-client-csharp/eng/scripts/Test-Packages.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/http-client-csharp/eng/scripts/Test-Packages.ps1 b/packages/http-client-csharp/eng/scripts/Test-Packages.ps1 index 82959cca970..afdeb8cd7a2 100644 --- a/packages/http-client-csharp/eng/scripts/Test-Packages.ps1 +++ b/packages/http-client-csharp/eng/scripts/Test-Packages.ps1 @@ -26,7 +26,7 @@ try { # Use the repo NuGet.Config explicitly so restore always targets the Azure DevOps feed. $repoRoot = (Resolve-Path "$packageRoot/../..").Path - $nugetConfigPath = (Join-Path $repoRoot "NuGet.Config") + $nugetConfigPath = (Join-Path $repoRoot "nuget.config") $ciNugetAuditArg = $env:TF_BUILD ? "-p:NuGetAudit=false" : "" Invoke-LoggedCommand "dotnet nuget list source --configfile `"$nugetConfigPath`"" -GroupOutput From ee26ac8761ad6c2856b508f0ef2902bc85e41a63 Mon Sep 17 00:00:00 2001 From: Chidozie Ononiwu Date: Tue, 21 Jul 2026 20:03:09 -0700 Subject: [PATCH 10/18] work to get test passing for csharp --- .../eng/scripts/Test-Packages.ps1 | 16 ++++++++++++++- .../src/StartUp/GeneratorHandler.cs | 14 +++++++++++++ .../test/StartUp/GeneratorHandlerTests.cs | 20 +++++++++++++++++-- 3 files changed, 47 insertions(+), 3 deletions(-) diff --git a/packages/http-client-csharp/eng/scripts/Test-Packages.ps1 b/packages/http-client-csharp/eng/scripts/Test-Packages.ps1 index afdeb8cd7a2..5e39e83a941 100644 --- a/packages/http-client-csharp/eng/scripts/Test-Packages.ps1 +++ b/packages/http-client-csharp/eng/scripts/Test-Packages.ps1 @@ -31,7 +31,21 @@ try { Invoke-LoggedCommand "dotnet nuget list source --configfile `"$nugetConfigPath`"" -GroupOutput # test the generator - Invoke-LoggedCommand "dotnet test ./generator -p:RestoreConfigFile=`"$nugetConfigPath`" $ciNugetAuditArg" -GroupOutput + # Ensure child dotnet processes spawned from tests use the same restore/audit settings. + $previousRestoreConfigFile = $env:RestoreConfigFile + $previousNuGetAudit = $env:NuGetAudit + try { + $env:RestoreConfigFile = $nugetConfigPath + if ($env:TF_BUILD) { + $env:NuGetAudit = "false" + } + + Invoke-LoggedCommand "dotnet test ./generator -p:RestoreConfigFile=`"$nugetConfigPath`" $ciNugetAuditArg" -GroupOutput + } + finally { + $env:RestoreConfigFile = $previousRestoreConfigFile + $env:NuGetAudit = $previousNuGetAudit + } Invoke-LoggedCommand "./eng/scripts/Get-Spector-Coverage.ps1" -GroupOutput } diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/StartUp/GeneratorHandler.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/StartUp/GeneratorHandler.cs index 5552002e20f..186531e1bda 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/StartUp/GeneratorHandler.cs +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/StartUp/GeneratorHandler.cs @@ -304,6 +304,8 @@ internal static string GetPackageDirectory(string rootDirectory, string package) process.StartInfo.ArgumentList.Add("Release"); process.StartInfo.ArgumentList.Add($"-p:BaseOutputPath={binDirectory}"); process.StartInfo.ArgumentList.Add($"-p:BaseIntermediateOutputPath={objDirectory}"); + AppendMsBuildPropertyIfSet(process.StartInfo.ArgumentList, "RestoreConfigFile", "RestoreConfigFile"); + AppendMsBuildPropertyIfSet(process.StartInfo.ArgumentList, "NuGetAudit", "NuGetAudit"); process.Start(); // Read both streams to avoid deadlocks. 'dotnet build' writes build/compiler @@ -346,6 +348,18 @@ internal static (string StandardOutput, string StandardError) ReadProcessOutput( return (stdoutTask.Result, stderrTask.Result); } + private static void AppendMsBuildPropertyIfSet( + System.Collections.ObjectModel.Collection argumentList, + string envVarName, + string propertyName) + { + var value = Environment.GetEnvironmentVariable(envVarName, EnvironmentVariableTarget.Process); + if (!string.IsNullOrWhiteSpace(value)) + { + argumentList.Add($"-p:{propertyName}={value}"); + } + } + /// /// Creates a unique, process-isolated directory to hold a plugin build's 'bin' and 'obj' /// output. The directory is keyed on the process id and a GUID so that concurrent diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/StartUp/GeneratorHandlerTests.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/StartUp/GeneratorHandlerTests.cs index 3f21af6cd66..a397a7e1657 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/StartUp/GeneratorHandlerTests.cs +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/StartUp/GeneratorHandlerTests.cs @@ -251,7 +251,7 @@ public void ReadProcessOutput_DrainsStandardOutputAndErrorConcurrently() Console.Out.Write("stdout"); """); - using var buildProcess = Process.Start(new ProcessStartInfo("dotnet") + var buildStartInfo = new ProcessStartInfo("dotnet") { UseShellExecute = false, ArgumentList = @@ -264,7 +264,11 @@ public void ReadProcessOutput_DrainsStandardOutputAndErrorConcurrently() "--verbosity", "quiet" } - }); + }; + AppendMsBuildPropertyIfSet(buildStartInfo.ArgumentList, "RestoreConfigFile", "RestoreConfigFile"); + AppendMsBuildPropertyIfSet(buildStartInfo.ArgumentList, "NuGetAudit", "NuGetAudit"); + + using var buildProcess = Process.Start(buildStartInfo); Assert.IsNotNull(buildProcess); buildProcess!.WaitForExit(); Assert.AreEqual(0, buildProcess.ExitCode); @@ -940,6 +944,18 @@ namespace Isolated { public class Dummy { } }"); "; + private static void AppendMsBuildPropertyIfSet( + System.Collections.ObjectModel.Collection argumentList, + string envVarName, + string propertyName) + { + var value = Environment.GetEnvironmentVariable(envVarName, EnvironmentVariableTarget.Process); + if (!string.IsNullOrWhiteSpace(value)) + { + argumentList.Add($"-p:{propertyName}={value}"); + } + } + /// Creates a unique temp directory and removes it on dispose. private sealed class TempDirectory : IDisposable { From e09543c32ad109cbc138eda88ae1004010c55e3a Mon Sep 17 00:00:00 2001 From: Chidozie Ononiwu Date: Wed, 22 Jul 2026 16:12:36 -0700 Subject: [PATCH 11/18] Update nuget.config path --- nuget.config => eng/nuget.config | 0 eng/tsp-core/pipelines/templates/install.yml | 2 +- packages/http-client-csharp/eng/scripts/Test-Packages.ps1 | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) rename nuget.config => eng/nuget.config (100%) diff --git a/nuget.config b/eng/nuget.config similarity index 100% rename from nuget.config rename to eng/nuget.config diff --git a/eng/tsp-core/pipelines/templates/install.yml b/eng/tsp-core/pipelines/templates/install.yml index 825b27b1099..07a194615c9 100644 --- a/eng/tsp-core/pipelines/templates/install.yml +++ b/eng/tsp-core/pipelines/templates/install.yml @@ -37,6 +37,6 @@ steps: retryCountOnTaskFailure: 3 - ${{ if parameters.useDotNet }}: - - script: dotnet restore --configfile "$(Build.SourcesDirectory)/nuget.config" + - script: dotnet restore --configfile "$(Build.SourcesDirectory)/eng/nuget.config" displayName: Restore .NET Dependencies workingDirectory: packages/typespec-vs diff --git a/packages/http-client-csharp/eng/scripts/Test-Packages.ps1 b/packages/http-client-csharp/eng/scripts/Test-Packages.ps1 index 5e39e83a941..26f1e8e2a6f 100644 --- a/packages/http-client-csharp/eng/scripts/Test-Packages.ps1 +++ b/packages/http-client-csharp/eng/scripts/Test-Packages.ps1 @@ -26,7 +26,7 @@ try { # Use the repo NuGet.Config explicitly so restore always targets the Azure DevOps feed. $repoRoot = (Resolve-Path "$packageRoot/../..").Path - $nugetConfigPath = (Join-Path $repoRoot "nuget.config") + $nugetConfigPath = (Join-Path $repoRoot "eng/nuget.config") $ciNugetAuditArg = $env:TF_BUILD ? "-p:NuGetAudit=false" : "" Invoke-LoggedCommand "dotnet nuget list source --configfile `"$nugetConfigPath`"" -GroupOutput From 30c8cfd588f9766ab1013bb105dd442e6c1a114f Mon Sep 17 00:00:00 2001 From: Chidozie Ononiwu Date: Wed, 22 Jul 2026 16:39:47 -0700 Subject: [PATCH 12/18] Enforce CFSClean for Network Isolation --- .../eng/scripts/Build-Packages.ps1 | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/packages/http-client-csharp/eng/scripts/Build-Packages.ps1 b/packages/http-client-csharp/eng/scripts/Build-Packages.ps1 index 7f8a2150d1f..69c9e98c52d 100644 --- a/packages/http-client-csharp/eng/scripts/Build-Packages.ps1 +++ b/packages/http-client-csharp/eng/scripts/Build-Packages.ps1 @@ -48,7 +48,9 @@ function Pack-And-Write-Info { $versionOption = $BuildNumber ? "/p:Version=$version" : "" $ciNugetAuditArg = $env:TF_BUILD ? "-p:NuGetAudit=false" : "" - Invoke-LoggedCommand "dotnet pack ./$package/src/$package.csproj $versionOption $ciNugetAuditArg -c Release -o $outputPath/packages" + $repoRoot = (Resolve-Path "$packageRoot/../..").Path + $nugetConfigPath = (Join-Path $repoRoot "eng/nuget.config") + Invoke-LoggedCommand "dotnet pack ./$package/src/$package.csproj $versionOption -p:RestoreConfigFile=`"$nugetConfigPath`" $ciNugetAuditArg -c Release -o $outputPath/packages" Write-PackageInfo -packageName $package -directoryPath "packages/http-client-csharp/generator/$package/src" -version $version } @@ -110,7 +112,24 @@ Push-Location "$packageRoot" try { Write-Host "Working in $PWD" - Invoke-LoggedCommand "npm run build" -GroupOutput + # Ensure nested dotnet builds (invoked via `npm run build:generator`) use the repo NuGet.Config + # so restore always targets the Azure DevOps feed instead of nuget.org. + $repoRoot = (Resolve-Path "$packageRoot/../..").Path + $nugetConfigPath = (Join-Path $repoRoot "eng/nuget.config") + $previousRestoreConfigFile = $env:RestoreConfigFile + $previousNuGetAudit = $env:NuGetAudit + try { + $env:RestoreConfigFile = $nugetConfigPath + if ($env:TF_BUILD) { + $env:NuGetAudit = "false" + } + + Invoke-LoggedCommand "npm run build" -GroupOutput + } + finally { + $env:RestoreConfigFile = $previousRestoreConfigFile + $env:NuGetAudit = $previousNuGetAudit + } Copy-Item "$packageRoot/emitter/temp/*.api.json" -Destination "$outputPath/packages" From 27de14df8ee2ad495a1887deb5fd2e0156d7ec07 Mon Sep 17 00:00:00 2001 From: Chidozie Ononiwu Date: Thu, 6 Aug 2026 18:11:22 -0700 Subject: [PATCH 13/18] Add NugetAuthenticate --- eng/emitters/pipelines/templates/steps/test-step.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/eng/emitters/pipelines/templates/steps/test-step.yml b/eng/emitters/pipelines/templates/steps/test-step.yml index 001db869f2a..145e301b5fd 100644 --- a/eng/emitters/pipelines/templates/steps/test-step.yml +++ b/eng/emitters/pipelines/templates/steps/test-step.yml @@ -53,6 +53,9 @@ steps: - template: /eng/common/pipelines/templates/steps/create-authenticated-npmrc.yml + - ${{ if eq(parameters.LanguageShortName, 'csharp') }}: + - task: NuGetAuthenticate@1 + - ${{ if eq(parameters.LanguageShortName, 'python') }}: - template: /eng/common/pipelines/templates/steps/pypi-auth-dev-feed.yml From d592b0bcace0b31dd25ebea0d29621f2d728ca2f Mon Sep 17 00:00:00 2001 From: Chidozie Ononiwu Date: Thu, 6 Aug 2026 19:14:10 -0700 Subject: [PATCH 14/18] Order nugetConfigPath --- .../eng/scripts/Test-Packages.ps1 | 38 +++++++++---------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/packages/http-client-csharp/eng/scripts/Test-Packages.ps1 b/packages/http-client-csharp/eng/scripts/Test-Packages.ps1 index 26f1e8e2a6f..cbbe1b10798 100644 --- a/packages/http-client-csharp/eng/scripts/Test-Packages.ps1 +++ b/packages/http-client-csharp/eng/scripts/Test-Packages.ps1 @@ -16,7 +16,21 @@ Push-Location $packageRoot try { if ($UnitTests) { Push-Location "$packageRoot" + # Ensure all dotnet processes, including those spawned by npm scripts and tests, + # restore through the repository's Azure DevOps feed instead of nuget.org. + $repoRoot = (Resolve-Path "$packageRoot/../..").Path + $nugetConfigPath = (Join-Path $repoRoot "eng/nuget.config") + $ciNugetAuditArg = $env:TF_BUILD ? "-p:NuGetAudit=false" : "" + $previousRestoreConfigFile = $env:RestoreConfigFile + $previousNuGetAudit = $env:NuGetAudit try { + $env:RestoreConfigFile = $nugetConfigPath + if ($env:TF_BUILD) { + $env:NuGetAudit = "false" + } + + Invoke-LoggedCommand "dotnet nuget list source --configfile `"$nugetConfigPath`"" -GroupOutput + # test the emitter Invoke-LoggedCommand "npm run build" -GroupOutput Invoke-LoggedCommand "npm run test:emitter" -GroupOutput @@ -24,32 +38,14 @@ try { # enforce cop static-analysis rules on the generator sources Invoke-LoggedCommand "./eng/scripts/Invoke-Cop.ps1" -GroupOutput - # Use the repo NuGet.Config explicitly so restore always targets the Azure DevOps feed. - $repoRoot = (Resolve-Path "$packageRoot/../..").Path - $nugetConfigPath = (Join-Path $repoRoot "eng/nuget.config") - $ciNugetAuditArg = $env:TF_BUILD ? "-p:NuGetAudit=false" : "" - Invoke-LoggedCommand "dotnet nuget list source --configfile `"$nugetConfigPath`"" -GroupOutput - # test the generator - # Ensure child dotnet processes spawned from tests use the same restore/audit settings. - $previousRestoreConfigFile = $env:RestoreConfigFile - $previousNuGetAudit = $env:NuGetAudit - try { - $env:RestoreConfigFile = $nugetConfigPath - if ($env:TF_BUILD) { - $env:NuGetAudit = "false" - } - - Invoke-LoggedCommand "dotnet test ./generator -p:RestoreConfigFile=`"$nugetConfigPath`" $ciNugetAuditArg" -GroupOutput - } - finally { - $env:RestoreConfigFile = $previousRestoreConfigFile - $env:NuGetAudit = $previousNuGetAudit - } + Invoke-LoggedCommand "dotnet test ./generator -p:RestoreConfigFile=`"$nugetConfigPath`" $ciNugetAuditArg" -GroupOutput Invoke-LoggedCommand "./eng/scripts/Get-Spector-Coverage.ps1" -GroupOutput } finally { + $env:RestoreConfigFile = $previousRestoreConfigFile + $env:NuGetAudit = $previousNuGetAudit Pop-Location } } From 70e5cfe748c6eb60a6f209624777ccd9f1c8be50 Mon Sep 17 00:00:00 2001 From: Chidozie Ononiwu Date: Fri, 7 Aug 2026 08:51:25 -0700 Subject: [PATCH 15/18] Make package feed auth language dependent --- .../pipelines/templates/steps/build-step.yml | 18 ++++++++++++------ .../pipelines/templates/steps/test-step.yml | 9 +++++---- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/eng/emitters/pipelines/templates/steps/build-step.yml b/eng/emitters/pipelines/templates/steps/build-step.yml index 778ec71ea3d..c86494b90e1 100644 --- a/eng/emitters/pipelines/templates/steps/build-step.yml +++ b/eng/emitters/pipelines/templates/steps/build-step.yml @@ -61,9 +61,14 @@ steps: - template: /eng/common/pipelines/templates/steps/create-authenticated-npmrc.yml - - template: /eng/common/pipelines/templates/steps/pypi-auth-dev-feed.yml + - ${{ if eq(parameters.LanguageShortName, 'csharp') }}: + - task: NuGetAuthenticate@1 - - template: /eng/common/pipelines/templates/steps/maven-authenticate.yml + - ${{ if eq(parameters.LanguageShortName, 'python') }}: + - template: /eng/common/pipelines/templates/steps/pypi-auth-dev-feed.yml + + - ${{ if eq(parameters.LanguageShortName, 'java') }}: + - template: /eng/common/pipelines/templates/steps/maven-authenticate.yml - task: NodeTool@0 displayName: Install Node.js @@ -72,10 +77,11 @@ steps: versionSpec: ${{ parameters.NodeVersion }} checkLatest: true - - task: UsePythonVersion@0 - displayName: "Use Python ${{ parameters.PythonVersion }}" - inputs: - versionSpec: ${{ parameters.PythonVersion }} + - ${{ if eq(parameters.LanguageShortName, 'python') }}: + - task: UsePythonVersion@0 + displayName: "Use Python ${{ parameters.PythonVersion }}" + inputs: + versionSpec: ${{ parameters.PythonVersion }} - ${{ parameters.AdditionalInitializeSteps }} diff --git a/eng/emitters/pipelines/templates/steps/test-step.yml b/eng/emitters/pipelines/templates/steps/test-step.yml index 145e301b5fd..b7ca2b5a14e 100644 --- a/eng/emitters/pipelines/templates/steps/test-step.yml +++ b/eng/emitters/pipelines/templates/steps/test-step.yml @@ -73,10 +73,11 @@ steps: versionSpec: ${{ parameters.NodeVersion }} checkLatest: true - - task: UsePythonVersion@0 - displayName: "Use Python ${{ parameters.PythonVersion }}" - inputs: - versionSpec: ${{ parameters.PythonVersion }} + - ${{ if eq(parameters.LanguageShortName, 'python') }}: + - task: UsePythonVersion@0 + displayName: "Use Python ${{ parameters.PythonVersion }}" + inputs: + versionSpec: ${{ parameters.PythonVersion }} - ${{ parameters.AdditionalInitializeSteps }} From cfda75795bac255b6926fb8b309d586ec587e43c Mon Sep 17 00:00:00 2001 From: Chidozie Ononiwu Date: Fri, 7 Aug 2026 11:21:59 -0700 Subject: [PATCH 16/18] Fix failures in CSharp and Python Regen test --- cspell.yaml | 1 + .../pipelines/templates/steps/build-step.yml | 6 ++-- .../eng/scripts/Test-Packages.ps1 | 28 +++++++++---------- packages/http-client-python/tests/tox.ini | 6 ++++ 4 files changed, 24 insertions(+), 17 deletions(-) diff --git a/cspell.yaml b/cspell.yaml index 4fdbe6d4b2f..fce7a455653 100644 --- a/cspell.yaml +++ b/cspell.yaml @@ -229,6 +229,7 @@ words: - pylint - pylintrc - pyodide + - pypi - pyproject - pyright - pyrightconfig diff --git a/eng/emitters/pipelines/templates/steps/build-step.yml b/eng/emitters/pipelines/templates/steps/build-step.yml index c86494b90e1..580889faae7 100644 --- a/eng/emitters/pipelines/templates/steps/build-step.yml +++ b/eng/emitters/pipelines/templates/steps/build-step.yml @@ -62,13 +62,13 @@ steps: - template: /eng/common/pipelines/templates/steps/create-authenticated-npmrc.yml - ${{ if eq(parameters.LanguageShortName, 'csharp') }}: - - task: NuGetAuthenticate@1 + - task: NuGetAuthenticate@1 - ${{ if eq(parameters.LanguageShortName, 'python') }}: - - template: /eng/common/pipelines/templates/steps/pypi-auth-dev-feed.yml + - template: /eng/common/pipelines/templates/steps/pypi-auth-dev-feed.yml - ${{ if eq(parameters.LanguageShortName, 'java') }}: - - template: /eng/common/pipelines/templates/steps/maven-authenticate.yml + - template: /eng/common/pipelines/templates/steps/maven-authenticate.yml - task: NodeTool@0 displayName: Install Node.js diff --git a/packages/http-client-csharp/eng/scripts/Test-Packages.ps1 b/packages/http-client-csharp/eng/scripts/Test-Packages.ps1 index cbbe1b10798..4a33a3081ef 100644 --- a/packages/http-client-csharp/eng/scripts/Test-Packages.ps1 +++ b/packages/http-client-csharp/eng/scripts/Test-Packages.ps1 @@ -13,22 +13,22 @@ $packageRoot = (Resolve-Path "$PSScriptRoot/../..").Path.Replace('\', '/') Set-ConsoleEncoding Push-Location $packageRoot +$repoRoot = (Resolve-Path "$packageRoot/../..").Path +$nugetConfigPath = (Join-Path $repoRoot "eng/nuget.config") +$ciNugetAuditArg = $env:TF_BUILD ? "-p:NuGetAudit=false" : "" +$previousRestoreConfigFile = $env:RestoreConfigFile +$previousNuGetAudit = $env:NuGetAudit try { + # Ensure all dotnet processes, including those spawned by npm scripts and generation, + # restore through the repository's Azure DevOps feed instead of nuget.org. + $env:RestoreConfigFile = $nugetConfigPath + if ($env:TF_BUILD) { + $env:NuGetAudit = "false" + } + if ($UnitTests) { Push-Location "$packageRoot" - # Ensure all dotnet processes, including those spawned by npm scripts and tests, - # restore through the repository's Azure DevOps feed instead of nuget.org. - $repoRoot = (Resolve-Path "$packageRoot/../..").Path - $nugetConfigPath = (Join-Path $repoRoot "eng/nuget.config") - $ciNugetAuditArg = $env:TF_BUILD ? "-p:NuGetAudit=false" : "" - $previousRestoreConfigFile = $env:RestoreConfigFile - $previousNuGetAudit = $env:NuGetAudit try { - $env:RestoreConfigFile = $nugetConfigPath - if ($env:TF_BUILD) { - $env:NuGetAudit = "false" - } - Invoke-LoggedCommand "dotnet nuget list source --configfile `"$nugetConfigPath`"" -GroupOutput # test the emitter @@ -44,8 +44,6 @@ try { Invoke-LoggedCommand "./eng/scripts/Get-Spector-Coverage.ps1" -GroupOutput } finally { - $env:RestoreConfigFile = $previousRestoreConfigFile - $env:NuGetAudit = $previousNuGetAudit Pop-Location } } @@ -80,5 +78,7 @@ try { } } finally { + $env:RestoreConfigFile = $previousRestoreConfigFile + $env:NuGetAudit = $previousNuGetAudit Pop-Location } diff --git a/packages/http-client-python/tests/tox.ini b/packages/http-client-python/tests/tox.ini index b661dd5afcd..29dde03686a 100644 --- a/packages/http-client-python/tests/tox.ini +++ b/packages/http-client-python/tests/tox.ini @@ -12,6 +12,12 @@ setenv = FLAVOR = {envname} passenv = FOLDER + PIP_INDEX_URL + PIP_EXTRA_INDEX_URL + UV_DEFAULT_INDEX + UV_INDEX_URL + UV_KEYRING_PROVIDER + UV_PYTHON_INSTALL_MIRROR # ============================================================================= # Test environments From 2755d0280ecf2134f3383f0746ba948404aecc38 Mon Sep 17 00:00:00 2001 From: Chidozie Ononiwu Date: Fri, 7 Aug 2026 14:39:57 -0700 Subject: [PATCH 17/18] Document changes with chronus --- .chronus/changes/disable-vs-build-nuget-audit-2026-8-7.md | 7 +++++++ .../forward-python-package-index-environment-2026-8-7.md | 7 +++++++ 2 files changed, 14 insertions(+) create mode 100644 .chronus/changes/disable-vs-build-nuget-audit-2026-8-7.md create mode 100644 .chronus/changes/forward-python-package-index-environment-2026-8-7.md diff --git a/.chronus/changes/disable-vs-build-nuget-audit-2026-8-7.md b/.chronus/changes/disable-vs-build-nuget-audit-2026-8-7.md new file mode 100644 index 00000000000..271c3071fae --- /dev/null +++ b/.chronus/changes/disable-vs-build-nuget-audit-2026-8-7.md @@ -0,0 +1,7 @@ +--- +changeKind: fix +packages: + - "typespec-vs" +--- + +Disable NuGet package auditing during cross-platform Visual Studio extension builds so restores do not fail when the vulnerability feed is unavailable. diff --git a/.chronus/changes/forward-python-package-index-environment-2026-8-7.md b/.chronus/changes/forward-python-package-index-environment-2026-8-7.md new file mode 100644 index 00000000000..1bca0d34314 --- /dev/null +++ b/.chronus/changes/forward-python-package-index-environment-2026-8-7.md @@ -0,0 +1,7 @@ +--- +changeKind: fix +packages: + - "@typespec/http-client-python" +--- + +Forward package index and Python mirror environment variables to tox test environments so tests can install dependencies from configured feeds. From fe1b95c06487d31291ffa70dcf3acaa70e4dde8e Mon Sep 17 00:00:00 2001 From: Chidozie Ononiwu Date: Tue, 11 Aug 2026 14:42:34 -0700 Subject: [PATCH 18/18] Remove AppendMsBuildPropertyIfSet helpers --- .../src/StartUp/GeneratorHandler.cs | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/StartUp/GeneratorHandler.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/StartUp/GeneratorHandler.cs index 186531e1bda..5552002e20f 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/StartUp/GeneratorHandler.cs +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/StartUp/GeneratorHandler.cs @@ -304,8 +304,6 @@ internal static string GetPackageDirectory(string rootDirectory, string package) process.StartInfo.ArgumentList.Add("Release"); process.StartInfo.ArgumentList.Add($"-p:BaseOutputPath={binDirectory}"); process.StartInfo.ArgumentList.Add($"-p:BaseIntermediateOutputPath={objDirectory}"); - AppendMsBuildPropertyIfSet(process.StartInfo.ArgumentList, "RestoreConfigFile", "RestoreConfigFile"); - AppendMsBuildPropertyIfSet(process.StartInfo.ArgumentList, "NuGetAudit", "NuGetAudit"); process.Start(); // Read both streams to avoid deadlocks. 'dotnet build' writes build/compiler @@ -348,18 +346,6 @@ internal static (string StandardOutput, string StandardError) ReadProcessOutput( return (stdoutTask.Result, stderrTask.Result); } - private static void AppendMsBuildPropertyIfSet( - System.Collections.ObjectModel.Collection argumentList, - string envVarName, - string propertyName) - { - var value = Environment.GetEnvironmentVariable(envVarName, EnvironmentVariableTarget.Process); - if (!string.IsNullOrWhiteSpace(value)) - { - argumentList.Add($"-p:{propertyName}={value}"); - } - } - /// /// Creates a unique, process-isolated directory to hold a plugin build's 'bin' and 'obj' /// output. The directory is keyed on the process id and a GUID so that concurrent