Skip to content

Commit 0b71134

Browse files
authored
fix dotnet (#2900)
1 parent 76a5796 commit 0b71134

2 files changed

Lines changed: 72 additions & 33 deletions

File tree

src/BuildScriptGenerator/DotNetCore/DotnetCorePlatform.cs

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -287,11 +287,27 @@ public string GetInstallerScriptSnippet(
287287
// 3. Try Direct-ACR (direct OCI API calls)
288288
if (this.commonOptions.EnableAcrSdkProvider)
289289
{
290-
var runtimeVersion = dotNetCorePlatformDetectorResult.PlatformVersion;
291-
var result = this.TryInstallFromAcrSdkProvider(sdkVersion, runtimeVersion);
292-
if (result != null)
290+
// DirectACR needs the exact runtime version for the tag (e.g. "10.0.4", not "10.0").
291+
// If ExternalACR handled version resolution, PlatformVersion may still be raw.
292+
// Try to resolve it — the version map is lazily loaded and cached.
293+
// If resolution fails, skip DirectACR entirely and let next provider handle it.
294+
try
293295
{
294-
return result;
296+
var runtimeVersion = this.GetMaxSatisfyingRuntimeVersionAndVerify(
297+
dotNetCorePlatformDetectorResult.PlatformVersion);
298+
dotNetCorePlatformDetectorResult.PlatformVersion = runtimeVersion;
299+
300+
var result = this.TryInstallFromAcrSdkProvider(sdkVersion, runtimeVersion);
301+
if (result != null)
302+
{
303+
return result;
304+
}
305+
}
306+
catch (Exception ex)
307+
{
308+
this.logger.LogWarning(
309+
ex,
310+
"Could not resolve runtime version for DirectACR. Skipping to next provider.");
295311
}
296312
}
297313

@@ -314,17 +330,14 @@ public void ResolveVersions(RepositoryContext context, PlatformDetectorResult de
314330
$"'{typeof(DotNetCorePlatformDetectorResult)}' but got '{detectorResult.GetType()}'.");
315331
}
316332

317-
// Resolve runtime version (same for all flows — ExternalAcrSdkProvider does not affect this).
318-
var resolvedRuntimeVersion = this.GetRuntimeVersionUsingHierarchicalRules(
319-
dotNetCorePlatformDetectorResult.PlatformVersion);
320-
resolvedRuntimeVersion = this.GetMaxSatisfyingRuntimeVersionAndVerify(resolvedRuntimeVersion);
321-
dotNetCorePlatformDetectorResult.PlatformVersion = resolvedRuntimeVersion;
322-
323-
// Resolve SDK version.
324-
// External ACR provider dictates the SDK version directly — no runtime→SDK lookup needed.
325-
// This is .NET-specific: other platforms have a single version,
326-
// but .NET has separate runtime and SDK versions. The external host already knows
327-
// which SDK companion image to use, so we trust its SDK version.
333+
// When External ACR is enabled, try it first — it dictates the SDK version
334+
// directly, without needing the runtime→SDK version map from blob/CDN.
335+
// The runtime version is expected to come from the user (--platform-version / DOTNET_VERSION)
336+
// or from .csproj detection (<TargetFramework>). We use it as-is without
337+
// validation against a version map — the external host already ensures
338+
// compatibility between the runtime and the SDK it provides.
339+
// If the SDK fetch later falls back to DirectACR, the runtime version is
340+
// resolved on demand at that point
328341
if (this.commonOptions.EnableExternalAcrSdkProvider)
329342
{
330343
try
@@ -335,6 +348,10 @@ public void ResolveVersions(RepositoryContext context, PlatformDetectorResult de
335348
this.logger.LogInformation(
336349
"External ACR provider returned .NET SDK version {Version}. Using it directly.",
337350
dictatedSdk);
351+
352+
var resolvedRuntime = this.GetRuntimeVersionUsingHierarchicalRules(
353+
dotNetCorePlatformDetectorResult.PlatformVersion);
354+
dotNetCorePlatformDetectorResult.PlatformVersion = resolvedRuntime;
338355
dotNetCorePlatformDetectorResult.SdkVersion = dictatedSdk;
339356
return;
340357
}
@@ -347,7 +364,12 @@ public void ResolveVersions(RepositoryContext context, PlatformDetectorResult de
347364
}
348365
}
349366

350-
// Normal SDK resolution: look up from runtime→SDK version map.
367+
// Normal path: resolve runtime version using the version map, then look up SDK.
368+
var resolvedRuntimeVersion = this.GetRuntimeVersionUsingHierarchicalRules(
369+
dotNetCorePlatformDetectorResult.PlatformVersion);
370+
resolvedRuntimeVersion = this.GetMaxSatisfyingRuntimeVersionAndVerify(resolvedRuntimeVersion);
371+
dotNetCorePlatformDetectorResult.PlatformVersion = resolvedRuntimeVersion;
372+
351373
var versionMap = this.versionProvider.GetSupportedVersions();
352374
var sdkVersion = this.GetSdkVersion(context, dotNetCorePlatformDetectorResult.PlatformVersion, versionMap);
353375
dotNetCorePlatformDetectorResult.SdkVersion = sdkVersion;

tests/BuildScriptGenerator.Tests/DotnetCore/DotNetCorePlatformTest.cs

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,17 @@ public void GetInstallerScript_UsesDirectAcrProvider_IfEnabled_AndSdkIsNotAlread
172172
detector,
173173
commonOptions: commonOptions,
174174
sdkAlreadyInstalled: false,
175-
acrSdkProvider: acrSdkProvider);
175+
acrSdkProvider: acrSdkProvider,
176+
supportedVersions: new Dictionary<string, string>
177+
{
178+
{ "3.1.32", "3.1.426" },
179+
});
176180
var context = CreateContext();
177181
var detectorResult = new DotNetCorePlatformDetectorResult
178182
{
179183
Platform = DotNetCoreConstants.PlatformName,
180-
PlatformVersion = "3.1.2",
181-
SdkVersion = "3.1.2",
184+
PlatformVersion = "3.1.32",
185+
SdkVersion = "3.1.426",
182186
};
183187

184188
// Act
@@ -247,13 +251,17 @@ public void GetInstallerScript_FallsBackToCdn_WhenAllProvidersFail()
247251
sdkAlreadyInstalled: false,
248252
externalAcrSdkProvider: externalAcrSdkProvider,
249253
acrSdkProvider: acrSdkProvider,
250-
externalSdkProvider: externalSdkProvider);
254+
externalSdkProvider: externalSdkProvider,
255+
supportedVersions: new Dictionary<string, string>
256+
{
257+
{ "3.1.32", "3.1.426" },
258+
});
251259
var context = CreateContext();
252260
var detectorResult = new DotNetCorePlatformDetectorResult
253261
{
254262
Platform = DotNetCoreConstants.PlatformName,
255-
PlatformVersion = "3.1.2",
256-
SdkVersion = "3.1.2",
263+
PlatformVersion = "3.1.32",
264+
SdkVersion = "3.1.426",
257265
};
258266

259267
// Act
@@ -285,14 +293,14 @@ public void GetInstallerScript_DirectAcrProvider_PassesRuntimeVersion()
285293
acrSdkProvider: acrSdkProvider,
286294
supportedVersions: new Dictionary<string, string>
287295
{
288-
{ "3.1.2", "3.1.2" },
296+
{ "3.1.32", "3.1.426" },
289297
});
290298
var context = CreateContext();
291299
var detectorResult = new DotNetCorePlatformDetectorResult
292300
{
293301
Platform = DotNetCoreConstants.PlatformName,
294-
PlatformVersion = "3.1.2",
295-
SdkVersion = "3.1.2",
302+
PlatformVersion = "3.1.32",
303+
SdkVersion = "3.1.426",
296304
};
297305

298306
// Act
@@ -302,9 +310,9 @@ public void GetInstallerScript_DirectAcrProvider_PassesRuntimeVersion()
302310
Assert.NotNull(snippet);
303311
Assert.True(acrSdkProvider.RequestSdkFromAcrAsyncCalled);
304312
Assert.Equal(DotNetCoreConstants.PlatformName, acrSdkProvider.LastRequestedPlatformName);
305-
Assert.Equal("3.1.2", acrSdkProvider.LastRequestedVersion);
313+
Assert.Equal("3.1.426", acrSdkProvider.LastRequestedVersion);
306314
Assert.Equal(OsTypes.DebianBookworm, acrSdkProvider.LastRequestedDebianFlavor);
307-
Assert.Equal("3.1.2", acrSdkProvider.LastRequestedRuntimeVersion);
315+
Assert.Equal("3.1.32", acrSdkProvider.LastRequestedRuntimeVersion);
308316
}
309317

310318
[Fact]
@@ -329,13 +337,17 @@ public void GetInstallerScript_FallsBackFromExternalAcrToDirectAcr_WhenBothExter
329337
sdkAlreadyInstalled: false,
330338
externalAcrSdkProvider: externalAcrSdkProvider,
331339
acrSdkProvider: acrSdkProvider,
332-
externalSdkProvider: externalSdkProvider);
340+
externalSdkProvider: externalSdkProvider,
341+
supportedVersions: new Dictionary<string, string>
342+
{
343+
{ "3.1.32", "3.1.426" },
344+
});
333345
var context = CreateContext();
334346
var detectorResult = new DotNetCorePlatformDetectorResult
335347
{
336348
Platform = DotNetCoreConstants.PlatformName,
337-
PlatformVersion = "3.1.2",
338-
SdkVersion = "3.1.2",
349+
PlatformVersion = "3.1.32",
350+
SdkVersion = "3.1.426",
339351
};
340352

341353
// Act
@@ -380,8 +392,11 @@ public void ResolveVersions_UsesExternalAcrSdkVersion_WhenEnabled()
380392
// Act
381393
platform.ResolveVersions(context, detectorResult);
382394

383-
// Assert - ExternalACR dictates SDK version, overriding normal map lookup
395+
// Assert - ExternalACR dictates SDK version, overriding normal map lookup.
396+
// PlatformVersion is only processed by hierarchical rules (not fully resolved
397+
// against the version map), so it stays as the detected value.
384398
Assert.Equal("3.1.415", detectorResult.SdkVersion);
399+
Assert.Equal("3.1", detectorResult.PlatformVersion);
385400
}
386401

387402
[Fact]
@@ -416,8 +431,10 @@ public void ResolveVersions_FallsBackToVersionMap_WhenExternalAcrReturnsNull()
416431
// Act
417432
platform.ResolveVersions(context, detectorResult);
418433

419-
// Assert - Falls back to normal version map
434+
// Assert - Falls back to normal version map.
435+
// PlatformVersion is fully resolved (hierarchical rules + version map).
420436
Assert.Equal("3.1.302", detectorResult.SdkVersion);
437+
Assert.Equal("3.1.2", detectorResult.PlatformVersion);
421438
}
422439

423440
private BuildScriptGeneratorContext CreateContext(ISourceRepo sourceRepo = null)
@@ -637,4 +654,4 @@ private DotNetCorePlatform CreatePlatformWithExternalAcrVersionProvider(
637654
new DefaultStandardOutputWriter());
638655
}
639656
}
640-
}
657+
}

0 commit comments

Comments
 (0)