Code coverage for .net core projects is including AutoGeneratedProgram in coverage metrics. It should be excluded.
Coverage includes user code only.

VS 2017 15.3 Preview 1
Might get fixed with #792 which will remove auto generated code from test projects.
Adding all coverage impacting issues for 15.5.
I just came across this today. I believe it's related to #519.
Does marking it as an enhancement mean it's not going to be fixed (this is typically what enhancement means at my organization :P)
CodeCoverage does not know that a certain code is autogenerated if it does not have "CompilerGenerated" Attribute on top of them.
This is by design
The code is autogenerated by the msbuild step in vstest/src/package/nuspec/Microsoft.NET.Test.Sdk.targets installed by the nuspec package so an attribute should either be added as part of the autogenerated file or the autogeneration should be removed.
@peteri reopening this issue. I'll take further look to understand why we need code, or how can we add the attribute
This issue added the comments so style cop ignores it, I suspect that it probably just needs the attribute adding.
The other comments on the linked roslyn issue seem to suggest the autogenerated program.cs is still needed.
It should have the GeneratedCodeAttribute attribute, not CompilerGeneratedAttribute though, right? Reference: https://blogs.msdn.microsoft.com/codeanalysis/2007/04/27/correct-usage-of-the-compilergeneratedattribute-and-the-generatedcodeattribute/
@samsmithnz , thanks for bringing it up. I agree it should be GenerateCodeAttribute, we plan to resolve this in next release to Test Platform.,
@mayankbansal018 Any further infos on that?
@gingters I've raised required PR's for this issue. We are hoping to resolve this in 15.6 RTM
@gingters, For VS IDE we missed the deadline for 2017 update 6, this will get fixed in update 7
However, it is fixed for vstest xcopy nuget package that we ship
fixed in latest Microsoft.Net.Test.SDK(15.8) VS 2017
I think msbuild (or whatever visual studio 2019 uses) does not add ExcludeFromCodeCoverage tag in auto generated csharp files.
I was expecting to test project to build:
// <auto-generated> This file has been auto generated. </auto-generated>
using System;
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
[Microsoft.VisualStudio.TestPlatform.TestSDKAutoGeneratedCode]
class AutoGeneratedProgram {static void Main(string[] args){}}
After reading that lasted updates fix the problem, I changed
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
to latest Test SDK:
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
and
So it seems to be possible to exclude from code coverage the autogenerated (Program) files of test project, by updating the Test SDK.
Most helpful comment
@samsmithnz , thanks for bringing it up. I agree it should be GenerateCodeAttribute, we plan to resolve this in next release to Test Platform.,