diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceAssemblySymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceAssemblySymbol.cs index 81e3db3de5b00..0b77ebe420db2 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceAssemblySymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceAssemblySymbol.cs @@ -2073,7 +2073,7 @@ private void DecodeWellKnownAttribute(ref DecodeWellKnownAttributeArguments EmitDeterministic(string source, Platform platform, return compilation.EmitToArray(EmitOptions.Default.WithDebugInformationFormat(pdbFormat), pdbStream: new MemoryStream()); } + [Fact, WorkItem(4578, "https://github.com/dotnet/roslyn/issues/4578")] + public void BanVersionWildcards() + { + string source = @"[assembly: System.Reflection.AssemblyVersion(""10101.0.*"")] public class C {}"; + var compilationDeterministic = CreateCompilation(source, assemblyName: "DeterminismTest", references: new[] { MscorlibRef }, + parseOptions: TestOptions.Regular.WithFeature("deterministic", "true")); + var compilationNonDeterministic = CreateCompilation(source, assemblyName: "DeterminismTest", references: new[] { MscorlibRef }); + + var resultDeterministic = compilationDeterministic.Emit(Stream.Null, Stream.Null); + var resultNonDeterministic = compilationNonDeterministic.Emit(Stream.Null, Stream.Null); + + Assert.False(resultDeterministic.Success); + Assert.True(resultNonDeterministic.Success); + } + [Fact, WorkItem(372, "https://github.com/dotnet/roslyn/issues/372")] public void Simple() { diff --git a/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceAssemblySymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceAssemblySymbol.vb index e4a678674b0c7..9a65b01dac51b 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceAssemblySymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceAssemblySymbol.vb @@ -998,7 +998,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols ElseIf attrData.IsTargetAttribute(Me, AttributeDescription.AssemblyVersionAttribute) Then Dim verString = DirectCast(attrData.CommonConstructorArguments(0).Value, String) Dim version As Version = Nothing - If Not VersionHelper.TryParseAssemblyVersion(verString, allowWildcard:=True, version:=version) Then + If Not VersionHelper.TryParseAssemblyVersion(verString, allowWildcard:=Not _compilation.IsEmitDeterministic, version:=version) Then arguments.Diagnostics.Add(ERRID.ERR_InvalidVersionFormat, GetAssemblyAttributeFirstArgumentLocation(arguments.AttributeSyntaxOpt)) End If arguments.GetOrCreateData(Of CommonAssemblyWellKnownAttributeData)().AssemblyVersionAttributeSetting = version diff --git a/src/Compilers/VisualBasic/Test/Emit/Emit/DeterministicTests.vb b/src/Compilers/VisualBasic/Test/Emit/Emit/DeterministicTests.vb index a0046aa288d6a..31bf7ce06fd11 100644 --- a/src/Compilers/VisualBasic/Test/Emit/Emit/DeterministicTests.vb +++ b/src/Compilers/VisualBasic/Test/Emit/Emit/DeterministicTests.vb @@ -1,6 +1,7 @@ ' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. Imports System +Imports System.IO Imports System.Collections.Generic Imports System.Collections.Immutable Imports System.Threading @@ -25,6 +26,25 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.UnitTests.Emit Return compilation.EmitToArray() End Function + + Public Sub BanVersionWildcards() + Dim source = +" +Class C + Shared Sub Main() + End Sub +End Class" + Dim compilationDeterministic = CreateCompilationWithMscorlib({source}, assemblyName:="DeterminismTest", + parseOptions:=TestOptions.Regular.WithFeature("deterministic", "true")) + Dim compilationNonDeterministic = CreateCompilationWithMscorlib({source}, assemblyName:="DeterminismTest") + + Dim resultDeterministic = compilationDeterministic.Emit(Stream.Null, Stream.Null) + Dim resultNonDeterministic = compilationNonDeterministic.Emit(Stream.Null, Stream.Null) + + Assert.False(resultDeterministic.Success) + Assert.True(resultNonDeterministic.Success) + End Sub + Public Sub CompareAllBytesEmitted_Release() Dim source =