From e4ea95c0486876cd5ebee51ca6c362ad52e39182 Mon Sep 17 00:00:00 2001 From: fhnaseer Date: Mon, 8 Mar 2021 13:36:38 +0100 Subject: [PATCH 1/3] Dynamic corelib.net loading (#2762) (#2803) * First working version, * Calling async method, * Cleaning code, * Reverting changes, * Fixing test, * Copy to output required libs to fix tests * Next fix Co-authored-by: Jakub Chocholowicz Co-authored-by: Jakub Chocholowicz --- scripts/build.ps1 | 15 +++++++ scripts/build/TestPlatform.Dependencies.props | 2 +- scripts/verify-nupkgs.ps1 | 2 +- .../CodeCoverageDataAttachmentsHandler.cs | 40 +++++++++++++------ .../Microsoft.TestPlatform.Utilities.csproj | 1 - 5 files changed, 45 insertions(+), 15 deletions(-) diff --git a/scripts/build.ps1 b/scripts/build.ps1 index b80ccd4bcd..b92c2b1176 100644 --- a/scripts/build.ps1 +++ b/scripts/build.ps1 @@ -573,6 +573,14 @@ function Publish-Package Copy-Loc-Files $eventLogDataCollectorNetFull $coreCLRExtensionsDir "Microsoft.TestPlatform.Extensions.EventLogCollector.resources.dll" } + # Copy Coverage.CoreLib.Net dlls + $codeCoverageExternalsVersion = ([xml](Get-Content $env:TP_ROOT_DIR\scripts\build\TestPlatform.Dependencies.props)).Project.PropertyGroup.CodeCoverageExternalsVersion + $codeCoverageCoreLibPackagesDir = Join-Path $env:TP_PACKAGES_DIR "microsoft.visualstudio.coverage.corelib.net\$codeCoverageExternalsVersion\lib\$TPB_TargetFrameworkStandard" + Copy-Item $codeCoverageCoreLibPackagesDir\Microsoft.VisualStudio.Coverage.CoreLib.Net.dll $coreCLR20PackageDir -Force + if($TPB_LocalizedBuild) { + Copy-Loc-Files $codeCoverageCoreLibPackagesDir $coreCLR20PackageDir "Microsoft.VisualStudio.Coverage.CoreLib.Net.resources.dll" + } + # If there are some dependencies for the TestHostRuntimeProvider assemblies, those need to be moved too. $runtimeproviders = @("Microsoft.TestPlatform.TestHostRuntimeProvider.dll", "Microsoft.TestPlatform.TestHostRuntimeProvider.pdb") foreach($file in $runtimeproviders) { @@ -736,6 +744,13 @@ function Create-VsixPackage if($TPB_LocalizedBuild) { Copy-Loc-Files $traceDataCollectorPackageDirectory $extensionsPackageDir "Microsoft.VisualStudio.TraceDataCollector.resources.dll" } + + # Copy Microsoft.VisualStudio.CoreLib.Net + $codeCoverageCoreLibPackagesDir = Join-Path $env:TP_PACKAGES_DIR "microsoft.visualstudio.coverage.corelib.net\$codeCoverageExternalsVersion\lib\$TPB_TargetFramework451" + Copy-Item $codeCoverageCoreLibPackagesDir\Microsoft.VisualStudio.Coverage.CoreLib.Net.dll $packageDir -Force + if($TPB_LocalizedBuild) { + Copy-Loc-Files $codeCoverageCoreLibPackagesDir $packageDir "Microsoft.VisualStudio.Coverage.CoreLib.Net.resources.dll" + } $codeCoverageInterprocessPackageDirectory = Join-Path $env:TP_PACKAGES_DIR "Microsoft.VisualStudio.Coverage.Interprocess\$codeCoverageExternalsVersion\lib\$TPB_TargetFrameworkNS20" Copy-Item $codeCoverageInterprocessPackageDirectory\Microsoft.VisualStudio.Coverage.Interprocess.dll $extensionsPackageDir -Force diff --git a/scripts/build/TestPlatform.Dependencies.props b/scripts/build/TestPlatform.Dependencies.props index 3d5fe97b47..efa91c881a 100644 --- a/scripts/build/TestPlatform.Dependencies.props +++ b/scripts/build/TestPlatform.Dependencies.props @@ -32,7 +32,7 @@ 9.0.1 4.7.63 16.9.0-preview-4267359 - 16.9.0-beta.21119.4 + 16.9.0-beta.21158.1 16.9.0-beta.20628.1 16.0.461 diff --git a/scripts/verify-nupkgs.ps1 b/scripts/verify-nupkgs.ps1 index 1ac89ac370..2c06c0ea67 100644 --- a/scripts/verify-nupkgs.ps1 +++ b/scripts/verify-nupkgs.ps1 @@ -16,7 +16,7 @@ function Verify-Nuget-Packages($packageDirectory, $version) "Microsoft.NET.Test.Sdk" = 27; "Microsoft.TestPlatform" = 515; "Microsoft.TestPlatform.Build" = 21; - "Microsoft.TestPlatform.CLI" = 381; + "Microsoft.TestPlatform.CLI" = 366; "Microsoft.TestPlatform.Extensions.TrxLogger" = 35; "Microsoft.TestPlatform.ObjectModel" = 180; "Microsoft.TestPlatform.AdapterUtilities" = 48; diff --git a/src/Microsoft.TestPlatform.Utilities/CodeCoverageDataAttachmentsHandler.cs b/src/Microsoft.TestPlatform.Utilities/CodeCoverageDataAttachmentsHandler.cs index 46cd936844..7d32f4634d 100644 --- a/src/Microsoft.TestPlatform.Utilities/CodeCoverageDataAttachmentsHandler.cs +++ b/src/Microsoft.TestPlatform.Utilities/CodeCoverageDataAttachmentsHandler.cs @@ -8,13 +8,14 @@ namespace Microsoft.VisualStudio.TestPlatform.Utilities using System.Collections.ObjectModel; using System.IO; using System.Linq; + using System.Reflection; using System.Threading; using System.Threading.Tasks; - using Microsoft.VisualStudio.Coverage.CoreLib.Net; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.DataCollection; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; + using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions; public class CodeCoverageDataAttachmentsHandler : IDataCollectorAttachmentProcessor { @@ -22,6 +23,11 @@ public class CodeCoverageDataAttachmentsHandler : IDataCollectorAttachmentProces private const string CoverageFileExtension = ".coverage"; private const string CoverageFriendlyName = "Code Coverage"; + private const string CodeCoverageCoreLibNetAssemblyName = "Microsoft.VisualStudio.Coverage.CoreLib.Net"; + private const string CoverageFileUtilityTypeName = "CoverageFileUtility"; + private const string MergeMethodName = "MergeCoverageFilesAsync"; + private const string WriteMethodName = "WriteCoverageFile"; + private static readonly Uri CodeCoverageDataCollectorUri = new Uri(CoverageUri); public bool SupportsIncrementalProcessing => true; @@ -29,7 +35,7 @@ public class CodeCoverageDataAttachmentsHandler : IDataCollectorAttachmentProces public IEnumerable GetExtensionUris() { yield return CodeCoverageDataCollectorUri; - } + } public async Task> ProcessAttachmentSetsAsync(ICollection attachments, IProgress progressReporter, IMessageLogger logger, CancellationToken cancellationToken) { @@ -53,7 +59,7 @@ public async Task> ProcessAttachmentSetsAsync(ICollec } } - if(coverageReportFilePaths.Count > 1) + if (coverageReportFilePaths.Count > 1) { var mergedCoverageReportFilePath = await this.MergeCodeCoverageFilesAsync(coverageReportFilePaths, progressReporter, cancellationToken).ConfigureAwait(false); if (!string.IsNullOrEmpty(mergedCoverageReportFilePath)) @@ -106,15 +112,25 @@ private async Task MergeCodeCoverageFilesAsync(IList files, IPro private async Task MergeCodeCoverageFilesAsync(IList files, CancellationToken cancellationToken) { - var coverageUtility = new CoverageFileUtility(); - - var coverageData = await coverageUtility.MergeCoverageFilesAsync( - files, - cancellationToken).ConfigureAwait(false); - - coverageUtility.WriteCoverageFile(files[0], coverageData); - - foreach(var file in files.Skip(1)) + cancellationToken.ThrowIfCancellationRequested(); + + var assemblyPath = Path.Combine(Path.GetDirectoryName(typeof(CodeCoverageDataAttachmentsHandler).GetTypeInfo().Assembly.GetAssemblyLocation()), CodeCoverageCoreLibNetAssemblyName + ".dll"); + + // Get assembly, type and methods + Assembly assembly = new PlatformAssemblyLoadContext().LoadAssemblyFromPath(assemblyPath); + var classType = assembly.GetType($"{CodeCoverageCoreLibNetAssemblyName}.{CoverageFileUtilityTypeName}"); + var classInstance = Activator.CreateInstance(classType); + var mergeMethodInfo = classType?.GetMethod(MergeMethodName, new[] { typeof(IList), typeof(CancellationToken) }); + var writeMethodInfo = classType?.GetMethod(WriteMethodName); + + // Invoke methods + var task = (Task)mergeMethodInfo.Invoke(classInstance, new object[] { files, cancellationToken }); + await task.ConfigureAwait(false); + var coverageData = task.GetType().GetProperty("Result").GetValue(task, null); + writeMethodInfo.Invoke(classInstance, new object[] { files[0], coverageData }); + + // Delete original files and keep merged file only + foreach (var file in files.Skip(1)) { try { diff --git a/src/Microsoft.TestPlatform.Utilities/Microsoft.TestPlatform.Utilities.csproj b/src/Microsoft.TestPlatform.Utilities/Microsoft.TestPlatform.Utilities.csproj index 7d1416479c..30a3cf6101 100644 --- a/src/Microsoft.TestPlatform.Utilities/Microsoft.TestPlatform.Utilities.csproj +++ b/src/Microsoft.TestPlatform.Utilities/Microsoft.TestPlatform.Utilities.csproj @@ -15,7 +15,6 @@ - From 07cb56ff9f0cfec85ce050760f9e29dfc955be20 Mon Sep 17 00:00:00 2001 From: Medeni Baykal <433724+Haplois@users.noreply.github.com> Date: Wed, 17 Mar 2021 15:47:44 +0100 Subject: [PATCH 2/3] Updated version to 16.9.2 (#2824) ## Description Updated TP version to 16.9.2 --- scripts/build/TestPlatform.Dependencies.props | 2 +- scripts/build/TestPlatform.Settings.targets | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/build/TestPlatform.Dependencies.props b/scripts/build/TestPlatform.Dependencies.props index efa91c881a..68e85eb663 100644 --- a/scripts/build/TestPlatform.Dependencies.props +++ b/scripts/build/TestPlatform.Dependencies.props @@ -11,7 +11,7 @@ - 16.9.1-dev + 16.9.2-dev 2.1.0 2.1.0 diff --git a/scripts/build/TestPlatform.Settings.targets b/scripts/build/TestPlatform.Settings.targets index 0f80133468..829ebbba00 100644 --- a/scripts/build/TestPlatform.Settings.targets +++ b/scripts/build/TestPlatform.Settings.targets @@ -5,7 +5,7 @@ - 16.9.1 + 16.9.2 - 16.9.2-dev + 16.9.4-dev 2.1.0 2.1.0 diff --git a/scripts/build/TestPlatform.Settings.targets b/scripts/build/TestPlatform.Settings.targets index 829ebbba00..1ba4ffbcba 100644 --- a/scripts/build/TestPlatform.Settings.targets +++ b/scripts/build/TestPlatform.Settings.targets @@ -5,7 +5,7 @@ - 16.9.2 + 16.9.4