private void VerifyAssemblyReferences(AggregatedMetadataReader reader, string[] expected) { AssertEx.Equal( expected, reader .GetAssemblyReferences() .Select(aref => $"{reader.GetString(aref.Name)}, {aref.Version}") ); }
private void TestDependencyVersionWildcards(string sourceVersion, Version version0, Version version1, Version version2) { string srcLib = $@" [assembly: System.Reflection.AssemblyVersion(""{sourceVersion}"")] public class D {{ }} "; string src0 = @" class C { public static int F(D a) { return 1; } } "; string src1 = @" class C { public static int F(D a) { return 2; } } "; string src2 = @" class C { public static int F(D a) { return 3; } public static int G(D a) { return 4; } } "; var lib0 = CreateCompilationWithMscorlib(srcLib, assemblyName: "Lib", options: TestOptions.DebugDll); ((SourceAssemblySymbol)lib0.Assembly).lazyAssemblyIdentity = new AssemblyIdentity("Lib", version0); lib0.VerifyDiagnostics(); var lib1 = CreateCompilationWithMscorlib(srcLib, assemblyName: "Lib", options: TestOptions.DebugDll); ((SourceAssemblySymbol)lib1.Assembly).lazyAssemblyIdentity = new AssemblyIdentity("Lib", version1); lib1.VerifyDiagnostics(); var lib2 = CreateCompilationWithMscorlib(srcLib, assemblyName: "Lib", options: TestOptions.DebugDll); ((SourceAssemblySymbol)lib2.Assembly).lazyAssemblyIdentity = new AssemblyIdentity("Lib", version2); lib2.VerifyDiagnostics(); var compilation0 = CreateCompilation(src0, new[] { MscorlibRef, lib0.ToMetadataReference() }, assemblyName: "C", options: TestOptions.DebugDll); var compilation1 = compilation0.WithSource(src1).WithReferences(new[] { MscorlibRef, lib1.ToMetadataReference() }); var compilation2 = compilation1.WithSource(src2).WithReferences(new[] { MscorlibRef, lib2.ToMetadataReference() }); var v0 = CompileAndVerify(compilation0); var v1 = CompileAndVerify(compilation1); var v2 = CompileAndVerify(compilation2); var f0 = compilation0.GetMember <MethodSymbol>("C.F"); var f1 = compilation1.GetMember <MethodSymbol>("C.F"); var f2 = compilation2.GetMember <MethodSymbol>("C.F"); var g2 = compilation2.GetMember <MethodSymbol>("C.G"); var md0 = ModuleMetadata.CreateFromImage(v0.EmittedAssemblyData); var generation0 = EmitBaseline.CreateInitialBaseline(md0, EmptyLocalsProvider); var diff1 = compilation1.EmitDifference( generation0, ImmutableArray.Create(new SemanticEdit(SemanticEditKind.Update, f0, f1))); var diff2 = compilation2.EmitDifference( diff1.NextGeneration, ImmutableArray.Create( new SemanticEdit(SemanticEditKind.Update, f1, f2), new SemanticEdit(SemanticEditKind.Insert, null, g2))); var md1 = diff1.GetMetadata(); var md2 = diff2.GetMetadata(); var aggReader = new AggregatedMetadataReader(md0.MetadataReader, md1.Reader, md2.Reader); // all references to Lib should be to the baseline version: VerifyAssemblyReferences(aggReader, new[] { "mscorlib, 4.0.0.0", "Lib, " + lib0.Assembly.Identity.Version, "mscorlib, 4.0.0.0", "Lib, " + lib0.Assembly.Identity.Version, "mscorlib, 4.0.0.0", "Lib, " + lib0.Assembly.Identity.Version, }); }
public void VerifyAssemblyReferences(AggregatedMetadataReader reader, string[] expected) { AssertEx.Equal(expected, reader.GetAssemblyReferences().Select(aref => $"{reader.GetString(aref.Name)}, {aref.Version}")); }
private void TestDependencyVersionWildcards(string sourceVersion, Version version0, Version version1, Version version2) { string srcLib = $@" [assembly: System.Reflection.AssemblyVersion(""{sourceVersion}"")] public class D {{ }} "; string src0 = @" class C { public static int F(D a) { return 1; } } "; string src1 = @" class C { public static int F(D a) { return 2; } } "; string src2 = @" class C { public static int F(D a) { return 3; } public static int G(D a) { return 4; } } "; var lib0 = CreateCompilationWithMscorlib(srcLib, assemblyName: "Lib", options: TestOptions.DebugDll); ((SourceAssemblySymbol)lib0.Assembly).lazyAssemblyIdentity = new AssemblyIdentity("Lib", version0); lib0.VerifyDiagnostics(); var lib1 = CreateCompilationWithMscorlib(srcLib, assemblyName: "Lib", options: TestOptions.DebugDll); ((SourceAssemblySymbol)lib1.Assembly).lazyAssemblyIdentity = new AssemblyIdentity("Lib", version1); lib1.VerifyDiagnostics(); var lib2 = CreateCompilationWithMscorlib(srcLib, assemblyName: "Lib", options: TestOptions.DebugDll); ((SourceAssemblySymbol)lib2.Assembly).lazyAssemblyIdentity = new AssemblyIdentity("Lib", version2); lib2.VerifyDiagnostics(); var compilation0 = CreateCompilation(src0, new[] { MscorlibRef, lib0.ToMetadataReference() }, assemblyName: "C", options: TestOptions.DebugDll); var compilation1 = compilation0.WithSource(src1).WithReferences(new[] { MscorlibRef, lib1.ToMetadataReference() }); var compilation2 = compilation1.WithSource(src2).WithReferences(new[] { MscorlibRef, lib2.ToMetadataReference() }); var v0 = CompileAndVerify(compilation0); var v1 = CompileAndVerify(compilation1); var v2 = CompileAndVerify(compilation2); var f0 = compilation0.GetMember<MethodSymbol>("C.F"); var f1 = compilation1.GetMember<MethodSymbol>("C.F"); var f2 = compilation2.GetMember<MethodSymbol>("C.F"); var g2 = compilation2.GetMember<MethodSymbol>("C.G"); var md0 = ModuleMetadata.CreateFromImage(v0.EmittedAssemblyData); var generation0 = EmitBaseline.CreateInitialBaseline(md0, EmptyLocalsProvider); var diff1 = compilation1.EmitDifference( generation0, ImmutableArray.Create(new SemanticEdit(SemanticEditKind.Update, f0, f1))); var diff2 = compilation2.EmitDifference( diff1.NextGeneration, ImmutableArray.Create( new SemanticEdit(SemanticEditKind.Update, f1, f2), new SemanticEdit(SemanticEditKind.Insert, null, g2))); var md1 = diff1.GetMetadata(); var md2 = diff2.GetMetadata(); var aggReader = new AggregatedMetadataReader(md0.MetadataReader, md1.Reader, md2.Reader); // all references to Lib should be to the baseline version: VerifyAssemblyReferences(aggReader, new[] { "mscorlib, 4.0.0.0", "Lib, " + lib0.Assembly.Identity.Version, "mscorlib, 4.0.0.0", "Lib, " + lib0.Assembly.Identity.Version, "mscorlib, 4.0.0.0", "Lib, " + lib0.Assembly.Identity.Version, }); }