Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix build break introduced in .NET Standard 1.x projects #453

Merged
merged 1 commit into from Mar 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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