Skip to content

Commit 99b911a

Browse files
authored
Merging servicing fixes for 16.9.4 (#2837)
* Dynamic corelib.net loading (#2762) (#2803)
1 parent 6a858a3 commit 99b911a

6 files changed

+47
-17
lines changed

scripts/build.ps1

+15
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,14 @@ function Publish-Package
573573
Copy-Loc-Files $eventLogDataCollectorNetFull $coreCLRExtensionsDir "Microsoft.TestPlatform.Extensions.EventLogCollector.resources.dll"
574574
}
575575

576+
# Copy Coverage.CoreLib.Net dlls
577+
$codeCoverageExternalsVersion = ([xml](Get-Content $env:TP_ROOT_DIR\scripts\build\TestPlatform.Dependencies.props)).Project.PropertyGroup.CodeCoverageExternalsVersion
578+
$codeCoverageCoreLibPackagesDir = Join-Path $env:TP_PACKAGES_DIR "microsoft.visualstudio.coverage.corelib.net\$codeCoverageExternalsVersion\lib\$TPB_TargetFrameworkStandard"
579+
Copy-Item $codeCoverageCoreLibPackagesDir\Microsoft.VisualStudio.Coverage.CoreLib.Net.dll $coreCLR20PackageDir -Force
580+
if($TPB_LocalizedBuild) {
581+
Copy-Loc-Files $codeCoverageCoreLibPackagesDir $coreCLR20PackageDir "Microsoft.VisualStudio.Coverage.CoreLib.Net.resources.dll"
582+
}
583+
576584
# If there are some dependencies for the TestHostRuntimeProvider assemblies, those need to be moved too.
577585
$runtimeproviders = @("Microsoft.TestPlatform.TestHostRuntimeProvider.dll", "Microsoft.TestPlatform.TestHostRuntimeProvider.pdb")
578586
foreach($file in $runtimeproviders) {
@@ -736,6 +744,13 @@ function Create-VsixPackage
736744
if($TPB_LocalizedBuild) {
737745
Copy-Loc-Files $traceDataCollectorPackageDirectory $extensionsPackageDir "Microsoft.VisualStudio.TraceDataCollector.resources.dll"
738746
}
747+
748+
# Copy Microsoft.VisualStudio.CoreLib.Net
749+
$codeCoverageCoreLibPackagesDir = Join-Path $env:TP_PACKAGES_DIR "microsoft.visualstudio.coverage.corelib.net\$codeCoverageExternalsVersion\lib\$TPB_TargetFramework451"
750+
Copy-Item $codeCoverageCoreLibPackagesDir\Microsoft.VisualStudio.Coverage.CoreLib.Net.dll $packageDir -Force
751+
if($TPB_LocalizedBuild) {
752+
Copy-Loc-Files $codeCoverageCoreLibPackagesDir $packageDir "Microsoft.VisualStudio.Coverage.CoreLib.Net.resources.dll"
753+
}
739754

740755
$codeCoverageInterprocessPackageDirectory = Join-Path $env:TP_PACKAGES_DIR "Microsoft.VisualStudio.Coverage.Interprocess\$codeCoverageExternalsVersion\lib\$TPB_TargetFrameworkNS20"
741756
Copy-Item $codeCoverageInterprocessPackageDirectory\Microsoft.VisualStudio.Coverage.Interprocess.dll $extensionsPackageDir -Force

scripts/build/TestPlatform.Dependencies.props

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<!-- this version also needs to be "statically" readable because the test fixture will inspect this file for the version
1212
and because during the test `dotnet test` will run and re-build some of the test projects and at that time the version
1313
from a build parameter would not be available, so I am writing this version from the build.ps1 script to keep it in sync -->
14-
<NETTestSdkVersion>16.9.1-dev</NETTestSdkVersion>
14+
<NETTestSdkVersion>16.9.4-dev</NETTestSdkVersion>
1515

1616
<MSTestFrameworkVersion>2.1.0</MSTestFrameworkVersion>
1717
<MSTestAdapterVersion>2.1.0</MSTestAdapterVersion>
@@ -32,7 +32,7 @@
3232
<JsonNetVersion>9.0.1</JsonNetVersion>
3333
<MoqVersion>4.7.63</MoqVersion>
3434
<TestPlatformExternalsVersion>16.9.0-preview-4267359</TestPlatformExternalsVersion>
35-
<CodeCoverageExternalsVersion>16.9.0-beta.21119.4</CodeCoverageExternalsVersion>
35+
<CodeCoverageExternalsVersion>16.9.0-beta.21158.1</CodeCoverageExternalsVersion>
3636
<MicrosoftFakesVersion>16.9.0-beta.20628.1</MicrosoftFakesVersion>
3737

3838
<MicrosoftBuildPackageVersion>16.0.461</MicrosoftBuildPackageVersion>

scripts/build/TestPlatform.Settings.targets

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<!-- This version is read by vsts-prebuild.ps1 and is a base for the current version, this should be updated
66
at the start of new iteration to the goal number. This is also used to version the local packages. This version needs to be statically
77
readable when we read the file as xml, don't move it to a .props file, unless you change the build server process -->
8-
<TPVersionPrefix>16.9.1</TPVersionPrefix>
8+
<TPVersionPrefix>16.9.4</TPVersionPrefix>
99
</PropertyGroup>
1010
<PropertyGroup>
1111
<!-- Versioning is defined from the build script. Use a default dev build if it's not defined.

scripts/verify-nupkgs.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function Verify-Nuget-Packages($packageDirectory, $version)
1616
"Microsoft.NET.Test.Sdk" = 27;
1717
"Microsoft.TestPlatform" = 515;
1818
"Microsoft.TestPlatform.Build" = 21;
19-
"Microsoft.TestPlatform.CLI" = 381;
19+
"Microsoft.TestPlatform.CLI" = 366;
2020
"Microsoft.TestPlatform.Extensions.TrxLogger" = 35;
2121
"Microsoft.TestPlatform.ObjectModel" = 180;
2222
"Microsoft.TestPlatform.AdapterUtilities" = 48;

src/Microsoft.TestPlatform.Utilities/CodeCoverageDataAttachmentsHandler.cs

+28-12
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,34 @@ namespace Microsoft.VisualStudio.TestPlatform.Utilities
88
using System.Collections.ObjectModel;
99
using System.IO;
1010
using System.Linq;
11+
using System.Reflection;
1112
using System.Threading;
1213
using System.Threading.Tasks;
1314

14-
using Microsoft.VisualStudio.Coverage.CoreLib.Net;
1515
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
1616
using Microsoft.VisualStudio.TestPlatform.ObjectModel.DataCollection;
1717
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;
18+
using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions;
1819

1920
public class CodeCoverageDataAttachmentsHandler : IDataCollectorAttachmentProcessor
2021
{
2122
private const string CoverageUri = "datacollector://microsoft/CodeCoverage/2.0";
2223
private const string CoverageFileExtension = ".coverage";
2324
private const string CoverageFriendlyName = "Code Coverage";
2425

26+
private const string CodeCoverageCoreLibNetAssemblyName = "Microsoft.VisualStudio.Coverage.CoreLib.Net";
27+
private const string CoverageFileUtilityTypeName = "CoverageFileUtility";
28+
private const string MergeMethodName = "MergeCoverageFilesAsync";
29+
private const string WriteMethodName = "WriteCoverageFile";
30+
2531
private static readonly Uri CodeCoverageDataCollectorUri = new Uri(CoverageUri);
2632

2733
public bool SupportsIncrementalProcessing => true;
2834

2935
public IEnumerable<Uri> GetExtensionUris()
3036
{
3137
yield return CodeCoverageDataCollectorUri;
32-
}
38+
}
3339

3440
public async Task<ICollection<AttachmentSet>> ProcessAttachmentSetsAsync(ICollection<AttachmentSet> attachments, IProgress<int> progressReporter, IMessageLogger logger, CancellationToken cancellationToken)
3541
{
@@ -53,7 +59,7 @@ public async Task<ICollection<AttachmentSet>> ProcessAttachmentSetsAsync(ICollec
5359
}
5460
}
5561

56-
if(coverageReportFilePaths.Count > 1)
62+
if (coverageReportFilePaths.Count > 1)
5763
{
5864
var mergedCoverageReportFilePath = await this.MergeCodeCoverageFilesAsync(coverageReportFilePaths, progressReporter, cancellationToken).ConfigureAwait(false);
5965
if (!string.IsNullOrEmpty(mergedCoverageReportFilePath))
@@ -106,15 +112,25 @@ private async Task<string> MergeCodeCoverageFilesAsync(IList<string> files, IPro
106112

107113
private async Task<string> MergeCodeCoverageFilesAsync(IList<string> files, CancellationToken cancellationToken)
108114
{
109-
var coverageUtility = new CoverageFileUtility();
110-
111-
var coverageData = await coverageUtility.MergeCoverageFilesAsync(
112-
files,
113-
cancellationToken).ConfigureAwait(false);
114-
115-
coverageUtility.WriteCoverageFile(files[0], coverageData);
116-
117-
foreach(var file in files.Skip(1))
115+
cancellationToken.ThrowIfCancellationRequested();
116+
117+
var assemblyPath = Path.Combine(Path.GetDirectoryName(typeof(CodeCoverageDataAttachmentsHandler).GetTypeInfo().Assembly.GetAssemblyLocation()), CodeCoverageCoreLibNetAssemblyName + ".dll");
118+
119+
// Get assembly, type and methods
120+
Assembly assembly = new PlatformAssemblyLoadContext().LoadAssemblyFromPath(assemblyPath);
121+
var classType = assembly.GetType($"{CodeCoverageCoreLibNetAssemblyName}.{CoverageFileUtilityTypeName}");
122+
var classInstance = Activator.CreateInstance(classType);
123+
var mergeMethodInfo = classType?.GetMethod(MergeMethodName, new[] { typeof(IList<string>), typeof(CancellationToken) });
124+
var writeMethodInfo = classType?.GetMethod(WriteMethodName);
125+
126+
// Invoke methods
127+
var task = (Task)mergeMethodInfo.Invoke(classInstance, new object[] { files, cancellationToken });
128+
await task.ConfigureAwait(false);
129+
var coverageData = task.GetType().GetProperty("Result").GetValue(task, null);
130+
writeMethodInfo.Invoke(classInstance, new object[] { files[0], coverageData });
131+
132+
// Delete original files and keep merged file only
133+
foreach (var file in files.Skip(1))
118134
{
119135
try
120136
{

src/Microsoft.TestPlatform.Utilities/Microsoft.TestPlatform.Utilities.csproj

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
<ItemGroup>
1616
<ProjectReference Include="..\Microsoft.TestPlatform.CoreUtilities\Microsoft.TestPlatform.CoreUtilities.csproj" />
1717
<ProjectReference Include="..\Microsoft.TestPlatform.ObjectModel\Microsoft.TestPlatform.ObjectModel.csproj" />
18-
<PackageReference Include="Microsoft.VisualStudio.Coverage.CoreLib.Net" Version="$(CodeCoverageExternalsVersion)" />
1918
</ItemGroup>
2019
<ItemGroup Condition="'$(TargetFramework)' == 'net451' ">
2120
<Reference Include="System" />

0 commit comments

Comments
 (0)