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

Move NuGet API usage to its own extension #824

Merged
merged 2 commits into from
Aug 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions Microsoft.DotNet.UpgradeAssistant.sln
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,14 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.DotNet.UpgradeAss
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.DotNet.UpgradeAssistant.Steps.Source.Tests", "tests\extensions\default\Microsoft.DotNet.UpgradeAssistant.Steps.Source.Tests\Microsoft.DotNet.UpgradeAssistant.Steps.Source.Tests.csproj", "{134CE4A1-E9A4-49C0-A998-7C531E6207CE}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "nuget", "nuget", "{021F1610-F2D0-4F00-81C7-AD7397DA296C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.DotNet.UpgradeAssistant.Extensions.NuGet", "src\extensions\nuget\Microsoft.DotNet.UpgradeAssistant.Extensions.NuGet\Microsoft.DotNet.UpgradeAssistant.Extensions.NuGet.csproj", "{E18A3CB0-BFDB-4672-AD53-7EAAF26C52AB}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "nuget", "nuget", "{824AFFC6-40A2-4AD6-8010-B939841CA16E}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.DotNet.UpgradeAssistant.Extensions.NuGet.Tests", "tests\extensions\nuget\Microsoft.DotNet.UpgradeAssistant.Extensions.NuGet.Tests\Microsoft.DotNet.UpgradeAssistant.Extensions.NuGet.Tests.csproj", "{58633641-85F3-4F8E-AC18-0EFACC36D142}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -758,6 +766,30 @@ Global
{134CE4A1-E9A4-49C0-A998-7C531E6207CE}.Release|x64.Build.0 = Release|Any CPU
{134CE4A1-E9A4-49C0-A998-7C531E6207CE}.Release|x86.ActiveCfg = Release|Any CPU
{134CE4A1-E9A4-49C0-A998-7C531E6207CE}.Release|x86.Build.0 = Release|Any CPU
{E18A3CB0-BFDB-4672-AD53-7EAAF26C52AB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E18A3CB0-BFDB-4672-AD53-7EAAF26C52AB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E18A3CB0-BFDB-4672-AD53-7EAAF26C52AB}.Debug|x64.ActiveCfg = Debug|Any CPU
{E18A3CB0-BFDB-4672-AD53-7EAAF26C52AB}.Debug|x64.Build.0 = Debug|Any CPU
{E18A3CB0-BFDB-4672-AD53-7EAAF26C52AB}.Debug|x86.ActiveCfg = Debug|Any CPU
{E18A3CB0-BFDB-4672-AD53-7EAAF26C52AB}.Debug|x86.Build.0 = Debug|Any CPU
{E18A3CB0-BFDB-4672-AD53-7EAAF26C52AB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E18A3CB0-BFDB-4672-AD53-7EAAF26C52AB}.Release|Any CPU.Build.0 = Release|Any CPU
{E18A3CB0-BFDB-4672-AD53-7EAAF26C52AB}.Release|x64.ActiveCfg = Release|Any CPU
{E18A3CB0-BFDB-4672-AD53-7EAAF26C52AB}.Release|x64.Build.0 = Release|Any CPU
{E18A3CB0-BFDB-4672-AD53-7EAAF26C52AB}.Release|x86.ActiveCfg = Release|Any CPU
{E18A3CB0-BFDB-4672-AD53-7EAAF26C52AB}.Release|x86.Build.0 = Release|Any CPU
{58633641-85F3-4F8E-AC18-0EFACC36D142}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{58633641-85F3-4F8E-AC18-0EFACC36D142}.Debug|Any CPU.Build.0 = Debug|Any CPU
{58633641-85F3-4F8E-AC18-0EFACC36D142}.Debug|x64.ActiveCfg = Debug|Any CPU
{58633641-85F3-4F8E-AC18-0EFACC36D142}.Debug|x64.Build.0 = Debug|Any CPU
{58633641-85F3-4F8E-AC18-0EFACC36D142}.Debug|x86.ActiveCfg = Debug|Any CPU
{58633641-85F3-4F8E-AC18-0EFACC36D142}.Debug|x86.Build.0 = Debug|Any CPU
{58633641-85F3-4F8E-AC18-0EFACC36D142}.Release|Any CPU.ActiveCfg = Release|Any CPU
{58633641-85F3-4F8E-AC18-0EFACC36D142}.Release|Any CPU.Build.0 = Release|Any CPU
{58633641-85F3-4F8E-AC18-0EFACC36D142}.Release|x64.ActiveCfg = Release|Any CPU
{58633641-85F3-4F8E-AC18-0EFACC36D142}.Release|x64.Build.0 = Release|Any CPU
{58633641-85F3-4F8E-AC18-0EFACC36D142}.Release|x86.ActiveCfg = Release|Any CPU
{58633641-85F3-4F8E-AC18-0EFACC36D142}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -831,6 +863,10 @@ Global
{7304F25F-0F4D-450F-A529-3C7AFE9D98CA} = {82BC0AAB-94CA-4D5B-BF95-F7329D1150CB}
{CEDAAB8D-613C-4A3F-8114-7D6B480F1EE3} = {7304F25F-0F4D-450F-A529-3C7AFE9D98CA}
{134CE4A1-E9A4-49C0-A998-7C531E6207CE} = {4E12F429-CEC0-4080-B0FE-39F9B8B9AE4C}
{021F1610-F2D0-4F00-81C7-AD7397DA296C} = {AA22EE67-3BBE-49A2-8868-531FE68FE162}
{E18A3CB0-BFDB-4672-AD53-7EAAF26C52AB} = {021F1610-F2D0-4F00-81C7-AD7397DA296C}
{824AFFC6-40A2-4AD6-8010-B939841CA16E} = {82BC0AAB-94CA-4D5B-BF95-F7329D1150CB}
{58633641-85F3-4F8E-AC18-0EFACC36D142} = {824AFFC6-40A2-4AD6-8010-B939841CA16E}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {D02F665B-C14D-43C2-955C-9338A23836E0}
Expand Down
Binary file modified docs/images/dependency-validation.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions eng/DependencyValidation/DependencyValidation.modelproj
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@
<Name>Microsoft.DotNet.UpgradeAssistant.Extensions.Maui</Name>
<Project>{a122dd5b-4b80-4558-8db2-8e9ebff12a1a}</Project>
</ProjectReference>
<ProjectReference Include="..\..\src\extensions\nuget\Microsoft.DotNet.UpgradeAssistant.Extensions.NuGet\Microsoft.DotNet.UpgradeAssistant.Extensions.NuGet.csproj">
<Name>Microsoft.DotNet.UpgradeAssistant.Extensions.NuGet</Name>
<Project>{e18a3cb0-bfdb-4672-ad53-7eaaf26c52ab}</Project>
</ProjectReference>
<ProjectReference Include="..\..\src\extensions\vb\Microsoft.DotNet.UpgradeAssistant.Extensions.VisualBasic\Microsoft.DotNet.UpgradeAssistant.Extensions.VisualBasic.csproj">
<Name>Microsoft.DotNet.UpgradeAssistant.Extensions.VisualBasic</Name>
<Project>{608e7ce5-5674-49eb-8728-719a468fc62e}</Project>
Expand Down
13 changes: 13 additions & 0 deletions eng/DependencyValidation/UpgradeAssistant.layerdiagram
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,19 @@
</reference>
</references>
</layer>
<layer Id="9905d4a3-87a3-46c4-abe5-202ee7b985ff" name="nuget">
<references>
<reference Id="2a788024-d9b8-419e-aa0a-d502a0e6aa6d" name="nuget">
<ArtifactNode Label="nuget" Category="CodeSchema_Project" Id="(Assembly=../../src/extensions/nuget)">
<Category Ref="CodeMap_SolutionFolder" />
</ArtifactNode>
<ExpandedNode Id="(Assembly=Microsoft.DotNet.UpgradeAssistant.Extensions.NuGet)" Label="Microsoft.DotNet.UpgradeAssistant.Extensions.NuGet.dll" Category="CodeSchema_Assembly">
<Category Ref="FileSystem.Category.FileOfType.dll" />
<LinkCategory Ref="Represents" />
</ExpandedNode>
</reference>
</references>
</layer>
</childLayers>
</layer>
<layer Id="421742ad-4313-43e3-bcee-4c01cd3c4c8c" name="Microsoft.DotNet.UpgradeAssistant.Abstractions">
Expand Down
11 changes: 7 additions & 4 deletions eng/DependencyValidation/UpgradeAssistant.layerdiagram.layout
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,12 @@
<layerShape Id="6f864661-c4c5-4da9-ad72-13a4bae5670a" absoluteBounds="24, 4, 1.625, 0.5" customColor="161, 199, 231">
<layerMoniker Id="8918b436-d958-4125-b519-fb14baa7dd53" />
</layerShape>
<layerShape Id="38feeace-77a9-4874-8eb3-1b6ccf8abcd0" absoluteBounds="24, 4.75, 1.625, 0.5" customColor="161, 199, 231">
<layerMoniker Id="9905d4a3-87a3-46c4-abe5-202ee7b985ff" />
</layerShape>
</nestedChildShapes>
</layerShape>
<dependencyConnector edgePoints="[(27.09375 : 5.75); (27.09375 : 7.375)]" fixedFrom="NotFixed" fixedTo="NotFixed" customColor="113, 111, 110">
<dependencyConnector edgePoints="[(27.90625 : 5.75); (27.90625 : 7.375)]" fixedFrom="Algorithm" fixedTo="Algorithm" customColor="113, 111, 110">
<dependencyFromLayerToLayerMoniker Id="153f1107-fc9d-4101-843e-a911901b91e4" />
<nodes>
<layerShapeMoniker Id="4be49585-80f9-43a6-9897-b31e107d49a0" />
Expand All @@ -79,7 +82,7 @@
<layerShape Id="936f240c-a956-4a13-a4c1-f7405040ccc5" absoluteBounds="29.5, 2.25, 2, 0.75" customColor="161, 199, 231">
<layerMoniker Id="a9443ba7-6840-4dd8-82e8-ae589e769244" />
</layerShape>
<dependencyConnector edgePoints="[(30.90625 : 3); (30.90625 : 7.375)]" fixedFrom="NotFixed" fixedTo="NotFixed" customColor="113, 111, 110">
<dependencyConnector edgePoints="[(30.90625 : 3); (30.90625 : 7.375)]" fixedFrom="Algorithm" fixedTo="Algorithm" customColor="113, 111, 110">
<dependencyFromLayerToLayerMoniker Id="6ef70d28-03de-4271-98c8-5dcc00559617" />
<nodes>
<layerShapeMoniker Id="936f240c-a956-4a13-a4c1-f7405040ccc5" />
Expand All @@ -103,7 +106,7 @@
<layerShape Id="e78c1014-0b86-46de-873d-5d087cf4a0e6" absoluteBounds="18.5, 6.5, 7, 0.375" customColor="161, 199, 231">
<layerMoniker Id="87aac048-b443-4d5c-bd87-162b1ff74794" />
</layerShape>
<dependencyConnector edgePoints="[(20.8125 : 5.75); (20.8125 : 6.5)]" fixedFrom="Algorithm" fixedTo="Algorithm" customColor="113, 111, 110">
<dependencyConnector edgePoints="[(20.8125 : 5.75); (20.8125 : 6.5)]" fixedFrom="NotFixed" fixedTo="NotFixed" customColor="113, 111, 110">
<dependencyFromLayerToLayerMoniker Id="ca5beb93-d957-49cb-908d-e10527cbe7e4" />
<nodes>
<layerShapeMoniker Id="8d717de7-8a7c-4613-99cc-dbb6565b9cee" />
Expand All @@ -124,7 +127,7 @@
<layerShapeMoniker Id="e78c1014-0b86-46de-873d-5d087cf4a0e6" />
</nodes>
</dependencyConnector>
<dependencyConnector edgePoints="[(22 : 6.875); (22 : 7.375)]" fixedFrom="Algorithm" fixedTo="Algorithm" customColor="113, 111, 110">
<dependencyConnector edgePoints="[(22 : 6.875); (22 : 7.375)]" fixedFrom="NotFixed" fixedTo="NotFixed" customColor="113, 111, 110">
<dependencyFromLayerToLayerMoniker Id="be6af2dc-b697-443b-ba64-fd21151968d8" />
<nodes>
<layerShapeMoniker Id="e78c1014-0b86-46de-873d-5d087cf4a0e6" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@
<Extension Include="..\..\extensions\windows\Microsoft.DotNet.UpgradeAssistant.Extensions.Windows\Microsoft.DotNet.UpgradeAssistant.Extensions.Windows.csproj">
<Name>windows</Name>
</Extension>
<Extension Include="..\..\extensions\NuGet\Microsoft.DotNet.UpgradeAssistant.Extensions.NuGet\Microsoft.DotNet.UpgradeAssistant.Extensions.NuGet.csproj">
<Name>nuget</Name>
</Extension>
</ItemGroup>
<ItemGroup>
<Compile Update="LocalizedStrings.Designer.cs">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,6 @@ public static IHostBuilder UseUpgradeAssistant<TApp>(this IHostBuilder host, IUp
}
});

services.AddNuGet(optionss =>
{
if (upgradeOptions.Project?.FullName is string fullname)
{
optionss.PackageSourcePath = Path.GetDirectoryName(fullname);
Copy link

Choose a reason for hiding this comment

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

I believe the setting of PackageSourcePath got lost in this PR. It would explain why changing package sources in nuget.config doesn't work anymore.

Copy link

Choose a reason for hiding this comment

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

I got the same issue, 0.4.421302 will not follow my nuget.config but 0.2.241603 (a version that is before the above PR) will follow my nuget.config.

}
});

services.AddUserInput();
services.AddAnalysis();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
"Extensions": {
"Source": "https://upgradeassistant.blob.core.windows.net/extensions/index.json",

"required": [
Copy link
Contributor

Choose a reason for hiding this comment

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

this naming feels a little confusing. almost feels like something that is default is required? or maybe we move the default extension under required?

Copy link
Member Author

@twsouthwick twsouthwick Aug 26, 2021

Choose a reason for hiding this comment

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

This is "required" because everything will need it. Default extensions are used to augment certain services but not needed everywhere. Long term, it may be good to define extensions on a "per command" usage; ie, identify commands that would only be used in analyze/upgrade/etc

Copy link
Contributor

Choose a reason for hiding this comment

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

cool!

"nuget"
],

"Default": [
"default",
"vb",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public interface IProjectFile

string FilePath { get; }

IEnumerable<NuGetReference> PackageReferences { get; }

void AddFrameworkReferences(IEnumerable<Reference> frameworkReferences);

void RemoveFrameworkReferences(IEnumerable<Reference> frameworkReferences);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections.Generic;

namespace Microsoft.DotNet.UpgradeAssistant
{
public interface ITargetFrameworkCollection : IReadOnlyCollection<TargetFrameworkMoniker>
{
void SetTargetFramework(TargetFrameworkMoniker tfm);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ private void Load(ExtensionInstance extension, string[] assemblies)
protected override Assembly? Load(AssemblyName assemblyName)
{
// If available in the default, we want to ensure that is used.
var inDefault = Default.Assemblies.FirstOrDefault(a => string.Equals(a.GetName().Name, assemblyName.Name, StringComparison.Ordinal));
var inDefault = Default.Assemblies
.Where(a => !a.GetName().Name!.Contains("NuGet", StringComparison.OrdinalIgnoreCase))
twsouthwick marked this conversation as resolved.
Show resolved Hide resolved
.FirstOrDefault(a => string.Equals(a.GetName().Name, assemblyName.Name, StringComparison.Ordinal));

if (inDefault is Assembly existing)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public class ExtensionOptions

public ICollection<string> DefaultExtensions { get; } = new List<string>();

public ICollection<string> RequiredExtensions { get; } = new List<string>();

public ICollection<string> ExtensionPaths { get; } = new List<string>();

public IEnumerable<AdditionalOption> AdditionalOptions { get; set; } = Enumerable.Empty<AdditionalOption>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,21 @@ public ExtensionProvider(

_extensions = new Lazy<IEnumerable<ExtensionInstance>>(() =>
{
var list = new List<ExtensionInstance>();

var opts = options.Value;

if (!opts.LoadExtensions)
// Required extensions are required for all commands UA may handle, as opposed to other extensions that augment certain commands
foreach (var path in opts.RequiredExtensions)
{
return Enumerable.Empty<ExtensionInstance>();
LoadPath(path, isDefault: true);
}

var list = new List<ExtensionInstance>();
// Required extensions must load, otherwise they may be turned off
if (!opts.LoadExtensions)
Copy link
Member

Choose a reason for hiding this comment

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

Do we need a LoadExtensions option? I'm not sure it's necessary and if we removed it, this code would simplify a bit as default and required extensions wouldn't have to be distinguished anymore. The only downside I can think of to removing it is that users won't be able to disable any default extensions, but I haven't seen a use case where that would be necessary.

Copy link
Member Author

@twsouthwick twsouthwick Aug 26, 2021

Choose a reason for hiding this comment

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

When managing extensions, it adds extra time that this prevents. The extension management doesn't need all the random extensions people may be adding, but it will need the NuGet one

{
return list;
}

foreach (var path in opts.ExtensionPaths)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,22 @@ public static OptionsBuilder<ExtensionOptions> AddDefaultExtensions(this Options
return builder.Configure(options =>
{
const string ExtensionDirectory = "extensions";

var settings = configuration.GetSection("Extensions").Get<ExtensionSettings>();
var defaultExtensions = settings.Default
.Select(n => Path.GetFullPath(Path.Combine(AppContext.BaseDirectory, ExtensionDirectory, n)));

options.DefaultSource = settings.Source;

foreach (var path in defaultExtensions)
AddExtensions(options.DefaultExtensions, settings.Default);
AddExtensions(options.RequiredExtensions, settings.Required);

static void AddExtensions(ICollection<string> collection, string[] names)
{
options.DefaultExtensions.Add(path);
var extensionFullPaths = names
.Select(n => Path.GetFullPath(Path.Combine(AppContext.BaseDirectory, ExtensionDirectory, n)));

foreach (var path in extensionFullPaths)
{
collection.Add(path);
}
}
});
}
Expand All @@ -106,6 +112,8 @@ private class ExtensionSettings
public string Source { get; set; } = string.Empty;

public string[] Default { get; set; } = Array.Empty<string>();

public string[] Required { get; set; } = Array.Empty<string>();
}

public static IServiceCollection AddExtensionOption<TOption>(this IServiceCollection services, TOption option)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;

namespace Microsoft.DotNet.UpgradeAssistant.MSBuild
{
internal class Factories
{
private readonly Func<IUpgradeContext, IProject, INuGetReferences> _nugetReferenceFactory;
private readonly Func<IProjectFile, ITargetFrameworkCollection> _tfmCollectionFactory;
private readonly Func<string, ISolutionInfo> _infoGenerator;

public Factories(
Copy link
Member

Choose a reason for hiding this comment

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

I think I'm overlooking something here. I'm trying to figure out how this type is instantiated. I see that it's registered as a transient DI service, but I don't see where the Funcs it needs as arguments are registered. Can you help me figure out where the nugetReferenceFactory and tfmCollectionFactory implementations come from?

Copy link
Member Author

Choose a reason for hiding this comment

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

Func<IUpgradeContext, IProject, INuGetReferences> nugetReferenceFactory,
Func<IProjectFile, ITargetFrameworkCollection> tfmCollectionFactory,
Func<string, ISolutionInfo> infoGenerator)
{
_nugetReferenceFactory = nugetReferenceFactory;
_tfmCollectionFactory = tfmCollectionFactory;
_infoGenerator = infoGenerator;
}

public INuGetReferences CreateNuGetReferences(IUpgradeContext context, IProject project) => _nugetReferenceFactory(context, project);

public ITargetFrameworkCollection CreateTfmCollection(IProjectFile project) => _tfmCollectionFactory(project);

public ISolutionInfo CreateSolutionInfo(string name) => _infoGenerator(name);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@ public ProjectRootElement ProjectRoot
}
}

public IEnumerable<NuGetReference> PackageReferences => ProjectRoot.GetAllPackageReferences().Select(p => p.AsNuGetReference());

public bool IsSdk => Sdk.Any();

public ICollection<string> Imports => new ImportsCollection(ProjectRoot);

public ICollection<string> Sdk => new SdkCollection(ProjectRoot);

public void SetTFM(TargetFrameworkMoniker tfm) => new TargetFrameworkMonikerCollection(this, _comparer).SetTargetFramework(tfm);
public void SetTFM(TargetFrameworkMoniker tfm) => _factories.CreateTfmCollection(this).SetTargetFramework(tfm);

public void AddPackages(IEnumerable<NuGetReference> references)
{
Expand All @@ -61,7 +63,7 @@ public void AddPackages(IEnumerable<NuGetReference> references)

public void RemovePackages(IEnumerable<NuGetReference> references)
{
foreach (var reference in PackageReferences)
foreach (var reference in NuGetReferences.PackageReferences)
{
if (references.Contains(reference))
{
Expand Down Expand Up @@ -184,7 +186,7 @@ public void RemoveProperty(string propertyName)
{
Project.RemoveProperty(property);
}
}
}

private static string GetPathRelativeToProject(string path, string projectDir) =>
Path.IsPathFullyQualified(path)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal partial class MSBuildProject : IProject
private readonly ILogger _logger;
private readonly IEnumerable<IComponentIdentifier> _componentIdentifiers;
private readonly IPackageRestorer _restorer;
private readonly ITargetFrameworkMonikerComparer _comparer;
private readonly Factories _factories;

public MSBuildWorkspaceUpgradeContext Context { get; }

Expand All @@ -29,6 +29,7 @@ internal partial class MSBuildProject : IProject
public MSBuildProject(
MSBuildWorkspaceUpgradeContext context,
IEnumerable<IComponentIdentifier> componentIdentifiers,
Factories factories,
IPackageRestorer restorer,
ITargetFrameworkMonikerComparer comparer,
FileInfo file,
Expand All @@ -37,9 +38,9 @@ public MSBuildProject(
FileInfo = file ?? throw new ArgumentNullException(nameof(file));
Context = context ?? throw new ArgumentNullException(nameof(context));

_factories = factories ?? throw new ArgumentNullException(nameof(factories));
_componentIdentifiers = componentIdentifiers ?? throw new ArgumentNullException(nameof(componentIdentifiers));
_restorer = restorer ?? throw new ArgumentNullException(nameof(restorer));
_comparer = comparer ?? throw new ArgumentNullException(nameof(comparer));
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
}

Expand All @@ -59,6 +60,8 @@ public MSBuildProject(

public Language Language => ParseLanguageByProjectFileExtension(FileInfo.Extension);

public INuGetReferences NuGetReferences => _factories.CreateNuGetReferences(Context, this);

private static Language ParseLanguageByProjectFileExtension(string extension)
=> extension.ToUpperInvariant() switch
{
Expand Down Expand Up @@ -141,7 +144,7 @@ public IEnumerable<string> FindFiles(ProjectItemMatcher matcher, ProjectItemType
public IEnumerable<Reference> References =>
ProjectRoot.GetAllReferences().Select(r => r.AsReference()).ToList();

public IReadOnlyCollection<TargetFrameworkMoniker> TargetFrameworks => new TargetFrameworkMonikerCollection(this, _comparer);
public IReadOnlyCollection<TargetFrameworkMoniker> TargetFrameworks => _factories.CreateTfmCollection(this);

public IEnumerable<string> ProjectTypes => GetPropertyValue("ProjectTypeGuids").Split(';');

Expand Down
Loading