React to application part changes
This commit is contained in:
parent
f1d965e5e4
commit
aa49e6990c
|
|
@ -21,9 +21,9 @@
|
|||
<MicrosoftAspNetCoreHttpAbstractionsPackageVersion>2.1.0-preview2-30355</MicrosoftAspNetCoreHttpAbstractionsPackageVersion>
|
||||
<MicrosoftAspNetCoreHttpPackageVersion>2.1.0-preview2-30355</MicrosoftAspNetCoreHttpPackageVersion>
|
||||
<MicrosoftAspNetCoreHttpsPolicyPackageVersion>2.1.0-preview2-30355</MicrosoftAspNetCoreHttpsPolicyPackageVersion>
|
||||
<MicrosoftAspNetCoreMvcPackageVersion>2.1.0-preview2-30355</MicrosoftAspNetCoreMvcPackageVersion>
|
||||
<MicrosoftAspNetCoreMvcPackageVersion>2.1.0-a-preview2-application-part-18617</MicrosoftAspNetCoreMvcPackageVersion>
|
||||
<MicrosoftAspNetCoreMvcRazorViewCompilationPackageVersion>2.1.0-preview2-30355</MicrosoftAspNetCoreMvcRazorViewCompilationPackageVersion>
|
||||
<MicrosoftAspNetCoreMvcTestingPackageVersion>2.1.0-preview2-30355</MicrosoftAspNetCoreMvcTestingPackageVersion>
|
||||
<MicrosoftAspNetCoreMvcTestingPackageVersion>2.1.0-a-preview2-application-part-18617</MicrosoftAspNetCoreMvcTestingPackageVersion>
|
||||
<MicrosoftAspNetCoreRazorDesignPackageVersion>2.1.0-preview2-30355</MicrosoftAspNetCoreRazorDesignPackageVersion>
|
||||
<MicrosoftAspNetCoreRewritePackageVersion>2.1.0-preview2-30355</MicrosoftAspNetCoreRewritePackageVersion>
|
||||
<MicrosoftAspNetCoreServerIISIntegrationPackageVersion>2.1.0-preview2-30355</MicrosoftAspNetCoreServerIISIntegrationPackageVersion>
|
||||
|
|
|
|||
|
|
@ -1,10 +1,6 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Microsoft.AspNetCore.Identity.UI;
|
||||
using Microsoft.AspNetCore.Identity.UI.Services;
|
||||
using Microsoft.AspNetCore.Mvc.ApplicationParts;
|
||||
|
|
@ -32,7 +28,7 @@ namespace Microsoft.AspNetCore.Identity
|
|||
public static IdentityBuilder AddDefaultUI(this IdentityBuilder builder)
|
||||
{
|
||||
builder.AddSignInManager();
|
||||
AddAdditionalApplicationParts(builder);
|
||||
AddRelatedParts(builder);
|
||||
|
||||
builder.Services.ConfigureOptions(
|
||||
typeof(IdentityDefaultUIConfigureOptions<>)
|
||||
|
|
@ -42,7 +38,7 @@ namespace Microsoft.AspNetCore.Identity
|
|||
return builder;
|
||||
}
|
||||
|
||||
private static void AddAdditionalApplicationParts(IdentityBuilder builder)
|
||||
private static void AddRelatedParts(IdentityBuilder builder)
|
||||
{
|
||||
// For preview1, we don't have a good mechanism to plug in additional parts.
|
||||
// We need to provide API surface to allow libraries to plug in existing parts
|
||||
|
|
@ -51,56 +47,19 @@ namespace Microsoft.AspNetCore.Identity
|
|||
// * Discovery of the parts.
|
||||
// * Ordering of the parts.
|
||||
// * Loading of the assembly in memory.
|
||||
var thisAssembly = typeof(IdentityBuilderUIExtensions).Assembly;
|
||||
var additionalReferences = thisAssembly
|
||||
.GetCustomAttributes<AssemblyMetadataAttribute>()
|
||||
.Where(am => string.Equals(am.Key, "Microsoft.AspNetCore.Mvc.AdditionalReference"))
|
||||
.Select(am => am.Value.Split(',')[0])
|
||||
.ToArray();
|
||||
|
||||
var mvcBuilder = builder.Services
|
||||
.AddMvc()
|
||||
.ConfigureApplicationPartManager(apm =>
|
||||
.ConfigureApplicationPartManager(partManager =>
|
||||
{
|
||||
foreach (var reference in additionalReferences)
|
||||
var thisAssembly = typeof(IdentityBuilderUIExtensions).Assembly;
|
||||
var relatedAssemblies = RelatedAssemblyAttribute.GetRelatedAssemblies(thisAssembly, throwOnError: true);
|
||||
|
||||
foreach (var assembly in relatedAssemblies)
|
||||
{
|
||||
var fileName = Path.GetFileName(reference);
|
||||
var filePath = Path.Combine(Path.GetDirectoryName(thisAssembly.Location), fileName);
|
||||
var additionalAssembly = LoadAssembly(filePath);
|
||||
// This needs to change to additional assembly part.
|
||||
var additionalPart = new AssemblyPart(additionalAssembly);
|
||||
if (!apm.ApplicationParts.Any(ap => HasSameName(ap.Name, additionalPart.Name)))
|
||||
{
|
||||
apm.ApplicationParts.Add(additionalPart);
|
||||
}
|
||||
partManager.ApplicationParts.Add(new CompiledRazorAssemblyPart(assembly));
|
||||
}
|
||||
});
|
||||
|
||||
bool HasSameName(string left, string right) => string.Equals(left, right, StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
private static Assembly LoadAssembly(string filePath)
|
||||
{
|
||||
Assembly viewsAssembly = null;
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
try
|
||||
{
|
||||
viewsAssembly = Assembly.LoadFile(filePath);
|
||||
}
|
||||
catch (FileLoadException)
|
||||
{
|
||||
throw new InvalidOperationException("Unable to load the precompiled views assembly in " +
|
||||
$"'{filePath}'.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InvalidOperationException("Could not find the precompiled views assembly for 'Microsoft.AspNetCore.Identity.UI' at " +
|
||||
$"'{filePath}'.");
|
||||
}
|
||||
|
||||
return viewsAssembly;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,15 +2,13 @@
|
|||
|
||||
<PropertyGroup>
|
||||
<Description>ASP.NET Core Identity UI is the default Razor Pages built-in UI for the ASP.NET Core Identity framework.</Description>
|
||||
<PrecompiledDescription>Precompiled views assembly for the ASP.NET Core Identity UI package.</PrecompiledDescription>
|
||||
<ViewAssemblyDescription>Compiled Razor views assembly for the ASP.NET Core Identity UI package.</ViewAssemblyDescription>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<GenerateDocumentationFile>false</GenerateDocumentationFile>
|
||||
<PackageTags>aspnetcore;identity;membership;razorpages</PackageTags>
|
||||
<EnableApiCheck>false</EnableApiCheck>
|
||||
<GenerateEmbeddedFilesManifest>true</GenerateEmbeddedFilesManifest>
|
||||
<RazorCompileOnBuild>true</RazorCompileOnBuild>
|
||||
<PrecompiledAssemblyTitle Condition=" '$(PrecompiledAssemblyTitle)' == '' ">$(RazorTargetName).dll</PrecompiledAssemblyTitle>
|
||||
<PreserveCompilationContext>false</PreserveCompilationContext>
|
||||
<EnableDefaultCompiledViewAssemblyLoadBehavior>false</EnableDefaultCompiledViewAssemblyLoadBehavior>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
@ -39,7 +37,7 @@
|
|||
</AssemblyAttribute>
|
||||
|
||||
<RazorAssemblyAttribute Include="System.Reflection.AssemblyDescriptionAttribute">
|
||||
<_Parameter1>$(PrecompiledDescription)</_Parameter1>
|
||||
<_Parameter1>$(ViewAssemblyDescription)</_Parameter1>
|
||||
</RazorAssemblyAttribute>
|
||||
<RazorAssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute" Condition="'$(BuildNumber)' != ''">
|
||||
<_Parameter1>BuildNumber</_Parameter1>
|
||||
|
|
@ -60,8 +58,7 @@
|
|||
<ExpectedOutputFile>$(OutputPath)$(RazorTargetName).dll</ExpectedOutputFile>
|
||||
</PropertyGroup>
|
||||
|
||||
<Error Text="Unable to find precompiled view file $(ExpectedOutputFile)"
|
||||
Condition="!Exists('$(ExpectedOutputFile)')" />
|
||||
<Error Text="Unable to find precompiled view file $(ExpectedOutputFile)" Condition="!Exists('$(ExpectedOutputFile)')" />
|
||||
</Target>
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
Loading…
Reference in New Issue