GitVersion: [Bug] GitVersionInformation.g.cs(12,42): error CS0234 'ExcludeFromCodeCoverageAttribute' does not exist
Describe the bug
Latest version 5.3.6 fails in .Net Standard 2.0 builds.
Expected Behavior
Expected build to not fail. Version 5.3.5 builds all frameworks correctly.
Actual Behavior
During build of a dll in .Net Standard 2.0 I am getting following error:
Unity.Abstractions -> D:\a\abstractions\abstractions\src\bin\Release\netstandard2.0\Unity.Abstractions.dll
obj\Release\netstandard1.6\GitVersionInformation.g.cs(12,42): error CS0234: The type or namespace name 'ExcludeFromCodeCoverageAttribute' does not exist in the namespace 'System.Diagnostics.CodeAnalysis' (are you missing an assembly reference?) [D:\a\abstractions\abstractions\src\Unity.Abstractions.csproj]
The generated file fails on line 12:
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// GitVersion
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
[global::System.Runtime.CompilerServices.CompilerGenerated]
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] <-- This line fails in NETSTANDARD2_0
static class GitVersionInformation
{
public static string Major = "6";
public static string Minor = "0";
public static string Patch = "0";
. . .
}
Possible Fix
Reverted to previous version for now
Steps to Reproduce
For more information please follow this link and examine Build step.
Context
I am using GitVerion tool in CI builds. The library is added to projects during CI steps
Your Environment
<TargetFrameworks>netstandard2.1;netstandard2.0;netstandard1.6;netcoreapp3.0;netcoreapp2.0;netcoreapp1.0;net48;net47;net46;net45;net40</TargetFrameworks>
- Version Used: 5.3.6
- Link to your project: https://github.com/unitycontainer/abstractions
- Link to your CI build (if appropriate): https://github.com/unitycontainer/abstractions/blob/release/6.0.0/.github/workflows/cd-flow.yml
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 17 (12 by maintainers)
Commits related to this issue
- Testing more frameworks - See https://github.com/GitTools/GitVersion/issues/2330 — committed to odalet/GitVersionTests by odalet 4 years ago
Good point, I think it would have been cleaner than using the define.
It was fails both locally and in Azure DevOps when building.
I have tried starting a new Library project from scratch and indeed the attribute is correctly resolved in Mono. The library also compiles correctly adding GitVersionTask to that project. After checking this, I went back to my project and noticed that it was lacking a reference to System (not sure why as vs4mac always adds it by defautl)
To sum up, everything is working as expected. I am sorry for the noise.
We deal with that particular attribute on unsupported platforms in ImageSharp in the following way.
First define your own internal version and type forward it on supported platforms.
Then define a custom
SUPPORTS_CODECOVERAGEcompiler conditional in your Directory.Build.props based on your target frameworks. You can see an example of that here.https://github.com/SixLabors/ImageSharp/blob/d074b72f33d2d313bd508af49b1bad89a3a31d5a/Directory.Build.props#L47
It works everywhere then.
You can see on what target frameworks it is supported here.
https://apisof.net/catalog/System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute
FWIW, I hit the same error with a VSIX project claiming to target .Net 4.7.2. Workaround was to add a NuGet reference to System.Diagnostics.Tools (4.3.0 in my case). Using GitVersion 5.6.6.
@ENikS
As can be seen in the logs you provided us, the issue seems to be rather related to .NET Standard 1.6, not 2.0: if you examine the path in the log, you have netstandard1.6 after obj\Release (there may be something weird in
Unity.Abstractions.csprojby the way).I double-checked in msdn what frameworks support the attribute and indeed it is unknown by .NET Standard < 2.0…
Still, we’ll need some
#ifon our side, but I honestly expect it to work when ‘really’ targeting .NET Standard 2.0; I’ll go clone your repository and look for this!I think we cover only project targeting .net framework and netcoreapp2.1 and 3.1 in out artifacts testing, because the artifacts can be executed, but netstandard can not
@asbjornu Sure, I’ll have a look at this!
To replicate locally:
I guess you will be able to see what build does differently from your tests.