diff --git a/src/Compilers/CSharp/Portable/CSharpResources.Designer.cs b/src/Compilers/CSharp/Portable/CSharpResources.Designer.cs
index 06b4c6809919df0b02a9d0412cf4494e240e15ca..ac84dca48a76279295266fbf2de88ba9814991e7 100644
--- a/src/Compilers/CSharp/Portable/CSharpResources.Designer.cs
+++ b/src/Compilers/CSharp/Portable/CSharpResources.Designer.cs
@@ -7702,6 +7702,15 @@ internal class CSharpResources {
}
}
+ ///
+ /// Looks up a localized string similar to Public signing is not supported for netmodules..
+ ///
+ internal static string ERR_PublicSignNetModule {
+ get {
+ return ResourceManager.GetString("ERR_PublicSignNetModule", resourceCulture);
+ }
+ }
+
///
/// Looks up a localized string similar to The range variable '{0}' has already been declared.
///
diff --git a/src/Compilers/CSharp/Portable/CSharpResources.resx b/src/Compilers/CSharp/Portable/CSharpResources.resx
index bf08116f6f858ac1bbe9b3e87bde8703428cfe7b..605000e625a55070f26f01439f79cc277ded3680 100644
--- a/src/Compilers/CSharp/Portable/CSharpResources.resx
+++ b/src/Compilers/CSharp/Portable/CSharpResources.resx
@@ -3833,6 +3833,9 @@ You should consider suppressing the warning only if you're sure that you don't w
Public signing was specified and requires a public key, but no public key was specified.
+
+ Public signing is not supported for netmodules.
+
Delay signing was specified and requires a public key, but no public key was specified
diff --git a/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs b/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs
index 06cf76b06982ee65c7064957d72ba3e37805b640..db4abde0e6ccc252f7cd36a947e0bc0d91fa2bc9 100644
--- a/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs
+++ b/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs
@@ -1449,6 +1449,7 @@ internal enum ErrorCode
ERR_VarInvocationLvalueReserved = 8199,
ERR_ExpressionVariableInConstructorOrFieldInitializer = 8200,
ERR_ExpressionVariableInQueryClause = 8201,
+ ERR_PublicSignNetModule = 8202,
#endregion more stragglers for C# 7
}
}
diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceAssemblySymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceAssemblySymbol.cs
index 7dbb2093de01685559c07a2cf854f2278b2553ad..618a9353b8e05b05abcc0728ebe1e1a190d3a099 100644
--- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceAssemblySymbol.cs
+++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceAssemblySymbol.cs
@@ -573,9 +573,16 @@ private void ValidateAttributeSemantics(DiagnosticBag diagnostics)
diagnostics.Add(ErrorCode.WRN_DelaySignButNoKey, NoLocation.Singleton);
}
- if (DeclaringCompilation.Options.PublicSign && !Identity.HasPublicKey)
+ if (DeclaringCompilation.Options.PublicSign)
{
- diagnostics.Add(ErrorCode.ERR_PublicSignButNoKey, NoLocation.Singleton);
+ if (_compilation.Options.OutputKind.IsNetModule())
+ {
+ diagnostics.Add(ErrorCode.ERR_PublicSignNetModule, NoLocation.Singleton);
+ }
+ else if (!Identity.HasPublicKey)
+ {
+ diagnostics.Add(ErrorCode.ERR_PublicSignButNoKey, NoLocation.Singleton);
+ }
}
// If the options and attributes applied on the compilation imply real signing,
@@ -790,7 +797,9 @@ private void DetectAttributeAndOptionConflicts(DiagnosticBag diagnostics)
}
}
- if (_compilation.Options.PublicSign && (object)this.AssemblyKeyContainerAttributeSetting != (object)CommonAssemblyWellKnownAttributeData.StringMissingValue)
+ if (_compilation.Options.PublicSign &&
+ !_compilation.Options.OutputKind.IsNetModule() &&
+ (object)this.AssemblyKeyContainerAttributeSetting != (object)CommonAssemblyWellKnownAttributeData.StringMissingValue)
{
diagnostics.Add(ErrorCode.WRN_AttributeIgnoredWhenPublicSigning, NoLocation.Singleton, AttributeDescription.AssemblyKeyNameAttribute.FullName);
}
@@ -825,7 +834,9 @@ private void DetectAttributeAndOptionConflicts(DiagnosticBag diagnostics)
}
}
- if (_compilation.Options.PublicSign && (object)this.AssemblyKeyFileAttributeSetting != (object)CommonAssemblyWellKnownAttributeData.StringMissingValue)
+ if (_compilation.Options.PublicSign &&
+ !_compilation.Options.OutputKind.IsNetModule() &&
+ (object)this.AssemblyKeyFileAttributeSetting != (object)CommonAssemblyWellKnownAttributeData.StringMissingValue)
{
diagnostics.Add(ErrorCode.WRN_AttributeIgnoredWhenPublicSigning, NoLocation.Singleton, AttributeDescription.AssemblyKeyFileAttribute.FullName);
}
diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/InternalsVisibleToAndStrongNameTests.cs b/src/Compilers/CSharp/Test/Emit/Attributes/InternalsVisibleToAndStrongNameTests.cs
index 1b1ad22441006ddc8eda46981185d658d1733290..a2ed18ec93f180ed6ce4330b01e919c7f58b5877 100644
--- a/src/Compilers/CSharp/Test/Emit/Attributes/InternalsVisibleToAndStrongNameTests.cs
+++ b/src/Compilers/CSharp/Test/Emit/Attributes/InternalsVisibleToAndStrongNameTests.cs
@@ -423,6 +423,36 @@ public class C {}
Assert.True(identity.HasPublicKey);
AssertEx.Equal(identity.PublicKey, s_publicKey);
Assert.Equal(CorFlags.ILOnly | CorFlags.StrongNameSigned, metadata.Module.PEReaderOpt.PEHeaders.CorHeader.Flags);
+
+ c = CreateCompilationWithMscorlib(source, options: TestOptions.ReleaseModule.WithCryptoPublicKey(s_publicKey).WithPublicSign(true));
+
+ c.VerifyDiagnostics(
+ // error CS8201: Public signing is not supported for netmodules.
+ Diagnostic(ErrorCode.ERR_PublicSignNetModule).WithLocation(1, 1)
+ );
+
+ c = CreateCompilationWithMscorlib(source, options: TestOptions.ReleaseModule.WithCryptoKeyFile(s_publicKeyFile).WithPublicSign(true));
+
+ c.VerifyDiagnostics(
+ // error CS7091: Attribute 'System.Reflection.AssemblyKeyFileAttribute' given in a source file conflicts with option 'CryptoKeyFile'.
+ Diagnostic(ErrorCode.ERR_CmdOptionConflictsSource).WithArguments("System.Reflection.AssemblyKeyFileAttribute", "CryptoKeyFile").WithLocation(1, 1),
+ // error CS8201: Public signing is not supported for netmodules.
+ Diagnostic(ErrorCode.ERR_PublicSignNetModule).WithLocation(1, 1)
+ );
+
+ var snk = Temp.CreateFile().WriteAllBytes(TestResources.General.snKey);
+
+ string source1 = @"
+[assembly: System.Reflection.AssemblyKeyName(""roslynTestContainer"")]
+[assembly: System.Reflection.AssemblyKeyFile(@""" + snk.Path + @""")]
+public class C {}
+";
+
+ c = CreateCompilationWithMscorlib(source1, options: TestOptions.ReleaseModule.WithCryptoKeyFile(snk.Path).WithPublicSign(true));
+ c.VerifyDiagnostics(
+ // error CS8201: Public signing is not supported for netmodules.
+ Diagnostic(ErrorCode.ERR_PublicSignNetModule).WithLocation(1, 1)
+ );
}
[Fact, WorkItem(9150, "https://github.com/dotnet/roslyn/issues/9150")]
diff --git a/src/Compilers/VisualBasic/Portable/Errors/Errors.vb b/src/Compilers/VisualBasic/Portable/Errors/Errors.vb
index 23607cca7afae8556290e7ec77a90c350f4c117f..7097fd2d0ad8f65049630ee7eb5b8a874696a80f 100644
--- a/src/Compilers/VisualBasic/Portable/Errors/Errors.vb
+++ b/src/Compilers/VisualBasic/Portable/Errors/Errors.vb
@@ -1721,6 +1721,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
ERR_NewWithTupleTypeSyntax = 37280
ERR_PredefinedValueTupleTypeMustBeStruct = 37281
+ ERR_PublicSignNetModule = 37282
'// WARNINGS BEGIN HERE
WRN_UseOfObsoleteSymbol2 = 40000
@@ -1941,7 +1942,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
WRN_NoAnalyzerInAssembly = 42377
WRN_UnableToLoadAnalyzer = 42378
- ' // AVAILABLE 42379 - 49998
+ WRN_AttributeIgnoredWhenPublicSigning = 42379
+
+ ' // AVAILABLE 42380 - 49998
ERRWRN_Last = WRN_UnableToLoadAnalyzer + 1
'// HIDDENS AND INFOS BEGIN HERE
diff --git a/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceAssemblySymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceAssemblySymbol.vb
index 4f4ea388a868ffdb41dfda9d4fd63368db163fd3..7571e171bdc8c0e3dc1c0cc118b1dbcee37fbe46 100644
--- a/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceAssemblySymbol.vb
+++ b/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceAssemblySymbol.vb
@@ -1193,8 +1193,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
diagnostics.Add(ERRID.WRN_DelaySignButNoKey, NoLocation.Singleton)
End If
- If DeclaringCompilation.Options.PublicSign AndAlso Not Identity.HasPublicKey Then
- diagnostics.Add(ERRID.ERR_PublicSignNoKey, NoLocation.Singleton)
+ If DeclaringCompilation.Options.PublicSign Then
+ If DeclaringCompilation.Options.OutputKind.IsNetModule() Then
+ diagnostics.Add(ERRID.ERR_PublicSignNetModule, NoLocation.Singleton)
+ ElseIf Not Identity.HasPublicKey Then
+ diagnostics.Add(ERRID.ERR_PublicSignNoKey, NoLocation.Singleton)
+ End If
End If
' If the options and attributes applied on the compilation imply real signing,
@@ -1274,6 +1278,14 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
diagnostics.Add(ERRID.ERR_CmdOptionConflictsSource, NoLocation.Singleton, AttributeDescription.AssemblyKeyFileAttribute.FullName, "CryptoKeyFile")
End If
End If
+ ElseIf _compilation.Options.PublicSign Then
+ If Me.AssemblyKeyContainerAttributeSetting IsNot CommonAssemblyWellKnownAttributeData.StringMissingValue Then
+ diagnostics.Add(ERRID.WRN_AttributeIgnoredWhenPublicSigning, NoLocation.Singleton, AttributeDescription.AssemblyKeyNameAttribute.FullName)
+ End If
+
+ If Me.AssemblyKeyFileAttributeSetting IsNot CommonAssemblyWellKnownAttributeData.StringMissingValue Then
+ diagnostics.Add(ERRID.WRN_AttributeIgnoredWhenPublicSigning, NoLocation.Singleton, AttributeDescription.AssemblyKeyFileAttribute.FullName)
+ End If
End If
End Sub
diff --git a/src/Compilers/VisualBasic/Portable/VBResources.Designer.vb b/src/Compilers/VisualBasic/Portable/VBResources.Designer.vb
index 9e11d39d98e3aa37b901c75f52c4d2969c65eae2..03f5f2975d931fef6a58c0b1c5e61455e54eec65 100644
--- a/src/Compilers/VisualBasic/Portable/VBResources.Designer.vb
+++ b/src/Compilers/VisualBasic/Portable/VBResources.Designer.vb
@@ -9324,6 +9324,15 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
End Get
End Property
+ '''
+ ''' Looks up a localized string similar to Public signing is not supported for netmodules..
+ '''
+ Friend ReadOnly Property ERR_PublicSignNetModule() As String
+ Get
+ Return ResourceManager.GetString("ERR_PublicSignNetModule", resourceCulture)
+ End Get
+ End Property
+
'''
''' Looks up a localized string similar to Public sign was specified and requires a public key, but no public key was specified.
'''
@@ -12675,6 +12684,24 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
End Get
End Property
+ '''
+ ''' Looks up a localized string similar to Attribute '{0}' is ignored when public signing is specified..
+ '''
+ Friend ReadOnly Property WRN_AttributeIgnoredWhenPublicSigning() As String
+ Get
+ Return ResourceManager.GetString("WRN_AttributeIgnoredWhenPublicSigning", resourceCulture)
+ End Get
+ End Property
+
+ '''
+ ''' Looks up a localized string similar to Attribute is ignored when public signing is specified..
+ '''
+ Friend ReadOnly Property WRN_AttributeIgnoredWhenPublicSigning_Title() As String
+ Get
+ Return ResourceManager.GetString("WRN_AttributeIgnoredWhenPublicSigning_Title", resourceCulture)
+ End Get
+ End Property
+
'''
''' Looks up a localized string similar to Bad checksum value, non hex digits or odd number of hex digits..
'''
diff --git a/src/Compilers/VisualBasic/Portable/VBResources.resx b/src/Compilers/VisualBasic/Portable/VBResources.resx
index 2001d749922fae85020fa399004f2805b9b6ba03..7fe90213595be326808577c97684085755726751 100644
--- a/src/Compilers/VisualBasic/Portable/VBResources.resx
+++ b/src/Compilers/VisualBasic/Portable/VBResources.resx
@@ -4340,6 +4340,15 @@
Public sign was specified and requires a public key, but no public key was specified
+
+ Public signing is not supported for netmodules.
+
+
+ Attribute '{0}' is ignored when public signing is specified.
+
+
+ Attribute is ignored when public signing is specified.
+
Delay signing was specified and requires a public key, but no public key was specified.
diff --git a/src/Compilers/VisualBasic/Test/Emit/Attributes/InternalsVisibleToAndStrongNameTests.vb b/src/Compilers/VisualBasic/Test/Emit/Attributes/InternalsVisibleToAndStrongNameTests.vb
index c836c336902ffe79bd47b5adfc2833028b25f5f4..a7cc99d62b1975a441c49968a14b23d429ddeff4 100644
--- a/src/Compilers/VisualBasic/Test/Emit/Attributes/InternalsVisibleToAndStrongNameTests.vb
+++ b/src/Compilers/VisualBasic/Test/Emit/Attributes/InternalsVisibleToAndStrongNameTests.vb
@@ -337,7 +337,8 @@ End Class
End Sub
- Public Sub PublicKeyFromOptions_OssSigned()
+
+ Public Sub PublicKeyFromOptions_PublicSign()
' attributes are ignored
Dim source =
@@ -350,8 +351,13 @@ End Class
- Dim c = CreateCompilationWithMscorlib(source, options:=TestOptions.ReleaseDll.WithCryptoPublicKey(s_publicKey))
- c.VerifyDiagnostics()
+ Dim c = CreateCompilationWithMscorlib(source, options:=TestOptions.ReleaseDll.WithCryptoPublicKey(s_publicKey).WithPublicSign(True))
+ c.AssertTheseDiagnostics(
+
+BC42379: Attribute 'System.Reflection.AssemblyKeyFileAttribute' is ignored when public signing is specified.
+BC42379: Attribute 'System.Reflection.AssemblyKeyNameAttribute' is ignored when public signing is specified.
+
+ )
Assert.True(ByteSequenceComparer.Equals(s_publicKey, c.Assembly.Identity.PublicKey))
Dim Metadata = ModuleMetadata.CreateFromImage(c.EmitToArray())
@@ -360,6 +366,41 @@ End Class
Assert.True(identity.HasPublicKey)
AssertEx.Equal(identity.PublicKey, s_publicKey)
Assert.Equal(CorFlags.ILOnly Or CorFlags.StrongNameSigned, Metadata.Module.PEReaderOpt.PEHeaders.CorHeader.Flags)
+
+ c = CreateCompilationWithMscorlib(source, options:=TestOptions.ReleaseModule.WithCryptoPublicKey(s_publicKey).WithPublicSign(True))
+ c.AssertTheseDiagnostics(
+
+BC37282: Public signing is not supported for netmodules.
+
+ )
+
+ c = CreateCompilationWithMscorlib(source, options:=TestOptions.ReleaseModule.WithCryptoKeyFile(s_publicKeyFile).WithPublicSign(True))
+ c.AssertTheseDiagnostics(
+
+BC37207: Attribute 'System.Reflection.AssemblyKeyFileAttribute' given in a source file conflicts with option 'CryptoKeyFile'.
+BC37282: Public signing is not supported for netmodules.
+
+ )
+
+ Dim snk = Temp.CreateFile().WriteAllBytes(TestResources.General.snKey)
+
+ Dim source1 =
+
+
+<%= snk.Path %>
+Public Class C
+End Class
+]]>
+
+
+
+ c = CreateCompilationWithMscorlib(source1, options:=TestOptions.ReleaseModule.WithCryptoKeyFile(snk.Path).WithPublicSign(True))
+ c.AssertTheseDiagnostics(
+
+BC37282: Public signing is not supported for netmodules.
+
+ )
End Sub
@@ -1706,14 +1747,17 @@ End Class
PublicSignCore(compilation)
End Sub
- Public Sub PublicSignCore(compilation As Compilation)
+ Public Sub PublicSignCore(compilation As Compilation, Optional assertNoDiagnostics As Boolean = True)
Assert.True(compilation.Options.PublicSign)
Assert.Null(compilation.Options.DelaySign)
Dim stream As New MemoryStream()
Dim emitResult = compilation.Emit(stream)
Assert.True(emitResult.Success)
- Assert.True(emitResult.Diagnostics.IsEmpty)
+ If assertNoDiagnostics Then
+ Assert.True(emitResult.Diagnostics.IsEmpty)
+ End If
+
stream.Position = 0
Using reader As New PEReader(stream)
@@ -1759,6 +1803,7 @@ End Class
AssertTheseDiagnostics(c,
BC37254: Public sign was specified and requires a public key, but no public key was specified
+BC42379: Attribute 'System.Reflection.AssemblyKeyFileAttribute' is ignored when public signing is specified.
)
Assert.True(c.Options.PublicSign)
@@ -1778,6 +1823,7 @@ End Class
AssertTheseDiagnostics(c,
BC37254: Public sign was specified and requires a public key, but no public key was specified
+BC42379: Attribute 'System.Reflection.AssemblyKeyNameAttribute' is ignored when public signing is specified.
)
Assert.True(c.Options.PublicSign)
@@ -1845,7 +1891,14 @@ End Class
Dim snk = Temp.CreateFile().WriteAllBytes(TestResources.General.snKey)
Dim options = TestOptions.ReleaseDll.WithCryptoKeyFile(snk.Path).WithPublicSign(True)
Dim compilation = CreateCompilationWithMscorlib(source, options:=options)
- PublicSignCore(compilation)
+
+ AssertTheseDiagnostics(compilation,
+
+BC42379: Attribute 'System.Reflection.AssemblyKeyFileAttribute' is ignored when public signing is specified.
+BC42379: Attribute 'System.Reflection.AssemblyKeyNameAttribute' is ignored when public signing is specified.
+ )
+
+ PublicSignCore(compilation, assertNoDiagnostics:=False)
End Sub