Skip to content

Commit

Permalink
Updated NugetDownloader. Remove duplicate dlls by filename in additio…
Browse files Browse the repository at this point in the history
…n to full path. Removed MinVer from published packages. Fixed issue with logging. Added option to use system Nuget feeds in addition to the specified feed.
  • Loading branch information
mikoskinen committed May 19, 2021
1 parent 8daef19 commit ed105dd
Show file tree
Hide file tree
Showing 14 changed files with 40 additions and 23 deletions.
1 change: 0 additions & 1 deletion samples/WebAppWithNuget/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public void ConfigureServices(IServiceCollection services)
.AddPluginType<IOperator>();

services.AddControllers();

}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="MinVer" Version="2.0.0" />
<PackageReference Include="MinVer" Version="2.0.*" PrivateAssets="all" />
</ItemGroup>

</Project>
8 changes: 4 additions & 4 deletions src/Weikio.PluginFramework.AspNetCore/PluginExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ namespace Microsoft.Extensions.DependencyInjection
{
public static class PluginExtensions
{
public static object Create(this Plugin plugin, IServiceProvider serviceProvider)
public static object Create(this Plugin plugin, IServiceProvider serviceProvider, params object[] parameters)
{
return ActivatorUtilities.CreateInstance(serviceProvider, plugin);
return ActivatorUtilities.CreateInstance(serviceProvider, plugin, parameters);
}

public static T Create<T>(this Plugin plugin, IServiceProvider serviceProvider) where T : class
public static T Create<T>(this Plugin plugin, IServiceProvider serviceProvider, params object[] parameters) where T : class
{
return ActivatorUtilities.CreateInstance(serviceProvider, plugin) as T;
return ActivatorUtilities.CreateInstance(serviceProvider, plugin, parameters) as T;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="MinVer" Version="2.0.0" />
<PackageReference Include="MinVer" Version="2.0.*" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public class NugetFeedPluginCatalog : IPluginCatalog

public NugetFeedPluginCatalog(NuGetFeed packageFeed, string searchTerm = null,
bool includePrereleases = false, int maxPackages = 128,
string packagesFolder = null, Action<TypeFinderCriteriaBuilder> configureFinder = null, Dictionary<string, TypeFinderCriteria> criterias = null, NugetFeedPluginCatalogOptions options = null)
string packagesFolder = null, Action<TypeFinderCriteriaBuilder> configureFinder = null, Dictionary<string, TypeFinderCriteria> criterias = null,
NugetFeedPluginCatalogOptions options = null)
{
_packageFeed = packageFeed;
_searchTerm = searchTerm;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public Plugin Get(string name, Version version)
public async Task Initialize()
{
var nuGetDownloader = new NuGetDownloader(_options.LoggerFactory());
var pluginAssemblyFileNames = await nuGetDownloader.DownloadAsync(PackagesFolder, _packageName, _packageVersion, _includePrerelease, _packageFeed);
var pluginAssemblyFileNames = await nuGetDownloader.DownloadAsync(PackagesFolder, _packageName, _packageVersion, _includePrerelease, _packageFeed, includeSecondaryRepositories: _options.IncludeSystemFeedsAsSecondary);

foreach (var f in pluginAssemblyFileNames)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ public class NugetPluginCatalogOptions
/// Gets or sets how the plugin names and version should be defined. <seealso cref="PluginNameOptions"/>.
/// </summary>
public PluginNameOptions PluginNameOptions { get; set; } = Defaults.PluginNameOptions;

/// <summary>
/// Gets or sets if system feeds should be used as secondary feeds for finding packages when feed url is defined.
/// </summary>
public bool IncludeSystemFeedsAsSecondary { get; set; } = false;

public static class Defaults
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NuGet.PackageManagement.NetStandard" Version="4.9.2" />
<PackageReference Include="NuGet.Packaging.Core" Version="5.6.0" />
<PackageReference Include="NuGet.ProjectModel" Version="5.6.0" />
<PackageReference Include="NuGet.Protocol" Version="5.6.0" />
<PackageReference Include="NuGet.Resolver" Version="5.6.0" />
<PackageReference Include="MinVer" Version="2.0.*" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="3.1.5" />
<PackageReference Include="Weikio.NugetDownloader" Version="1.0.0" />
<PackageReference Include="MinVer" Version="2.0.*" PrivateAssets="all" />
<PackageReference Include="Weikio.NugetDownloader" Version="1.1.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MinVer" Version="2.0.*" />
<PackageReference Include="MinVer" Version="2.0.*" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.Scripting" Version="3.6.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.6.0" />
<PackageReference Include="Weikio.TypeGenerator" Version="1.2.4" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MinVer" Version="2.0.*" />
<PackageReference Include="MinVer" Version="2.0.*" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
Expand Down
21 changes: 20 additions & 1 deletion src/Weikio.PluginFramework/Catalogs/FolderPluginCatalog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System.Runtime.InteropServices;
using System.Runtime.Loader;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Weikio.PluginFramework.Abstractions;
using Weikio.PluginFramework.Context;
using Weikio.PluginFramework.TypeFinding;
Expand Down Expand Up @@ -235,6 +234,26 @@ private bool IsPluginAssembly(string assemblyPath)

paths = paths.Distinct().ToList();

// Also make sure to include only one dll of each. If same dll is found from multiple locations, use the first found dll and remove the others.
var duplicateDlls = paths.Select(x => new {FullPath = x, FileName = Path.GetFileName(x)}).GroupBy(x => x.FileName)
.Where(x => x.Count() > 1)
.ToList();

var removed = new List<string>();

foreach (var duplicateDll in duplicateDlls)
{
foreach (var duplicateDllPath in duplicateDll.Skip(1))
{
removed.Add(duplicateDllPath.FullPath);
}
}

foreach (var re in removed)
{
paths.Remove(re);
}

var resolver = new PathAssemblyResolver(paths);

// We use the metadata (readonly) versions of the assemblies before loading them
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ private void Log(LogLevel logLevel, string message, Exception ex = null, params
{
var logger = GetLogger();

logger.Log(logLevel, message, ex, args);
logger.Log(logLevel, ex, message, args);
}

private static string loggerLock = "lock";
Expand Down
2 changes: 1 addition & 1 deletion src/Weikio.PluginFramework/Weikio.PluginFramework.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="MinVer" Version="2.0.0" />
<PackageReference Include="MinVer" Version="2.0.*" PrivateAssets="all" />
<PackageReference Include="System.Reflection.MetadataLoadContext" Version="4.7.1" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.2" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.3.1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ namespace Weikio.PluginFramework.AspNetCore.IntegrationTests
{
public class DefaultPluginTypeTests : TestBase
{

public DefaultPluginTypeTests(WebApplicationFactory<Startup> factory, ITestOutputHelper output) : base(factory, output)
{
}
Expand Down

0 comments on commit ed105dd

Please sign in to comment.