You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, when I try to get the target framework version of Microsoft.NETCore.App\2.1.30\mscorlib.dll it comes back as ".NETFramework,Version=v4.0". I have a feeling I am doing something wrong. Below is the test I was using.
It looked like "2.1.30", "3.1.32" didn't have the TargetFrameworkAttribute and all of the newer did have that attribute. (All versions had mscorlib as the name for line 80).
using System.IO;
using System.Reflection.Metadata;
using System.Reflection.PortableExecutable;
using ICSharpCode.Decompiler;
using ICSharpCode.Decompiler.Metadata;
namespace TestNetCoreTwoTargetFrameworkResolution
{
internal class Program
{
public static void Main(string[] args)
{
var versions = new string[] { "2.1.30", "3.1.32", "6.0.16", "7.0.5", "8.0.0-preview.3.23174.8" };
foreach (var version in versions)
{
var assemblyPath = $@"C:\Program Files\dotnet\shared\Microsoft.NETCore.App\{version}\mscorlib.dll";
// var assemblyPath = @"C:\Program Files\dotnet\shared\Microsoft.NETCore.App\7.0.5\mscorlib.dll";
var options = MetadataReaderOptions.ApplyWindowsRuntimeProjections;
using (var fileStream = new FileStream(assemblyPath, FileMode.Open, FileAccess.Read))
{
var peFile = new PEFile(
assemblyPath,
fileStream,
PEStreamOptions.PrefetchEntireImage,
metadataOptions: options);
AssemblyDefinition assemblyDefinition = peFile.Metadata.GetAssemblyDefinition();
var frameworkId = GetTargetFrameworkId(peFile.Metadata);
var name = peFile.Metadata.GetString(assemblyDefinition.Name);
var targetFrameworkId = peFile.DetectTargetFrameworkId();
Console.WriteLine($"{frameworkId} {name} {targetFrameworkId}");
}
}
}
const string TargetFrameworkAttributeName = "System.Runtime.Versioning.TargetFrameworkAttribute";
public static string GetTargetFrameworkId(MetadataReader metadata)
{
foreach (var h in metadata.GetCustomAttributes(Handle.AssemblyDefinition))
{
var attribute = metadata.GetCustomAttribute(h);
if (attribute.GetAttributeType(metadata).GetFullTypeName(metadata).ToString() !=
TargetFrameworkAttributeName)
continue;
var blobReader = metadata.GetBlobReader(attribute.Value);
if (blobReader.ReadUInt16() == 0x0001)
{
return blobReader.ReadSerializedString()?.Replace(" ", "");
}
}
return null;
}
}
}```
Output:
mscorlib .NETFramework,Version=v4.0
mscorlib .NETFramework,Version=v4.0
.NETCoreApp,Version=v6.0 mscorlib .NETCoreApp,Version=v6.0
.NETCoreApp,Version=v7.0 mscorlib .NETCoreApp,Version=v7.0
.NETCoreApp,Version=v8.0 mscorlib .NETCoreApp,Version=v8.0
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi, when I try to get the target framework version of Microsoft.NETCore.App\2.1.30\mscorlib.dll it comes back as ".NETFramework,Version=v4.0". I have a feeling I am doing something wrong. Below is the test I was using.
It looked like it has to do with these 2 lines.
ILSpy/ICSharpCode.Decompiler/Metadata/DotNetCorePathFinderExtensions.cs
Line 65 in 397661b
ILSpy/ICSharpCode.Decompiler/Metadata/DotNetCorePathFinderExtensions.cs
Line 80 in 397661b
It looked like "2.1.30", "3.1.32" didn't have the TargetFrameworkAttribute and all of the newer did have that attribute. (All versions had mscorlib as the name for line 80).
Beta Was this translation helpful? Give feedback.
All reactions