Skip to content

Commit

Permalink
Fix build break introduced in .NET Standard 1.x projects
Browse files Browse the repository at this point in the history
Fixes #452
  • Loading branch information
AArnott committed Mar 15, 2020
1 parent 5bb27a1 commit 4b0113b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/NerdBank.GitVersioning.Tests/AssemblyInfoTest.cs
Expand Up @@ -36,6 +36,8 @@ namespace AssemblyInfo
do()
#if NETSTANDARD || NETFRAMEWORK || NETCOREAPP
[<System.CodeDom.Compiler.GeneratedCode(""" + AssemblyVersionInfo.GeneratorName + @""",""" + AssemblyVersionInfo.GeneratorVersion + @""")>]
#endif
#if NETFRAMEWORK || NETCOREAPP || NETSTANDARD2_0 || NETSTANDARD2_1
[<System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage>]
#endif
type internal ThisAssembly() =
Expand Down Expand Up @@ -76,6 +78,8 @@ public void CSharpGenerator()
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("""")]
#if NETSTANDARD || NETFRAMEWORK || NETCOREAPP
[System.CodeDom.Compiler.GeneratedCode(""" + AssemblyVersionInfo.GeneratorName + @""",""" + AssemblyVersionInfo.GeneratorVersion + @""")]
#endif
#if NETFRAMEWORK || NETCOREAPP || NETSTANDARD2_0 || NETSTANDARD2_1
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
#endif
internal static partial class ThisAssembly {
Expand Down
10 changes: 9 additions & 1 deletion src/Nerdbank.GitVersioning.Tasks/AssemblyVersionInfo.cs
Expand Up @@ -20,6 +20,7 @@ public class AssemblyVersionInfo : Task
/// See https://github.com/dotnet/Nerdbank.GitVersioning/issues/346
/// </remarks>
private const string CompilerDefinesAroundGeneratedCodeAttribute = "NETSTANDARD || NETFRAMEWORK || NETCOREAPP";
private const string CompilerDefinesAroundExcludeFromCodeCoverageAttribute = "NETFRAMEWORK || NETCOREAPP || NETSTANDARD2_0 || NETSTANDARD2_1";

public static readonly string GeneratorName = ThisAssembly.AssemblyName;
public static readonly string GeneratorVersion = ThisAssembly.AssemblyVersion;
Expand Down Expand Up @@ -519,6 +520,8 @@ internal override void StartThisAssemblyClass()
this.codeBuilder.AppendLine("do()");
this.codeBuilder.AppendLine($"#if {CompilerDefinesAroundGeneratedCodeAttribute}");
this.codeBuilder.AppendLine($"[<System.CodeDom.Compiler.GeneratedCode(\"{GeneratorName}\",\"{GeneratorVersion}\")>]");
this.codeBuilder.AppendLine("#endif");
this.codeBuilder.AppendLine($"#if {CompilerDefinesAroundExcludeFromCodeCoverageAttribute}");
this.codeBuilder.AppendLine("[<System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage>]");
this.codeBuilder.AppendLine("#endif");
this.codeBuilder.AppendLine("type internal ThisAssembly() =");
Expand All @@ -541,6 +544,8 @@ internal override void StartThisAssemblyClass()
{
this.codeBuilder.AppendLine($"#if {CompilerDefinesAroundGeneratedCodeAttribute}");
this.codeBuilder.AppendLine($"[System.CodeDom.Compiler.GeneratedCode(\"{GeneratorName}\",\"{GeneratorVersion}\")]");
this.codeBuilder.AppendLine("#endif");
this.codeBuilder.AppendLine($"#if {CompilerDefinesAroundExcludeFromCodeCoverageAttribute}");
this.codeBuilder.AppendLine("[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]");
this.codeBuilder.AppendLine("#endif");
this.codeBuilder.AppendLine("internal static partial class ThisAssembly {");
Expand Down Expand Up @@ -581,10 +586,13 @@ internal override void DeclareAttribute(Type type, string arg)

internal override void StartThisAssemblyClass()
{
this.codeBuilder.AppendLine($"#If {CompilerDefinesAroundGeneratedCodeAttribute.Replace("||", " Or ")} Then");
this.codeBuilder.AppendLine($"#If {CompilerDefinesAroundExcludeFromCodeCoverageAttribute.Replace("||", " Or ")} Then");
this.codeBuilder.AppendLine($"<System.CodeDom.Compiler.GeneratedCode(\"{GeneratorName}\",\"{GeneratorVersion}\")>");
this.codeBuilder.AppendLine("<System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage>");
this.codeBuilder.AppendLine("Partial Friend NotInheritable Class ThisAssembly");
this.codeBuilder.AppendLine($"#ElseIf {CompilerDefinesAroundGeneratedCodeAttribute.Replace("||", " Or ")} Then");
this.codeBuilder.AppendLine($"<System.CodeDom.Compiler.GeneratedCode(\"{GeneratorName}\",\"{GeneratorVersion}\")>");
this.codeBuilder.AppendLine("Partial Friend NotInheritable Class ThisAssembly");
this.codeBuilder.AppendLine("#Else");
this.codeBuilder.AppendLine("Partial Friend NotInheritable Class ThisAssembly");
this.codeBuilder.AppendLine("#End If");
Expand Down

0 comments on commit 4b0113b

Please sign in to comment.