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 14 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
17 changes: 17 additions & 0 deletions THIRD-PARTY-NOTICES.txt
Expand Up @@ -32,3 +32,20 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

License notice for NuGet.Client (NuGet.Frameworks)
--------------------------------------------------
Copyright (c) .NET Foundation and Contributors.

All rights reserved.


Licensed under the Apache License, Version 2.0 (the "License"); you may not use
these files except in compliance with the License. You may obtain a copy of the
License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
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
117 changes: 117 additions & 0 deletions scripts/update-nuget-frameworks.ps1
@@ -0,0 +1,117 @@
param (
[String] $VersionTag = "6.8.0.117"
)

$root = Resolve-Path "$PSScriptRoot/.."

$source = "$root/artifacts/tmp/NuGet.Client"

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

git clone --depth 1 --branch $VersionTag https://github.com/NuGet/NuGet.Client.git $source
if (0 -ne $LASTEXITCODE) {
throw "Cloning failed."
}

$commit = git -C $source log -1 --pretty=format:"%h"
if (0 -ne $LASTEXITCODE) {
throw "Getting commit failed."
}

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

$frameworksPath = "$source/src/NuGet.Core/NuGet.Frameworks"
$frameworkItems = @(
"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
}


@"
This directory contains code that is copied from https://github.com/NuGet/NuGet.Client/tree/dev/src/NuGet.Core/NuGet.Frameworks, with the namespaces changed
and class visibility changed. This is done to ensure we are providing the same functionality as Nuget.Frameworks, without depending on the package explicitly.

The files in this folder are coming from tag $VersionTag, on commit $commit.

To update this code, run the script in: $($PSCommandPath -replace [regex]::Escape($root)) , with -VersionTag <theDesiredVersion>.

"@ | Set-Content "$destination/README.md"

$tpnPath = "$root/src/package/ThirdPartyNotices.txt"
$tpn = Get-Content $tpnPath -Raw
$tpn = $tpn -replace "Nuget.Client version.*\(", "Nuget.Client version $versionTag \("
$tpn | Set-Content -Path $tpnPath -Encoding utf8NoBOM -NoNewline
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