-
Notifications
You must be signed in to change notification settings - Fork 653
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
[Bug] GitVersionInformation.g.cs(12,42): error CS0234 'ExcludeFromCodeCoverageAttribute' does not exist #2330
Comments
Ideas why our tests didn't discover this, @arturcic? |
To replicate locally:
I guess you will be able to see what build does differently from your tests. |
@asbjornu Sure, I'll have a look at 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 |
Ok, so to discover this we would need one project for each of our target platforms that reference |
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 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 |
So, a quick fix could look like this: #if NETFRAMEWORK || (NETCOREAPP && !NETCOREAPP1_0 && !NETCOREAPP1_1) || (NETSTANDARD && !NETSTANDARD1_0 && !NETSTANDARD1_1 && !NETSTANDARD1_2 && !NETSTANDARD1_3 && !NETSTANDARD1_4 && !NETSTANDARD1_5 && !NETSTANDARD1_6)
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
#endif It's a bit ugly, but works (at least across .NET fx, .NET Core and .NET Standard - maybe we'll need more of this if we are to target Xamarin, old portable libs, Silverlight or whatever weird target we'll come up with). Then I wonder, maybe it would be better to detect the target framework at generation time. For now, I suppose I'll simply propose the code above for a quick fix. |
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. #if SUPPORTS_CODECOVERAGE
using System.Runtime.CompilerServices;
[assembly: TypeForwardedTo(typeof(System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute))]
#else
namespace System.Diagnostics.CodeAnalysis
{
/// <summary>
/// Specifies that the attributed code should be excluded from code coverage information.
/// </summary>
[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Event, Inherited = false, AllowMultiple = false)]
internal sealed class ExcludeFromCodeCoverageAttribute : Attribute
{
}
}
#endif Then define a custom It works everywhere then. You can see on what target frameworks it is supported here. https://apisof.net/catalog/System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute |
@JimBobSquarePants Yes, I knew some types are "duck-typing" detected by .NET and was wondering whether this applied to this attribute as well, but didn't have time to explore this further. I really like the
Anyway that's a great suggestion (I expected no less from ImageSharp 👍) and very helpful! PS: Still one question though. What is the |
🎉 This issue has been resolved in version 5.3.7 🎉 Your GitReleaseManager bot 📦🚀 |
I can reproduce this same issue with GitVersion 5.5.0 in a library project targeting .Net Framework v4.8 using Mono 6.12.0.93. Mono does not seems to have the ExcludeFromCodeCoverage attribute implemented. |
@ylatuya I've had a look at your repository and in particular to this hack of yours. I have zero experience with building Xamarin code so I wouldn't know where to start in order to detect a mono compiler and the lack of the ExcludeFromCodeCoverage attribute in this case. Anyway, I can see you forced the definition of
If you'd like to try my last suggestion, simply copy/paste the code below somewhere in your project: namespace System.Diagnostics.CodeAnalysis
{
[global::System.AttributeUsage(
global::System.AttributeTargets.Assembly |
global::System.AttributeTargets.Class |
global::System.AttributeTargets.Struct |
global::System.AttributeTargets.Constructor |
global::System.AttributeTargets.Method |
global::System.AttributeTargets.Property |
global::System.AttributeTargets.Event,
Inherited = false, AllowMultiple = false)]
internal sealed class ExcludeFromCodeCoverageAttribute : global::System.Attribute { }
} When I find some time, I'll clone your repository and try to build it and see if I can come up with something better. Could you also elaborate on when exaxtly the build fails? Locally? Only in Azure DevOps? When building or when running the unit tests? Could you share some build log? |
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. To sum up, everything is working as expected. I am sorry for the noise. |
Seems we're all good then! |
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. |
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:The generated file fails on line 12:
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
netstandard2.1;netstandard2.0;netstandard1.6;netcoreapp3.0;netcoreapp2.0;netcoreapp1.0;net48;net47;net46;net45;net40
The text was updated successfully, but these errors were encountered: