Skip to content
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

Remove dependency on Nuget.Frameworks #4693

Merged
merged 15 commits into from Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion eng/SourceBuildPrebuiltBaseline.xml
Expand Up @@ -6,7 +6,6 @@
<!-- Caused by dependency on System.ComponentModel.Composition.4.5.0. This version is overridden in full source-build. -->
<UsagePattern IdentityGlob="Microsoft.NETCore.Platforms/2.0.0" />
<UsagePattern IdentityGlob="Microsoft.SourceBuild.Intermediate.*/*" />
<UsagePattern IdentityGlob="NuGet.Frameworks/6.5.0" />
<!-- This version is overridden in full source-build. -->
<UsagePattern IdentityGlob="System.ComponentModel.Composition/4.5.0" />
<!-- Caused by dependency on System.ComponentModel.Composition.4.5.0. This version is overridden in full source-build. -->
Expand Down
4 changes: 0 additions & 4 deletions eng/Version.Details.xml
Expand Up @@ -24,10 +24,6 @@
<Sha>0030d238c7929b0e9b06576837b60ad90037b1d2</Sha>
<SourceBuild RepoName="source-build-reference-packages" ManagedOnly="true" />
</Dependency>
<Dependency Name="NuGet.Frameworks" Version="6.5.0">
<Uri>https://github.com/nuget/nuget.client</Uri>
<Sha>4ba7bfa82f894ec32a554ca8d2df143675c85735</Sha>
</Dependency>
<!-- Necessary for source-build. This allows the live version of the package to be used by source-build. -->
<Dependency Name="System.ComponentModel.Composition" Version="4.5.0">
<Uri>https://github.com/dotnet/corefx</Uri>
Expand Down
4 changes: 0 additions & 4 deletions eng/Versions.props
Expand Up @@ -90,10 +90,6 @@
<VSTestConsoleMostDownloadedVersion>[16.6.1]</VSTestConsoleMostDownloadedVersion>
<VSTestConsolePreviousStableVersion>[16.11.0]</VSTestConsolePreviousStableVersion>
<VSTestConsoleLegacyStableVersion>[15.9.2]</VSTestConsoleLegacyStableVersion>
<!-- This version also needs to be updated in src\Microsoft.TestPlatform.ObjectModel\Microsoft.TestPlatform.ObjectModel.nuspec -->
<!-- This version needs to be the same or lower than <NuGetFrameworksPackageVersion> https://github.com/dotnet/sdk/blob/release/main/eng/Versions.props
(or the respective branch. It also needs to be on nuget.org. -->
<NuGetFrameworksVersion>6.5.0</NuGetFrameworksVersion>
<ILAsmPackageVersion>5.0.0</ILAsmPackageVersion>
</PropertyGroup>
</Project>
6 changes: 3 additions & 3 deletions eng/verify-nupkgs.ps1
Expand Up @@ -16,13 +16,13 @@ function Verify-Nuget-Packages {
$expectedNumOfFiles = @{
"Microsoft.CodeCoverage" = 59;
"Microsoft.NET.Test.Sdk" = 16;
"Microsoft.TestPlatform" = 607;
"Microsoft.TestPlatform" = 605;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$path = "S:\p\vstest3\artifacts\packages\Debug\Shipping"; (ls $path -re -fo | where { $_.FullName -notlike "*Symbols*" -and $_.Name -eq "Nuget.Frameworks.dll" }  | % fullName) -replace [regex]::escape($path)

\Microsoft.TestPlatform.17.8.0-dev\tools\net462\Common7\IDE\Extensions\TestPlatform\NuGet.Frameworks.dll
\Microsoft.TestPlatform.17.8.0-dev\tools\net462\Common7\IDE\Extensions\TestPlatform\TestHostNet\NuGet.Frameworks.dll

\Microsoft.TestPlatform.CLI.17.8.0-dev\contentFiles\any\netcoreapp3.1\NuGet.Frameworks.dll
\Microsoft.TestPlatform.CLI.17.8.0-dev\contentFiles\any\netcoreapp3.1\TestHostNetFramework\NuGet.Frameworks.dll

\Microsoft.TestPlatform.Portable.17.8.0-dev\tools\net462\NuGet.Frameworks.dll
\Microsoft.TestPlatform.Portable.17.8.0-dev\tools\netcoreapp3.1\NuGet.Frameworks.dll
\Microsoft.TestPlatform.Portable.17.8.0-dev\tools\netcoreapp3.1\TestHostNetFramework\NuGet.Frameworks.dll

which is count reduction by 2, 2 and 3 just like here.

"Microsoft.TestPlatform.Build" = 21;
"Microsoft.TestPlatform.CLI" = 472;
"Microsoft.TestPlatform.CLI" = 470;
"Microsoft.TestPlatform.Extensions.TrxLogger" = 35;
"Microsoft.TestPlatform.ObjectModel" = 93;
"Microsoft.TestPlatform.AdapterUtilities" = 34;
"Microsoft.TestPlatform.Portable" = 595;
"Microsoft.TestPlatform.Portable" = 592;
"Microsoft.TestPlatform.TestHost" = 63;
"Microsoft.TestPlatform.TranslationLayer" = 123;
"Microsoft.TestPlatform.Internal.Uwp" = 39;
Expand Down
84 changes: 84 additions & 0 deletions scripts/update-nuget-frameworks.ps1
@@ -0,0 +1,84 @@
$root = Resolve-Path "$PSScriptRoot/.."

$source = "S:\c\NuGet.Client"

$destination = "$root/src/Microsoft.TestPlatform.ObjectModel/Nuget.Frameworks/"

$frameworksPath = "$source/src/NuGet.Core/NuGet.Frameworks"
$frameworkItems = @(
"Strings.Designer.cs"
"DefaultFrameworkMappings.cs"
"DefaultFrameworkNameProvider.cs"
"DefaultPortableFrameworkMappings.cs"
"DefaultCompatibilityProvider.cs"
"CompatibilityProvider.cs"
"FrameworkConstants.cs"
"FrameworkException.cs"
"FrameworkNameProvider.cs"
"FrameworkRange.cs"
"FrameworkReducer.cs"
"FrameworkNameHelpers.cs",
"FrameworkSpecificMapping.cs"
"FallbackFramework.cs"
"FrameworkExpander.cs"
"CompatibilityCacheKey.cs"
"def/IFrameworkCompatibilityListProvider.cs"
"def/IFrameworkCompatibilityProvider.cs"
"def/IFrameworkMappings.cs"
"def/IFrameworkNameProvider.cs"
"def/IFrameworkSpecific.cs"
"def/IPortableFrameworkMappings.cs"
"NuGetFramework.cs"
"NuGetFrameworkFactory.cs"
"comparers/NuGetFrameworkFullComparer.cs"
"comparers/NuGetFrameworkNameComparer.cs"
"comparers/CompatibilityMappingComparer.cs"
"comparers/FrameworkRangeComparer.cs"
"comparers/NuGetFrameworkSorter.cs"
"comparers/FrameworkPrecedenceSorter.cs"
"NuGetFrameworkUtility.cs"
"OneWayCompatibilityMappingEntry.cs"
) | ForEach-Object { "$frameworksPath/$_" }

$extraItems = @(
".editorconfig"
"build/Shared/HashCodeCombiner.cs"
"build/Shared/NoAllocEnumerateExtensions.cs"
"build/Shared/StringBuilderPool.cs"
"build/Shared/SimplePool.cs"
) | ForEach-Object { "$source/$_" }

if ((Test-Path $destination)) {
Remove-Item $destination -Force -Recurse
}

New-Item -ItemType Directory $destination -ErrorAction Ignore | Out-Null
foreach ($item in $frameworkItems + $extraItems) {
if (-not (Test-Path $item)) {
throw "File not found $item"
}
$content = Get-Content $item
$name = (Get-Item $item).Name

$path = "$destination/$name"

# some types are directly in Nuget namespace, and if we would suffix
# .Clone, then Nuget.Frameworks.Clone is no longer autometicaly using
# Nuget.Clone, and we would have to add more usings into the files.
$finalContent = $content `
-replace 'public(.*)(class|interface)', 'internal$1$2' `
-replace 'namespace NuGet', 'namespace NuGetClone' `
-replace 'using NuGet', 'using NuGetClone' `
-replace 'NuGet.Frameworks.NuGetFramework', 'NuGetClone.Frameworks.NuGetFramework'

if ($name -eq ".editorconfig") {
$finalContent += @"

[*.{cs,vb}]
dotnet_diagnostic.IDE0001.severity = none
dotnet_diagnostic.IDE0005.severity = none
dotnet_diagnostic.IDE1006.severity = none
"@
}
$finalContent | Set-Content -Path $path -Encoding utf8NoBOM
}
Expand Up @@ -7,8 +7,6 @@
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers;

using NuGet.Frameworks;

namespace Microsoft.TestPlatform.Extensions.BlameDataCollector;

internal class CrashDumperFactory : ICrashDumperFactory
Expand All @@ -18,15 +16,15 @@ public ICrashDumper Create(string targetFramework)
ValidateArg.NotNull(targetFramework, nameof(targetFramework));
EqtTrace.Info($"CrashDumperFactory: Creating dumper for {RuntimeInformation.OSDescription} with target framework {targetFramework}.");

var tfm = NuGetFramework.Parse(targetFramework);
var tfm = Framework.FromString(targetFramework);

if (tfm == null || tfm.IsUnsupported)
if (tfm == null)
{
EqtTrace.Error($"CrashDumperFactory: Could not parse target framework {targetFramework}, to a supported framework version.");
throw new NotSupportedException($"Could not parse target framework {targetFramework}, to a supported framework version.");
}

var isNet50OrNewer = tfm.Framework == ".NETCoreApp" && tfm.Version >= Version.Parse("5.0.0.0");
var isNet50OrNewer = tfm.FrameworkName == ".NETCoreApp" && Version.Parse(tfm.Version) >= Version.Parse("5.0.0.0");

if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
Expand Down
Expand Up @@ -7,8 +7,6 @@
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions;

using NuGet.Frameworks;

namespace Microsoft.TestPlatform.Extensions.BlameDataCollector;

internal class HangDumperFactory : IHangDumperFactory
Expand All @@ -24,9 +22,9 @@ public IHangDumper Create(string targetFramework)
var netdumpOverride = Environment.GetEnvironmentVariable("VSTEST_DUMP_FORCENETDUMP")?.Trim();
EqtTrace.Verbose($"HangDumperFactory: Overrides for dumpers: VSTEST_DUMP_FORCEPROCDUMP={procdumpOverride};VSTEST_DUMP_FORCENETDUMP={netdumpOverride}");

var tfm = NuGetFramework.Parse(targetFramework);
var tfm = Framework.FromString(targetFramework);

if (tfm == null || tfm.IsUnsupported)
if (tfm == null)
{
EqtTrace.Error($"HangDumperFactory: Could not parse target framework {targetFramework}, to a supported framework version.");
throw new NotSupportedException($"Could not parse target framework {targetFramework}, to a supported framework version.");
Expand All @@ -46,15 +44,15 @@ public IHangDumper Create(string targetFramework)
var forceUsingNetdump = !netdumpOverride.IsNullOrWhiteSpace() && netdumpOverride != "0";
if (forceUsingNetdump)
{
var isLessThan50 = tfm.Framework == ".NETCoreApp" && tfm.Version < Version.Parse("5.0.0.0");
var isLessThan50 = tfm.FrameworkName == ".NETCoreApp" && Version.Parse(tfm.Version) < Version.Parse("5.0.0.0");
if (!isLessThan50)
{
EqtTrace.Info($"HangDumperFactory: This is Windows on {tfm.Framework} {tfm.Version}, VSTEST_DUMP_FORCENETDUMP={netdumpOverride} is active, forcing use of .NetClientHangDumper");
EqtTrace.Info($"HangDumperFactory: This is Windows on {tfm.FrameworkName} {tfm.Version}, VSTEST_DUMP_FORCENETDUMP={netdumpOverride} is active, forcing use of .NetClientHangDumper");
return new NetClientHangDumper();
}
else
{
EqtTrace.Info($"HangDumperFactory: This is Windows on {tfm.Framework} {tfm.Version}, VSTEST_DUMP_FORCENETDUMP={netdumpOverride} is active, but only applies to .NET 5.0 and newer. Falling back to default hang dumper.");
EqtTrace.Info($"HangDumperFactory: This is Windows on {tfm.FrameworkName} {tfm.Version}, VSTEST_DUMP_FORCENETDUMP={netdumpOverride} is active, but only applies to .NET 5.0 and newer. Falling back to default hang dumper.");
}
}

Expand All @@ -64,7 +62,7 @@ public IHangDumper Create(string targetFramework)

if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
var isLessThan31 = tfm.Framework == ".NETCoreApp" && tfm.Version < Version.Parse("3.1.0.0");
var isLessThan31 = tfm.FrameworkName == ".NETCoreApp" && Version.Parse(tfm.Version) < Version.Parse("3.1.0.0");
if (isLessThan31)
{
EqtTrace.Info($"HangDumperFactory: This is Linux on netcoreapp2.1, returning SigtrapDumper.");
Expand All @@ -78,7 +76,7 @@ public IHangDumper Create(string targetFramework)

if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
var isLessThan50 = tfm.Framework == ".NETCoreApp" && tfm.Version < Version.Parse("5.0.0.0");
var isLessThan50 = tfm.FrameworkName == ".NETCoreApp" && Version.Parse(tfm.Version) < Version.Parse("5.0.0.0");
if (isLessThan50)
{
EqtTrace.Info($"HangDumperFactory: This is OSX on {targetFramework}, This combination of OS and framework is not supported.");
Expand Down
Expand Up @@ -18,8 +18,6 @@
using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers;
using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces;

using NuGet.Frameworks;

using HtmlLoggerConstants = Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.Constants;
using HtmlResource = Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.Resources.Resources;

Expand Down Expand Up @@ -285,7 +283,7 @@ public void TestRunCompleteHandler(object? sender, TestRunCompleteEventArgs e)
var framework = _parametersDictionary[DefaultLoggerParameterNames.TargetFramework];
if (framework != null)
{
framework = NuGetFramework.Parse(framework).GetShortFolderName();
framework = Framework.FromString(framework)?.ShortName ?? framework;
logFilePrefixValue = logFilePrefixValue + "_" + framework;
}

Expand Down
4 changes: 1 addition & 3 deletions src/Microsoft.TestPlatform.Extensions.TrxLogger/TrxLogger.cs
Expand Up @@ -20,8 +20,6 @@
using Microsoft.VisualStudio.TestPlatform.Utilities;
using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces;

using NuGet.Frameworks;

using ObjectModelConstants = Microsoft.VisualStudio.TestPlatform.ObjectModel.Constants;
using TrxLoggerConstants = Microsoft.TestPlatform.Extensions.TrxLogger.Utility.Constants;
using TrxLoggerObjectModel = Microsoft.TestPlatform.Extensions.TrxLogger.ObjectModel;
Expand Down Expand Up @@ -489,7 +487,7 @@ private string AcquireTrxFileNamePath(out bool shouldOverwrite)
{
if (_parametersDictionary.TryGetValue(DefaultLoggerParameterNames.TargetFramework, out var framework) && framework != null)
{
framework = NuGetFramework.Parse(framework).GetShortFolderName();
framework = Framework.FromString(framework)?.ShortName ?? framework;
logFilePrefixValue = logFilePrefixValue + "_" + framework;
}

Expand Down
59 changes: 36 additions & 23 deletions src/Microsoft.TestPlatform.ObjectModel/Framework.cs
Expand Up @@ -5,9 +5,7 @@

using System.Globalization;

using NuGet.Frameworks;

using static NuGet.Frameworks.FrameworkConstants;
using NuGetClone.Frameworks;

namespace Microsoft.VisualStudio.TestPlatform.ObjectModel;

Expand Down Expand Up @@ -36,6 +34,16 @@ private Framework()
/// </summary>
public string Name { get; private set; }

/// <summary>
/// Gets the framework name such as .NETCoreApp.
/// </summary>
public string FrameworkName { get; private set; }

/// <summary>
/// Common short name, as well as directory name, such as net5.0.
/// </summary>
public string ShortName { get; private set; }

/// <summary>
/// Gets the framework version.
/// </summary>
Expand All @@ -53,56 +61,61 @@ private Framework()
return null;
}

string name, version;
string name, frameworkName, shortName, version;
try
{
// IDE always sends framework in form of ENUM, which always throws exception
// This throws up in first chance exception, refer Bug https://devdiv.visualstudio.com/DefaultCollection/DevDiv/_workitems/edit/591142
var formattedFrameworkString = frameworkString.Trim().ToLower(CultureInfo.InvariantCulture);
string? mappedShortName = null;
switch (formattedFrameworkString)
{
case "framework35":
name = CommonFrameworks.Net35.DotNetFrameworkName;
version = CommonFrameworks.Net35.Version.ToString();
mappedShortName = "net3.5";
break;

case "framework40":
name = CommonFrameworks.Net4.DotNetFrameworkName;
version = CommonFrameworks.Net4.Version.ToString();
mappedShortName = "net4.0";
break;

case "framework45":
name = CommonFrameworks.Net45.DotNetFrameworkName;
version = CommonFrameworks.Net45.Version.ToString();
mappedShortName = "net4.5";
break;

case "frameworkcore10":
name = CommonFrameworks.NetCoreApp10.DotNetFrameworkName;
version = CommonFrameworks.NetCoreApp10.Version.ToString();
mappedShortName = "netcoreapp1.0";
break;

case "frameworkuap10":
name = CommonFrameworks.UAP10.DotNetFrameworkName;
version = CommonFrameworks.UAP10.Version.ToString();
mappedShortName = "uap10.0";
break;
}

if (mappedShortName != null)
{
frameworkString = mappedShortName;
}

default:
var nugetFramework = NuGetFramework.Parse(frameworkString);
if (nugetFramework.IsUnsupported)
return null;
var nugetFramework = NuGetFramework.Parse(frameworkString);
if (nugetFramework.IsUnsupported)
return null;

name = nugetFramework.DotNetFrameworkName;
version = nugetFramework.Version.ToString();
// e.g. .NETFramework,Version=v3.5
name = nugetFramework.DotNetFrameworkName;
// e.g. net35
shortName = nugetFramework.GetShortFolderName();
// e.g. .NETFramework
frameworkName = nugetFramework.Framework;
// e.g. 3.5.0.0
version = nugetFramework.Version.ToString();

break;
}
}
catch
{
return null;
}

return new Framework() { Name = name, Version = version };
return new Framework() { Name = name, ShortName = shortName, FrameworkName = frameworkName, Version = version };
}

/// <summary>
Expand Down
Expand Up @@ -4,6 +4,8 @@
<PropertyGroup>
<AssemblyName>Microsoft.VisualStudio.TestPlatform.ObjectModel</AssemblyName>
<TargetFrameworks>net7.0;$(NetFrameworkMinimum);$(NetCoreAppMinimum);netstandard2.0;</TargetFrameworks>
<!-- Suppress warning that is caused by Nuget.Frameworks code that we copy. -->
<NoWarn>$(NoWarn);SYSLIB0051</NoWarn>
</PropertyGroup>

<PropertyGroup>
Expand Down Expand Up @@ -32,7 +34,6 @@

<ItemGroup>
<PackageReference Include="System.Reflection.Metadata" Version="1.6.0" />
<PackageReference Include="NuGet.Frameworks" Version="$(NuGetFrameworksVersion)" />
</ItemGroup>

<ItemGroup>
Expand Down
Expand Up @@ -6,17 +6,14 @@
<dependencies>
<group targetFramework="net462">
<dependency id="System.Reflection.Metadata" version="[1.6.0, )" />
<dependency id="NuGet.Frameworks" version="[6.5.0, )" />
</group>

<group targetFramework="netcoreapp3.1">
<dependency id="System.Reflection.Metadata" version="[1.6.0, )" />
<dependency id="NuGet.Frameworks" version="[6.5.0, )" />
</group>

<group targetFramework="netstandard2.0">
<dependency id="System.Reflection.Metadata" version="[1.6.0, )" />
<dependency id="NuGet.Frameworks" version="[6.5.0, )" />
</group>
</dependencies>

Expand Down