Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/Framework/test/SharedFxTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,32 +159,38 @@ public void SharedFrameworkContainsValidDepsJson()
[Fact]
public void SharedFrameworkAssembliesHaveExpectedAssemblyVersions()
{
// Only test managed assemblies from dotnet/aspnetcore.
// Assemblies from this repo and dotnet/runtime don't always have identical assembly versions.
var repoAssemblies = TestData.GetSharedFrameworkBinariesFromRepo()
.Split(';', StringSplitOptions.RemoveEmptyEntries)
.ToHashSet();

var versionStringWithoutPrereleaseTag = TestData.GetMicrosoftNETCoreAppPackageVersion().Split('-', 2)[0];
var version = Version.Parse(versionStringWithoutPrereleaseTag);
var aspnetcoreVersionString = TestData.GetSharedFxVersion().Split('-', 2)[0];
var aspnetcoreVersion = Version.Parse(aspnetcoreVersionString);

var dlls = Directory.GetFiles(_sharedFxRoot, "*.dll", SearchOption.AllDirectories);
Assert.NotEmpty(dlls);

Assert.All(dlls, path =>
{
// Unlike dotnet/aspnetcore, dotnet/runtime varies the assembly version while in servicing.
if (!repoAssemblies.Contains(Path.GetFileNameWithoutExtension(path)))
var name = Path.GetFileNameWithoutExtension(path);
if (string.Equals(name, "aspnetcorev2_inprocess", StringComparison.Ordinal))
{
// Skip our native assembly.
return;
}

var expectedVersion = repoAssemblies.Contains(name) ? aspnetcoreVersion : version;

using var fileStream = File.OpenRead(path);
using var peReader = new PEReader(fileStream, PEStreamOptions.Default);
var reader = peReader.GetMetadataReader(MetadataReaderOptions.Default);
var assemblyDefinition = reader.GetAssemblyDefinition();

// Assembly versions should all match Major.Minor.0.0
Assert.Equal(version.Major, assemblyDefinition.Version.Major);
Assert.Equal(version.Minor, assemblyDefinition.Version.Minor);
Assert.Equal(expectedVersion.Major, assemblyDefinition.Version.Major);
Assert.Equal(expectedVersion.Minor, assemblyDefinition.Version.Minor);
Assert.Equal(0, assemblyDefinition.Version.Build);
Assert.Equal(0, assemblyDefinition.Version.Revision);
});
Expand Down
23 changes: 20 additions & 3 deletions src/Framework/test/TargetingPackTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void TargetingPackContainsListedAssemblies()
var actualAssemblies = Directory.GetFiles(Path.Combine(_targetingPackRoot, "ref", _targetingPackTfm), "*.dll")
.Select(Path.GetFileNameWithoutExtension)
.ToHashSet();
var listedTargetingPackAssemblies = TestData.ListedTargetingPackAssemblies.Keys.ToHashSet();
var listedTargetingPackAssemblies = TestData.ListedTargetingPackAssemblies.ToHashSet();

_output.WriteLine("==== actual assemblies ====");
_output.WriteLine(string.Join('\n', actualAssemblies.OrderBy(i => i)));
Expand All @@ -60,20 +60,37 @@ public void TargetingPackContainsListedAssemblies()
[Fact]
public void RefAssembliesHaveExpectedAssemblyVersions()
{
// Assemblies from this repo and dotnet/runtime don't always have identical assembly versions.
var repoAssemblies = TestData.GetAspNetCoreTargetingPackDependencies()
.Split(';', StringSplitOptions.RemoveEmptyEntries)
.ToHashSet();

var versionStringWithoutPrereleaseTag = TestData.GetMicrosoftNETCoreAppPackageVersion().Split('-', 2)[0];
var version = Version.Parse(versionStringWithoutPrereleaseTag);
var aspnetcoreVersionString = TestData.GetSharedFxVersion().Split('-', 2)[0];
var aspnetcoreVersion = Version.Parse(aspnetcoreVersionString);

IEnumerable<string> dlls = Directory.GetFiles(Path.Combine(_targetingPackRoot, "ref", _targetingPackTfm), "*.dll", SearchOption.AllDirectories);
Assert.NotEmpty(dlls);

Assert.All(dlls, path =>
{
var expectedVersion = repoAssemblies.Contains(Path.GetFileNameWithoutExtension(path)) ?
aspnetcoreVersion :
version;

var fileName = Path.GetFileNameWithoutExtension(path);
var assemblyName = AssemblyName.GetAssemblyName(path);
using var fileStream = File.OpenRead(path);
using var peReader = new PEReader(fileStream, PEStreamOptions.Default);
var reader = peReader.GetMetadataReader(MetadataReaderOptions.Default);
var assemblyDefinition = reader.GetAssemblyDefinition();

TestData.ListedTargetingPackAssemblies.TryGetValue(fileName, out var expectedVersion);
Assert.Equal(expectedVersion, assemblyDefinition.Version.ToString());
// Assembly versions should all match Major.Minor.0.0
Assert.Equal(expectedVersion.Major, assemblyDefinition.Version.Major);
Assert.Equal(expectedVersion.Minor, assemblyDefinition.Version.Minor);
Assert.Equal(0, assemblyDefinition.Version.Build);
Assert.Equal(0, assemblyDefinition.Version.Revision);
});
}

Expand Down
Loading