Skip to content

Commit 669c282

Browse files
authored
Merge pull request #453 from dotnet/fix452
Fix build break introduced in .NET Standard 1.x projects
2 parents 5bb27a1 + 4b0113b commit 669c282

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/NerdBank.GitVersioning.Tests/AssemblyInfoTest.cs

+4
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ namespace AssemblyInfo
3636
do()
3737
#if NETSTANDARD || NETFRAMEWORK || NETCOREAPP
3838
[<System.CodeDom.Compiler.GeneratedCode(""" + AssemblyVersionInfo.GeneratorName + @""",""" + AssemblyVersionInfo.GeneratorVersion + @""")>]
39+
#endif
40+
#if NETFRAMEWORK || NETCOREAPP || NETSTANDARD2_0 || NETSTANDARD2_1
3941
[<System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage>]
4042
#endif
4143
type internal ThisAssembly() =
@@ -76,6 +78,8 @@ public void CSharpGenerator()
7678
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("""")]
7779
#if NETSTANDARD || NETFRAMEWORK || NETCOREAPP
7880
[System.CodeDom.Compiler.GeneratedCode(""" + AssemblyVersionInfo.GeneratorName + @""",""" + AssemblyVersionInfo.GeneratorVersion + @""")]
81+
#endif
82+
#if NETFRAMEWORK || NETCOREAPP || NETSTANDARD2_0 || NETSTANDARD2_1
7983
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
8084
#endif
8185
internal static partial class ThisAssembly {

src/Nerdbank.GitVersioning.Tasks/AssemblyVersionInfo.cs

+9-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public class AssemblyVersionInfo : Task
2020
/// See https://github.com/dotnet/Nerdbank.GitVersioning/issues/346
2121
/// </remarks>
2222
private const string CompilerDefinesAroundGeneratedCodeAttribute = "NETSTANDARD || NETFRAMEWORK || NETCOREAPP";
23+
private const string CompilerDefinesAroundExcludeFromCodeCoverageAttribute = "NETFRAMEWORK || NETCOREAPP || NETSTANDARD2_0 || NETSTANDARD2_1";
2324

2425
public static readonly string GeneratorName = ThisAssembly.AssemblyName;
2526
public static readonly string GeneratorVersion = ThisAssembly.AssemblyVersion;
@@ -519,6 +520,8 @@ internal override void StartThisAssemblyClass()
519520
this.codeBuilder.AppendLine("do()");
520521
this.codeBuilder.AppendLine($"#if {CompilerDefinesAroundGeneratedCodeAttribute}");
521522
this.codeBuilder.AppendLine($"[<System.CodeDom.Compiler.GeneratedCode(\"{GeneratorName}\",\"{GeneratorVersion}\")>]");
523+
this.codeBuilder.AppendLine("#endif");
524+
this.codeBuilder.AppendLine($"#if {CompilerDefinesAroundExcludeFromCodeCoverageAttribute}");
522525
this.codeBuilder.AppendLine("[<System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage>]");
523526
this.codeBuilder.AppendLine("#endif");
524527
this.codeBuilder.AppendLine("type internal ThisAssembly() =");
@@ -541,6 +544,8 @@ internal override void StartThisAssemblyClass()
541544
{
542545
this.codeBuilder.AppendLine($"#if {CompilerDefinesAroundGeneratedCodeAttribute}");
543546
this.codeBuilder.AppendLine($"[System.CodeDom.Compiler.GeneratedCode(\"{GeneratorName}\",\"{GeneratorVersion}\")]");
547+
this.codeBuilder.AppendLine("#endif");
548+
this.codeBuilder.AppendLine($"#if {CompilerDefinesAroundExcludeFromCodeCoverageAttribute}");
544549
this.codeBuilder.AppendLine("[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]");
545550
this.codeBuilder.AppendLine("#endif");
546551
this.codeBuilder.AppendLine("internal static partial class ThisAssembly {");
@@ -581,10 +586,13 @@ internal override void DeclareAttribute(Type type, string arg)
581586

582587
internal override void StartThisAssemblyClass()
583588
{
584-
this.codeBuilder.AppendLine($"#If {CompilerDefinesAroundGeneratedCodeAttribute.Replace("||", " Or ")} Then");
589+
this.codeBuilder.AppendLine($"#If {CompilerDefinesAroundExcludeFromCodeCoverageAttribute.Replace("||", " Or ")} Then");
585590
this.codeBuilder.AppendLine($"<System.CodeDom.Compiler.GeneratedCode(\"{GeneratorName}\",\"{GeneratorVersion}\")>");
586591
this.codeBuilder.AppendLine("<System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage>");
587592
this.codeBuilder.AppendLine("Partial Friend NotInheritable Class ThisAssembly");
593+
this.codeBuilder.AppendLine($"#ElseIf {CompilerDefinesAroundGeneratedCodeAttribute.Replace("||", " Or ")} Then");
594+
this.codeBuilder.AppendLine($"<System.CodeDom.Compiler.GeneratedCode(\"{GeneratorName}\",\"{GeneratorVersion}\")>");
595+
this.codeBuilder.AppendLine("Partial Friend NotInheritable Class ThisAssembly");
588596
this.codeBuilder.AppendLine("#Else");
589597
this.codeBuilder.AppendLine("Partial Friend NotInheritable Class ThisAssembly");
590598
this.codeBuilder.AppendLine("#End If");

0 commit comments

Comments
 (0)