forked from dotnet/msbuild
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssemblyLoadContextTestTasks.cs
More file actions
94 lines (80 loc) · 3.08 KB
/
AssemblyLoadContextTestTasks.cs
File metadata and controls
94 lines (80 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using System;
using System.Reflection;
#nullable disable
namespace AssemblyLoadContextTest
{
/// <summary>
/// Task that validates assembly version roll-forward behavior.
/// Tests that MSBuildLoadContext accepts newer assembly versions when older versions are requested.
/// </summary>
public class ValidateAssemblyVersionRollForward : Task
{
/// <summary>
/// The name of the assembly to check (e.g., "System.Collections.Immutable")
/// </summary>
[Required]
public string AssemblyName { get; set; }
/// <summary>
/// The minimum expected version (e.g., "1.0.0.0")
/// </summary>
[Required]
public string MinimumVersion { get; set; }
public override bool Execute()
{
try
{
// Try to load the assembly by name with minimum version
var minimumVersion = Version.Parse(MinimumVersion);
var assemblyName = new AssemblyName(AssemblyName)
{
Version = minimumVersion
};
// This will trigger MSBuildLoadContext.Load which should accept newer versions
var assembly = Assembly.Load(assemblyName);
var loadedVersion = assembly.GetName().Version;
Log.LogMessage(MessageImportance.High,
$"Requested {AssemblyName} version {minimumVersion}, loaded version {loadedVersion}");
// Verify that we got a version >= minimum
if (loadedVersion < minimumVersion)
{
Log.LogError(
$"Assembly version roll-forward failed: requested {minimumVersion}, but loaded {loadedVersion} which is older");
return false;
}
Log.LogMessage(MessageImportance.High,
$"Assembly version roll-forward succeeded: loaded version {loadedVersion} >= requested {minimumVersion}");
return true;
}
catch (Exception ex)
{
Log.LogErrorFromException(ex, showStackTrace: true);
return false;
}
}
}
public class RegisterObject : Task
{
internal const string CacheKey = "RegressionForMSBuild#5080";
public override bool Execute()
{
BuildEngine4.RegisterTaskObject(
CacheKey,
new RegisterObject(),
RegisteredTaskObjectLifetime.Build,
allowEarlyCollection: false);
return true;
}
}
public class RetrieveObject : Task
{
public override bool Execute()
{
var entry = (RegisterObject)BuildEngine4.GetRegisteredTaskObject(RegisterObject.CacheKey, RegisteredTaskObjectLifetime.Build);
return true;
}
}
}