22// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33
44using System ;
5+ using System . Collections . Generic ;
56using System . IO ;
67using System . Linq ;
8+ using System . Reflection ;
9+ using System . Reflection . Metadata ;
10+ using System . Reflection . PortableExecutable ;
711using Newtonsoft . Json . Linq ;
812using Xunit ;
913using Xunit . Abstractions ;
@@ -81,7 +85,7 @@ public void SharedFrameworkContainsExpectedFiles()
8185 }
8286
8387 [ Fact ]
84- public void ItContainsValidRuntimeConfigFile ( )
88+ public void SharedFrameworkContainsValidRuntimeConfigFile ( )
8589 {
8690 var runtimeConfigFilePath = Path . Combine ( _sharedFxRoot , "Microsoft.AspNetCore.App.runtimeconfig.json" ) ;
8791
@@ -98,7 +102,7 @@ public void ItContainsValidRuntimeConfigFile()
98102 }
99103
100104 [ Fact ]
101- public void ItContainsValidDepsJson ( )
105+ public void SharedFrameworkContainsValidDepsJson ( )
102106 {
103107 var depsFilePath = Path . Combine ( _sharedFxRoot , "Microsoft.AspNetCore.App.deps.json" ) ;
104108
@@ -155,6 +159,46 @@ public void ItContainsValidDepsJson()
155159 }
156160 }
157161
162+ [ Fact ]
163+ public void SharedFrameworkAssembliesHaveExpectedAssemblyVersions ( )
164+ {
165+ // Only test managed assemblies
166+ IEnumerable < string > dlls = Directory . GetFiles ( _sharedFxRoot , "*.dll" , SearchOption . AllDirectories ) . Where ( i => ! i . Contains ( "aspnetcorev2_inprocess" ) ) ;
167+ Assert . NotEmpty ( dlls ) ;
168+
169+ Assert . All ( dlls , path =>
170+ {
171+ using var fileStream = File . OpenRead ( path ) ;
172+ using var peReader = new PEReader ( fileStream , PEStreamOptions . Default ) ;
173+ var reader = peReader . GetMetadataReader ( MetadataReaderOptions . Default ) ;
174+ var assemblyDefinition = reader . GetAssemblyDefinition ( ) ;
175+
176+ // Assembly versions should all match Major.Minor.0.0
177+ Assert . Equal ( 0 , assemblyDefinition . Version . Build ) ;
178+ Assert . Equal ( 0 , assemblyDefinition . Version . Revision ) ;
179+ } ) ;
180+ }
181+
182+ [ Fact ]
183+ public void SharedFrameworkAssemblyReferencesHaveExpectedAssemblyVersions ( )
184+ {
185+ IEnumerable < string > dlls = Directory . GetFiles ( _sharedFxRoot , "*.dll" , SearchOption . AllDirectories ) . Where ( i => ! i . Contains ( "aspnetcorev2_inprocess" ) && ! i . Contains ( "System.Security.Cryptography.Xml" , StringComparison . OrdinalIgnoreCase ) ) ;
186+ Assert . NotEmpty ( dlls ) ;
187+
188+ Assert . All ( dlls , path =>
189+ {
190+ using var fileStream = File . OpenRead ( path ) ;
191+ using var peReader = new PEReader ( fileStream , PEStreamOptions . Default ) ;
192+ var reader = peReader . GetMetadataReader ( MetadataReaderOptions . Default ) ;
193+
194+ Assert . All ( reader . AssemblyReferences , handle =>
195+ {
196+ var reference = reader . GetAssemblyReference ( handle ) ;
197+ Assert . Equal ( 0 , reference . Version . Revision ) ;
198+ } ) ;
199+ } ) ;
200+ }
201+
158202 [ Fact ]
159203 public void ItContainsVersionFile ( )
160204 {
0 commit comments