From 4e1d1331198ae8bab78f3d53b3aaabefdf799864 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Tue, 3 Aug 2021 16:36:07 -0700 Subject: [PATCH 1/3] Use the repo-local NuGet.config with GetReferenceAssemblies so we can use pre-release ref packs reliably. --- .../DllImportGenerator.UnitTests/TestUtils.cs | 24 ++++++++++++++++++- eng/Versions.props | 2 +- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/DllImportGenerator/DllImportGenerator.UnitTests/TestUtils.cs b/DllImportGenerator/DllImportGenerator.UnitTests/TestUtils.cs index 995c2f0450f1..fdb1f0c7fcf0 100644 --- a/DllImportGenerator/DllImportGenerator.UnitTests/TestUtils.cs +++ b/DllImportGenerator/DllImportGenerator.UnitTests/TestUtils.cs @@ -2,8 +2,10 @@ using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.Testing; +using System; using System.Collections.Generic; using System.Collections.Immutable; +using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; @@ -16,6 +18,25 @@ namespace DllImportGenerator.UnitTests { internal static class TestUtils { + private static string NuGetConfigPath { get; } = FindRepoNuGetConfig(); + + private static string FindRepoNuGetConfig() + { + ReadOnlySpan assemblyLocation = typeof(TestUtils).Assembly.Location; + for (ReadOnlySpan directory = Path.GetDirectoryName(assemblyLocation); !directory.IsEmpty; directory = Path.GetDirectoryName(directory)) + { + string nugetConfigPath = Path.Join(directory, "NuGet.config"); + if (File.Exists(nugetConfigPath)) + { + return nugetConfigPath; + } + } + + Debug.Assert(false, "This repo should always contain a NuGet.config at the repo root."); + + return string.Empty; + } + /// /// Assert the pre-srouce generator compilation has only /// the expected failure diagnostics. @@ -96,7 +117,8 @@ public static (ReferenceAssemblies, MetadataReference) GetReferenceAssemblies() new PackageIdentity( "Microsoft.NETCore.App.Ref", "6.0.0-preview.6.21317.4"), - Path.Combine("ref", "net6.0")); + Path.Combine("ref", "net6.0")) + .WithNuGetConfigFilePath(NuGetConfigPath); // Include the assembly containing the new attribute and all of its references. // [TODO] Remove once the attribute has been added to the BCL diff --git a/eng/Versions.props b/eng/Versions.props index cd3c8ca95a31..fc425df2da3a 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -20,7 +20,7 @@ 2.4.3 3.10.0-3.21229.26 - 1.0.1-beta1.20478.1 + 1.1.0 3.3.3-beta1.21268.3 2.0.0-beta1.21118.1 From c1bd1ccf78cfc5c41c81961520f6d9a087c5e56d Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Fri, 6 Aug 2021 15:43:31 -0700 Subject: [PATCH 2/3] Copy NuGet.config to output path instead of searching up to the repo root. --- .../DllImportGenerator.UnitTests.csproj | 4 ++++ .../DllImportGenerator.UnitTests/TestUtils.cs | 21 +------------------ 2 files changed, 5 insertions(+), 20 deletions(-) diff --git a/DllImportGenerator/DllImportGenerator.UnitTests/DllImportGenerator.UnitTests.csproj b/DllImportGenerator/DllImportGenerator.UnitTests/DllImportGenerator.UnitTests.csproj index 7fd03c53f8c1..1ebce78dadc5 100644 --- a/DllImportGenerator/DllImportGenerator.UnitTests/DllImportGenerator.UnitTests.csproj +++ b/DllImportGenerator/DllImportGenerator.UnitTests/DllImportGenerator.UnitTests.csproj @@ -26,4 +26,8 @@ + + + + diff --git a/DllImportGenerator/DllImportGenerator.UnitTests/TestUtils.cs b/DllImportGenerator/DllImportGenerator.UnitTests/TestUtils.cs index fdb1f0c7fcf0..2a0c5af8395f 100644 --- a/DllImportGenerator/DllImportGenerator.UnitTests/TestUtils.cs +++ b/DllImportGenerator/DllImportGenerator.UnitTests/TestUtils.cs @@ -18,25 +18,6 @@ namespace DllImportGenerator.UnitTests { internal static class TestUtils { - private static string NuGetConfigPath { get; } = FindRepoNuGetConfig(); - - private static string FindRepoNuGetConfig() - { - ReadOnlySpan assemblyLocation = typeof(TestUtils).Assembly.Location; - for (ReadOnlySpan directory = Path.GetDirectoryName(assemblyLocation); !directory.IsEmpty; directory = Path.GetDirectoryName(directory)) - { - string nugetConfigPath = Path.Join(directory, "NuGet.config"); - if (File.Exists(nugetConfigPath)) - { - return nugetConfigPath; - } - } - - Debug.Assert(false, "This repo should always contain a NuGet.config at the repo root."); - - return string.Empty; - } - /// /// Assert the pre-srouce generator compilation has only /// the expected failure diagnostics. @@ -118,7 +99,7 @@ public static (ReferenceAssemblies, MetadataReference) GetReferenceAssemblies() "Microsoft.NETCore.App.Ref", "6.0.0-preview.6.21317.4"), Path.Combine("ref", "net6.0")) - .WithNuGetConfigFilePath(NuGetConfigPath); + .WithNuGetConfigFilePath(Path.Combine(Path.GetDirectoryName(typeof(TestUtils).Assembly.Location)!, "NuGet.config")); // Include the assembly containing the new attribute and all of its references. // [TODO] Remove once the attribute has been added to the BCL From 098065c5b372089d5869103c6b6e1e03fa50c6be Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Fri, 6 Aug 2021 16:10:15 -0700 Subject: [PATCH 3/3] Update DllImportGenerator/DllImportGenerator.UnitTests/TestUtils.cs --- DllImportGenerator/DllImportGenerator.UnitTests/TestUtils.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/DllImportGenerator/DllImportGenerator.UnitTests/TestUtils.cs b/DllImportGenerator/DllImportGenerator.UnitTests/TestUtils.cs index 2a0c5af8395f..fd49c82ccf91 100644 --- a/DllImportGenerator/DllImportGenerator.UnitTests/TestUtils.cs +++ b/DllImportGenerator/DllImportGenerator.UnitTests/TestUtils.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.Collections.Immutable; -using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection;