Skip to content

Commit 98b84d2

Browse files
daveMuellerMarco Rossignoli
and
Marco Rossignoli
authored
migration to .net 6.0 (#1473)
Co-authored-by: Marco Rossignoli <[email protected]>
1 parent d936138 commit 98b84d2

File tree

19 files changed

+88
-74
lines changed

19 files changed

+88
-74
lines changed

Directory.Build.targets

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<PackageReference Update="Microsoft.Extensions.DependencyModel" Version="2.1.0" />
77
<PackageReference Update="Microsoft.Extensions.DependencyInjection" Version="6.0.1" />
88
<PackageReference Update="Microsoft.Extensions.FileSystemGlobbing" Version="2.0.1" />
9-
<PackageReference Update="Microsoft.NET.Test.Sdk" Version="16.5.0" />
9+
<PackageReference Update="Microsoft.NET.Test.Sdk" Version="17.5.0" />
1010
<!-- https://github.com/coverlet-coverage/coverlet/issues/1042 -->
1111
<PackageReference Update="Microsoft.TestPlatform.ObjectModel" Version="16.9.1" />
1212
<PackageReference Update="Mono.Cecil" Version="0.11.1" />
@@ -21,8 +21,8 @@
2121
We can check minimum supported package version here https://github.com/Microsoft/vstest/blob/master/src/Microsoft.TestPlatform.ObjectModel/Microsoft.TestPlatform.ObjectModel.csproj#L37
2222
-->
2323
<PackageReference Update="System.Reflection.Metadata" Version="1.5.0" />
24-
<PackageReference Update="xunit" Version="2.4.1" />
25-
<PackageReference Update="xunit.assert" Version="2.4.1" />
24+
<PackageReference Update="xunit" Version="2.4.2" />
25+
<PackageReference Update="xunit.assert" Version="2.4.2" />
2626
<PackageReference Update="xunit.runner.visualstudio" Version="2.4.1"/>
2727
<PackageReference Update="Tmds.ExecFunction" Version="0.4.0" />
2828
</ItemGroup>

Documentation/Changelog.md

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414
-Allign published nuget package version to github release version [#1413](https://github.com/coverlet-coverage/coverlet/issues/1413)
1515
-Sync nuget and github release versions [#1122](https://github.com/coverlet-coverage/coverlet/issues/1122)
1616

17+
### Improvements
18+
-Migration of the project to .NET 6.0 [#1473](https://github.com/coverlet-coverage/coverlet/pull/1473)
19+
1720
### Breaking changes
1821
- New parameter `ExcludeAssembliesWithoutSources` to control automatic assembly exclusion [1164](https://github.com/coverlet-coverage/coverlet/issues/1164). The parameter `InstrumentModulesWithoutLocalSources` has been removed. since it can be handled by setting `ExcludeAssembliesWithoutSources` to `None`.
1922
- The default heuristics for determining whether to instrument an assembly has been changed. In previous versions any missing source file was taken as a signal that it was a third-party project that shouldn't be instrumented, with exceptions for some common file name patterns for source generators. Now only assemblies where no source files at all can be found are excluded from instrumentation, and the code for detecting source generator files have been removed. To get back to the behaviour that at least one missing file is sufficient to exclude an assembly, set `ExcludeAssembliesWithoutSources` to `MissingAny`, or use assembly exclusion filters for more fine-grained control.

eng/build.yml

+10
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@ steps:
99
version: 5.0.401
1010
displayName: Install .NET Core SDK 5.0.401
1111

12+
- task: UseDotNet@2
13+
inputs:
14+
version: 6.0.408
15+
displayName: Install .NET Core SDK 6.0.408
16+
17+
- task: UseDotNet@2
18+
inputs:
19+
version: 7.0.203
20+
displayName: Install .NET Core SDK 7.0.203
21+
1222
- script: dotnet restore
1323
displayName: Restore packages
1424

global.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"sdk": {
3-
"version": "5.0.401",
3+
"version": "6.0.408",
44
"rollForward": "latestMajor"
55
}
66
}

src/coverlet.console/coverlet.console.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net5.0</TargetFramework>
5+
<TargetFramework>net6.0</TargetFramework>
66
<ToolCommandName>coverlet</ToolCommandName>
77
<PackAsTool>true</PackAsTool>
88
<AssemblyTitle>coverlet.console</AssemblyTitle>

src/coverlet.core/Helpers/InstrumentationHelper.cs

+29-33
Original file line numberDiff line numberDiff line change
@@ -125,20 +125,18 @@ public bool HasPdb(string module, out bool embedded)
125125

126126
public bool EmbeddedPortablePdbHasLocalSource(string module, AssemblySearchType excludeAssembliesWithoutSources)
127127
{
128-
using (Stream moduleStream = _fileSystem.OpenRead(module))
129-
using (var peReader = new PEReader(moduleStream))
128+
using Stream moduleStream = _fileSystem.OpenRead(module);
129+
using var peReader = new PEReader(moduleStream);
130+
foreach (DebugDirectoryEntry entry in peReader.ReadDebugDirectory())
130131
{
131-
foreach (DebugDirectoryEntry entry in peReader.ReadDebugDirectory())
132+
if (entry.Type == DebugDirectoryEntryType.EmbeddedPortablePdb)
132133
{
133-
if (entry.Type == DebugDirectoryEntryType.EmbeddedPortablePdb)
134-
{
135-
using MetadataReaderProvider embeddedMetadataProvider = peReader.ReadEmbeddedPortablePdbDebugDirectoryData(entry);
136-
MetadataReader metadataReader = embeddedMetadataProvider.GetMetadataReader();
134+
using MetadataReaderProvider embeddedMetadataProvider = peReader.ReadEmbeddedPortablePdbDebugDirectoryData(entry);
135+
MetadataReader metadataReader = embeddedMetadataProvider.GetMetadataReader();
137136

138-
if (!MatchDocumentsWithSources(module, excludeAssembliesWithoutSources, metadataReader))
139-
{
140-
return false;
141-
}
137+
if (!MatchDocumentsWithSources(module, excludeAssembliesWithoutSources, metadataReader))
138+
{
139+
return false;
142140
}
143141
}
144142
}
@@ -150,31 +148,29 @@ public bool EmbeddedPortablePdbHasLocalSource(string module, AssemblySearchType
150148

151149
public bool PortablePdbHasLocalSource(string module, AssemblySearchType excludeAssembliesWithoutSources)
152150
{
153-
using (Stream moduleStream = _fileSystem.OpenRead(module))
154-
using (var peReader = new PEReader(moduleStream))
151+
using Stream moduleStream = _fileSystem.OpenRead(module);
152+
using var peReader = new PEReader(moduleStream);
153+
foreach (DebugDirectoryEntry entry in peReader.ReadDebugDirectory())
155154
{
156-
foreach (DebugDirectoryEntry entry in peReader.ReadDebugDirectory())
155+
if (entry.Type == DebugDirectoryEntryType.CodeView)
157156
{
158-
if (entry.Type == DebugDirectoryEntryType.CodeView)
157+
CodeViewDebugDirectoryData codeViewData = peReader.ReadCodeViewDebugDirectoryData(entry);
158+
using Stream pdbStream = _fileSystem.OpenRead(_sourceRootTranslator.ResolveFilePath(codeViewData.Path));
159+
using var metadataReaderProvider = MetadataReaderProvider.FromPortablePdbStream(pdbStream);
160+
MetadataReader metadataReader = null;
161+
try
162+
{
163+
metadataReader = metadataReaderProvider.GetMetadataReader();
164+
}
165+
catch (BadImageFormatException)
166+
{
167+
_logger.LogWarning($"{nameof(BadImageFormatException)} during MetadataReaderProvider.FromPortablePdbStream in InstrumentationHelper.PortablePdbHasLocalSource, unable to check if module has got local source.");
168+
return true;
169+
}
170+
171+
if (!MatchDocumentsWithSources(module, excludeAssembliesWithoutSources, metadataReader))
159172
{
160-
CodeViewDebugDirectoryData codeViewData = peReader.ReadCodeViewDebugDirectoryData(entry);
161-
using Stream pdbStream = _fileSystem.OpenRead(_sourceRootTranslator.ResolveFilePath(codeViewData.Path));
162-
using var metadataReaderProvider = MetadataReaderProvider.FromPortablePdbStream(pdbStream);
163-
MetadataReader metadataReader = null;
164-
try
165-
{
166-
metadataReader = metadataReaderProvider.GetMetadataReader();
167-
}
168-
catch (BadImageFormatException)
169-
{
170-
_logger.LogWarning($"{nameof(BadImageFormatException)} during MetadataReaderProvider.FromPortablePdbStream in InstrumentationHelper.PortablePdbHasLocalSource, unable to check if module has got local source.");
171-
return true;
172-
}
173-
174-
if (!MatchDocumentsWithSources(module, excludeAssembliesWithoutSources, metadataReader))
175-
{
176-
return false;
177-
}
173+
return false;
178174
}
179175
}
180176
}

test/coverlet.collector.tests/coverlet.collector.tests.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Import Project="$(RepoRoot)src\coverlet.msbuild.tasks\coverlet.msbuild.props" />
33

44
<PropertyGroup>
5-
<TargetFramework>net5.0</TargetFramework>
5+
<TargetFramework>net6.0</TargetFramework>
66
<IsPackable>false</IsPackable>
77
</PropertyGroup>
88

test/coverlet.core.performancetest/coverlet.core.performancetest.csproj

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
<Import Project="$(RepoRoot)src\coverlet.msbuild.tasks\coverlet.msbuild.props" />
33

44
<PropertyGroup>
5-
<TargetFramework>net5.0</TargetFramework>
5+
<TargetFramework>net6.0</TargetFramework>
66
<IsPackable>false</IsPackable>
77
</PropertyGroup>
88

99
<ItemGroup>
1010
<PackageReference Include="xunit" />
1111
<PackageReference Include="xunit.runner.visualstudio" />
12+
<PackageReference Include="Microsoft.NET.Test.Sdk" />
1213
</ItemGroup>
1314

1415
<ItemGroup>

test/coverlet.core.tests/Instrumentation/InstrumenterTests.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -514,11 +514,11 @@ public void CanInstrumentFSharpAssemblyWithAnonymousRecord()
514514
string sample = Directory.GetFiles(Directory.GetCurrentDirectory(), "coverlet.tests.projectsample.fsharp.dll").First();
515515
var instrumentationHelper =
516516
new InstrumentationHelper(new ProcessExitHandler(), new RetryHelper(), new FileSystem(), new Mock<ILogger>().Object,
517-
new SourceRootTranslator(sample, new Mock<ILogger>().Object, new FileSystem(), new AssemblyAdapter()));
517+
new SourceRootTranslator(Assembly.GetExecutingAssembly().Location, new Mock<ILogger>().Object, new FileSystem(), new AssemblyAdapter()));
518518

519519
var instrumenter = new Instrumenter(sample, "_coverlet_tests_projectsample_fsharp", new CoverageParameters(), loggerMock.Object, instrumentationHelper,
520-
new FileSystem(), new SourceRootTranslator(sample, loggerMock.Object, new FileSystem(), new AssemblyAdapter()), new CecilSymbolHelper());
521-
520+
new FileSystem(), new SourceRootTranslator(Assembly.GetExecutingAssembly().Location, loggerMock.Object, new FileSystem(), new AssemblyAdapter()), new CecilSymbolHelper());
521+
522522
Assert.True(instrumentationHelper.HasPdb(sample, out bool embedded));
523523
Assert.False(embedded);
524524
Assert.True(instrumenter.CanInstrument());

test/coverlet.core.tests/coverlet.core.tests.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Import Project="$(RepoRoot)src\coverlet.msbuild.tasks\coverlet.msbuild.props" />
33

44
<PropertyGroup>
5-
<TargetFramework>net5.0</TargetFramework>
5+
<TargetFramework>net6.0</TargetFramework>
66
<IsPackable>false</IsPackable>
77
<NoWarn>$(NoWarn);CS8002</NoWarn>
88
<MSBuildWarningsAsMessages>NU1702</MSBuildWarningsAsMessages>

test/coverlet.integration.determisticbuild/coverlet.integration.determisticbuild.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<Import Project="$(MSBuildThisFileDirectory)\DeterministicTest.props" />
44

55
<PropertyGroup>
6-
<TargetFramework>net5.0</TargetFramework>
6+
<TargetFramework>net6.0</TargetFramework>
77
<IsPackable>false</IsPackable>
88
<AssemblyName>coverletsample.integration.determisticbuild</AssemblyName>
99
<RestoreSources>
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net5.0</TargetFramework>
4+
<TargetFramework>net6.0</TargetFramework>
55
<IsPackable>false</IsPackable>
66
<AssemblyName>coverletsamplelib.integration.template</AssemblyName>
77
<IsTestProject>false</IsTestProject>
@@ -10,8 +10,8 @@
1010
</PropertyGroup>
1111

1212
<ItemGroup>
13-
<PackageReference Include="xunit" Version="2.4.1" />
14-
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1"/>
13+
<PackageReference Include="xunit" Version="2.4.1" />
14+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1"/>
1515
</ItemGroup>
1616

1717
</Project>

test/coverlet.integration.tests/BaseTest.cs

+9-7
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ private protected string GetPackageVersion(string filter)
6565
}
6666
}
6767

68-
private protected ClonedTemplateProject CloneTemplateProject(bool cleanupOnDispose = true, string testSDKVersion = "16.5.0")
68+
private protected ClonedTemplateProject CloneTemplateProject(bool cleanupOnDispose = true, string testSDKVersion = "17.5.0")
6969
{
7070
DirectoryInfo finalRoot = Directory.CreateDirectory($"{Guid.NewGuid().ToString("N")[..6]}{Interlocked.Increment(ref s_folderSuffix)}");
7171
foreach (string file in (Directory.GetFiles($"../../../../coverlet.integration.template", "*.cs")
@@ -248,12 +248,14 @@ private protected void AssertCoverage(ClonedTemplateProject clonedTemplateProjec
248248
bool coverageChecked = false;
249249
foreach (string coverageFile in clonedTemplateProject.GetFiles(filter))
250250
{
251-
JsonConvert.DeserializeObject<Modules>(File.ReadAllText(coverageFile))
252-
.Document("DeepThought.cs")
253-
.Class("Coverlet.Integration.Template.DeepThought")
254-
.Method("System.Int32 Coverlet.Integration.Template.DeepThought::AnswerToTheUltimateQuestionOfLifeTheUniverseAndEverything()")
255-
.AssertLinesCovered((6, 1), (7, 1), (8, 1));
256-
coverageChecked = true;
251+
Classes? document = JsonConvert.DeserializeObject<Modules>(File.ReadAllText(coverageFile))?.Document("DeepThought.cs");
252+
if (document != null)
253+
{
254+
document.Class("Coverlet.Integration.Template.DeepThought")
255+
.Method("System.Int32 Coverlet.Integration.Template.DeepThought::AnswerToTheUltimateQuestionOfLifeTheUniverseAndEverything()")
256+
.AssertLinesCovered((6, 1), (7, 1), (8, 1));
257+
coverageChecked = true;
258+
}
257259
}
258260

259261
Assert.True(coverageChecked, $"Coverage check fail\n{standardOutput}");

test/coverlet.integration.tests/DeterministicBuild.cs

+9-7
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,15 @@ private protected void AssertCoverage(string standardOutput = "", bool checkDete
4545
string reportFilePath = "";
4646
foreach (string coverageFile in Directory.GetFiles(_testProjectPath, "coverage.json", SearchOption.AllDirectories))
4747
{
48-
JsonConvert.DeserializeObject<Modules>(File.ReadAllText(coverageFile))
49-
.Document("DeepThought.cs")
50-
.Class("Coverlet.Integration.DeterministicBuild.DeepThought")
51-
.Method("System.Int32 Coverlet.Integration.DeterministicBuild.DeepThought::AnswerToTheUltimateQuestionOfLifeTheUniverseAndEverything()")
52-
.AssertLinesCovered((6, 1), (7, 1), (8, 1));
53-
coverageChecked = true;
54-
reportFilePath = coverageFile;
48+
Classes? document = JsonConvert.DeserializeObject<Modules>(File.ReadAllText(coverageFile))?.Document("DeepThought.cs");
49+
if (document != null)
50+
{
51+
document.Class("Coverlet.Integration.DeterministicBuild.DeepThought")
52+
.Method("System.Int32 Coverlet.Integration.DeterministicBuild.DeepThought::AnswerToTheUltimateQuestionOfLifeTheUniverseAndEverything()")
53+
.AssertLinesCovered((6, 1), (7, 1), (8, 1));
54+
coverageChecked = true;
55+
reportFilePath = coverageFile;
56+
}
5557
}
5658
Assert.True(coverageChecked, $"Coverage check fail\n{standardOutput}");
5759
File.Delete(reportFilePath);

0 commit comments

Comments
 (0)