diff --git a/src/Cake.Common.Tests/Unit/Solution/Project/Properties/AssemblyInfoCreatorTests.cs b/src/Cake.Common.Tests/Unit/Solution/Project/Properties/AssemblyInfoCreatorTests.cs index 1ccea6b5b5..2b66e294d4 100644 --- a/src/Cake.Common.Tests/Unit/Solution/Project/Properties/AssemblyInfoCreatorTests.cs +++ b/src/Cake.Common.Tests/Unit/Solution/Project/Properties/AssemblyInfoCreatorTests.cs @@ -347,6 +347,51 @@ public void Should_Add_CustomAttributes_If_Set() Assert.Contains("[assembly: TestAttribute(\"TestValue\")]", result); } + [Fact] + public void Should_Add_CustomAttributes_If_Set_With_Boolean_Value() + { + // Given + var fixture = new AssemblyInfoFixture(); + fixture.Settings.CustomAttributes = new Collection { new AssemblyInfoCustomAttribute { Name = "TestAttribute", NameSpace = "Test.NameSpace", Value = true } }; + + // When + var result = fixture.CreateAndReturnContent(); + + // Then + Assert.Contains("using Test.NameSpace;", result); + Assert.Contains("[assembly: TestAttribute(true)]", result); + } + + [Fact] + public void Should_Add_CustomAttributes_If_Set_With_Null_Value() + { + // Given + var fixture = new AssemblyInfoFixture(); + fixture.Settings.CustomAttributes = new Collection { new AssemblyInfoCustomAttribute { Name = "TestAttribute", NameSpace = "Test.NameSpace", Value = null } }; + + // When + var result = fixture.CreateAndReturnContent(); + + // Then + Assert.Contains("using Test.NameSpace;", result); + Assert.Contains("[assembly: TestAttribute()]", result); + } + + [Fact] + public void Should_Add_CustomAttributes_If_Set_With_Empty_Value() + { + // Given + var fixture = new AssemblyInfoFixture(); + fixture.Settings.CustomAttributes = new Collection { new AssemblyInfoCustomAttribute { Name = "TestAttribute", NameSpace = "Test.NameSpace", Value = string.Empty } }; + + // When + var result = fixture.CreateAndReturnContent(); + + // Then + Assert.Contains("using Test.NameSpace;", result); + Assert.Contains("[assembly: TestAttribute()]", result); + } + [Fact] public void Should_Add_MetadataAttributes_If_Set() { diff --git a/src/Cake.Common.Tests/Unit/Solution/Project/Properties/AssemblyInfoCreatorTests_VB.cs b/src/Cake.Common.Tests/Unit/Solution/Project/Properties/AssemblyInfoCreatorTests_VB.cs index 579684029e..1ecf09ae98 100644 --- a/src/Cake.Common.Tests/Unit/Solution/Project/Properties/AssemblyInfoCreatorTests_VB.cs +++ b/src/Cake.Common.Tests/Unit/Solution/Project/Properties/AssemblyInfoCreatorTests_VB.cs @@ -301,6 +301,51 @@ public void Should_Add_CustomAttributes_If_Set() Assert.Contains("Imports Test.NameSpace", result); Assert.Contains("", result); } + + [Fact] + public void Should_Add_CustomAttributes_If_Set_With_Boolean_Value() + { + // Given + var fixture = new AssemblyInfoFixture_VB(); + fixture.Settings.CustomAttributes = new Collection { new AssemblyInfoCustomAttribute { Name = "TestAttribute", NameSpace = "Test.NameSpace", Value = true } }; + + // When + var result = fixture.CreateAndReturnContent(); + + // Then + Assert.Contains("Imports Test.NameSpace", result); + Assert.Contains("", result); + } + + [Fact] + public void Should_Add_CustomAttributes_If_Set_With_Null_Value() + { + // Given + var fixture = new AssemblyInfoFixture_VB(); + fixture.Settings.CustomAttributes = new Collection { new AssemblyInfoCustomAttribute { Name = "TestAttribute", NameSpace = "Test.NameSpace", Value = null } }; + + // When + var result = fixture.CreateAndReturnContent(); + + // Then + Assert.Contains("Imports Test.NameSpace", result); + Assert.Contains("", result); + } + + [Fact] + public void Should_Add_CustomAttributes_If_Set_With_Empty_Value() + { + // Given + var fixture = new AssemblyInfoFixture_VB(); + fixture.Settings.CustomAttributes = new Collection { new AssemblyInfoCustomAttribute { Name = "TestAttribute", NameSpace = "Test.NameSpace", Value = string.Empty } }; + + // When + var result = fixture.CreateAndReturnContent(); + + // Then + Assert.Contains("Imports Test.NameSpace", result); + Assert.Contains("", result); + } } } } \ No newline at end of file diff --git a/src/Cake.Common/Solution/Project/Properties/AssemblyInfoCreatorData.cs b/src/Cake.Common/Solution/Project/Properties/AssemblyInfoCreatorData.cs index 63665078b4..269e677267 100644 --- a/src/Cake.Common/Solution/Project/Properties/AssemblyInfoCreatorData.cs +++ b/src/Cake.Common/Solution/Project/Properties/AssemblyInfoCreatorData.cs @@ -99,9 +99,17 @@ private void AddAttribute(string name, string @namespace, string value) } } - private void AddCustomAttribute(string name, string @namespace, string value) + private void AddCustomAttribute(string name, string @namespace, object value) { - if (value != null) + if (value is bool) + { + AddAttributeCore(CustomAttributes, name, @namespace, (bool)value ? _trueStringValue : _falseStringValue); + } + else if (value == null || string.IsNullOrEmpty(value as string)) + { + AddAttributeCore(CustomAttributes, name, @namespace, string.Empty); + } + else { AddAttributeCore(CustomAttributes, name, @namespace, string.Concat("\"", value, "\"")); } diff --git a/src/Cake.Common/Solution/Project/Properties/AssemblyInfoCustomAttribute.cs b/src/Cake.Common/Solution/Project/Properties/AssemblyInfoCustomAttribute.cs index 0aa60ff3b3..368722111f 100644 --- a/src/Cake.Common/Solution/Project/Properties/AssemblyInfoCustomAttribute.cs +++ b/src/Cake.Common/Solution/Project/Properties/AssemblyInfoCustomAttribute.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -25,6 +25,6 @@ public sealed class AssemblyInfoCustomAttribute /// Gets or sets the value. /// /// The value for the attribute. - public string Value { get; set; } + public object Value { get; set; } } } \ No newline at end of file