Skip to content

Commit 90741b1

Browse files
committed
Fix VersionLoader to check local packages for all versions
Previously, VersionLoader only checked artifacts/local-packages for versions containing 'current' in the name. Now it always checks the local packages folder first for ANY version before falling back to the global NuGet cache. This enables the CI workflow to build packages with versions like '1.0.0-preview08-pr4-3' and have them correctly resolved during tests.
1 parent e0480eb commit 90741b1

1 file changed

Lines changed: 22 additions & 25 deletions

File tree

  • Microsoft.Azure.Cosmos.Encryption.Custom/tests/Microsoft.Azure.Cosmos.Encryption.Custom.CompatibilityTests/SideBySide

Microsoft.Azure.Cosmos.Encryption.Custom/tests/Microsoft.Azure.Cosmos.Encryption.Custom.CompatibilityTests/SideBySide/VersionLoader.cs

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -80,37 +80,34 @@ public Type GetType(string fullTypeName)
8080

8181
private static string GetPackagePath(string version)
8282
{
83-
// For "current" versions (e.g., "1.0.0-current-*"), check local packages first
84-
if (version.Contains("current", StringComparison.OrdinalIgnoreCase))
83+
// First, always check local packages folder (for CI-built or locally-built packages)
84+
string localPackagesPath = Path.GetFullPath(
85+
Path.Combine(AppContext.BaseDirectory, "../../../../../artifacts/local-packages"));
86+
87+
if (Directory.Exists(localPackagesPath))
8588
{
86-
var localPackagesPath = Path.GetFullPath(
87-
Path.Combine(AppContext.BaseDirectory, "../../../../../artifacts/local-packages"));
88-
89-
if (Directory.Exists(localPackagesPath))
90-
{
91-
// Extract the version from NuGet package in local folder
92-
var packageFiles = Directory.GetFiles(localPackagesPath, $"Microsoft.Azure.Cosmos.Encryption.Custom.{version}.nupkg")
93-
.Where(f => !f.EndsWith(".symbols.nupkg"))
94-
.ToArray();
89+
// Look for exact version match in local packages
90+
string[] packageFiles = Directory.GetFiles(localPackagesPath, $"Microsoft.Azure.Cosmos.Encryption.Custom.{version}.nupkg")
91+
.Where(f => !f.EndsWith(".symbols.nupkg"))
92+
.ToArray();
9593

96-
if (packageFiles.Length > 0)
94+
if (packageFiles.Length > 0)
95+
{
96+
// Extract the package to a temp location for loading
97+
string packageFile = packageFiles[0];
98+
string extractPath = Path.Combine(Path.GetTempPath(), "cosmos-compat-tests", Path.GetFileNameWithoutExtension(packageFile));
99+
100+
if (!Directory.Exists(extractPath) || !File.Exists(Path.Combine(extractPath, "lib", "netstandard2.0", "Microsoft.Azure.Cosmos.Encryption.Custom.dll")))
97101
{
98-
// Extract the package to a temp location for loading
99-
var packageFile = packageFiles[0];
100-
var extractPath = Path.Combine(Path.GetTempPath(), "cosmos-compat-tests", Path.GetFileNameWithoutExtension(packageFile));
101-
102-
if (!Directory.Exists(extractPath) || !File.Exists(Path.Combine(extractPath, "lib", "netstandard2.0", "Microsoft.Azure.Cosmos.Encryption.Custom.dll")))
103-
{
104-
Directory.CreateDirectory(extractPath);
105-
System.IO.Compression.ZipFile.ExtractToDirectory(packageFile, extractPath, overwriteFiles: true);
106-
}
107-
108-
return extractPath;
102+
Directory.CreateDirectory(extractPath);
103+
System.IO.Compression.ZipFile.ExtractToDirectory(packageFile, extractPath, overwriteFiles: true);
109104
}
105+
106+
return extractPath;
110107
}
111108
}
112109

113-
// Default: use global NuGet packages folder
110+
// Fallback: use global NuGet packages folder
114111
string globalPackagesPath = Environment.GetEnvironmentVariable("NUGET_PACKAGES");
115112

116113
if (string.IsNullOrWhiteSpace(globalPackagesPath))
@@ -138,7 +135,7 @@ private static string FindAssemblyPath(string packagePath)
138135
string libDir = Path.Combine(packagePath, "lib");
139136
if (Directory.Exists(libDir))
140137
{
141-
var dllPath = Directory.GetFiles(libDir, "Microsoft.Azure.Cosmos.Encryption.Custom.dll", SearchOption.AllDirectories)
138+
string dllPath = Directory.GetFiles(libDir, "Microsoft.Azure.Cosmos.Encryption.Custom.dll", SearchOption.AllDirectories)
142139
.FirstOrDefault();
143140
if (dllPath != null)
144141
{

0 commit comments

Comments
 (0)