React to application part changes

This commit is contained in:
Pranav K 2018-03-21 10:13:53 -07:00
parent f1d965e5e4
commit aa49e6990c
3 changed files with 15 additions and 59 deletions

View File

@ -21,9 +21,9 @@
<MicrosoftAspNetCoreHttpAbstractionsPackageVersion>2.1.0-preview2-30355</MicrosoftAspNetCoreHttpAbstractionsPackageVersion> <MicrosoftAspNetCoreHttpAbstractionsPackageVersion>2.1.0-preview2-30355</MicrosoftAspNetCoreHttpAbstractionsPackageVersion>
<MicrosoftAspNetCoreHttpPackageVersion>2.1.0-preview2-30355</MicrosoftAspNetCoreHttpPackageVersion> <MicrosoftAspNetCoreHttpPackageVersion>2.1.0-preview2-30355</MicrosoftAspNetCoreHttpPackageVersion>
<MicrosoftAspNetCoreHttpsPolicyPackageVersion>2.1.0-preview2-30355</MicrosoftAspNetCoreHttpsPolicyPackageVersion> <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> <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> <MicrosoftAspNetCoreRazorDesignPackageVersion>2.1.0-preview2-30355</MicrosoftAspNetCoreRazorDesignPackageVersion>
<MicrosoftAspNetCoreRewritePackageVersion>2.1.0-preview2-30355</MicrosoftAspNetCoreRewritePackageVersion> <MicrosoftAspNetCoreRewritePackageVersion>2.1.0-preview2-30355</MicrosoftAspNetCoreRewritePackageVersion>
<MicrosoftAspNetCoreServerIISIntegrationPackageVersion>2.1.0-preview2-30355</MicrosoftAspNetCoreServerIISIntegrationPackageVersion> <MicrosoftAspNetCoreServerIISIntegrationPackageVersion>2.1.0-preview2-30355</MicrosoftAspNetCoreServerIISIntegrationPackageVersion>

View File

@ -1,10 +1,6 @@
// Copyright (c) .NET Foundation. All rights reserved. // 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. // 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;
using Microsoft.AspNetCore.Identity.UI.Services; using Microsoft.AspNetCore.Identity.UI.Services;
using Microsoft.AspNetCore.Mvc.ApplicationParts; using Microsoft.AspNetCore.Mvc.ApplicationParts;
@ -32,7 +28,7 @@ namespace Microsoft.AspNetCore.Identity
public static IdentityBuilder AddDefaultUI(this IdentityBuilder builder) public static IdentityBuilder AddDefaultUI(this IdentityBuilder builder)
{ {
builder.AddSignInManager(); builder.AddSignInManager();
AddAdditionalApplicationParts(builder); AddRelatedParts(builder);
builder.Services.ConfigureOptions( builder.Services.ConfigureOptions(
typeof(IdentityDefaultUIConfigureOptions<>) typeof(IdentityDefaultUIConfigureOptions<>)
@ -42,7 +38,7 @@ namespace Microsoft.AspNetCore.Identity
return builder; 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. // 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 // 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. // * Discovery of the parts.
// * Ordering of the parts. // * Ordering of the parts.
// * Loading of the assembly in memory. // * 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 var mvcBuilder = builder.Services
.AddMvc() .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); partManager.ApplicationParts.Add(new CompiledRazorAssemblyPart(assembly));
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);
}
} }
}); });
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;
} }
} }
} }

View File

@ -2,15 +2,13 @@
<PropertyGroup> <PropertyGroup>
<Description>ASP.NET Core Identity UI is the default Razor Pages built-in UI for the ASP.NET Core Identity framework.</Description> <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> <TargetFramework>netstandard2.0</TargetFramework>
<GenerateDocumentationFile>false</GenerateDocumentationFile> <GenerateDocumentationFile>false</GenerateDocumentationFile>
<PackageTags>aspnetcore;identity;membership;razorpages</PackageTags> <PackageTags>aspnetcore;identity;membership;razorpages</PackageTags>
<EnableApiCheck>false</EnableApiCheck> <EnableApiCheck>false</EnableApiCheck>
<GenerateEmbeddedFilesManifest>true</GenerateEmbeddedFilesManifest> <GenerateEmbeddedFilesManifest>true</GenerateEmbeddedFilesManifest>
<RazorCompileOnBuild>true</RazorCompileOnBuild> <EnableDefaultCompiledViewAssemblyLoadBehavior>false</EnableDefaultCompiledViewAssemblyLoadBehavior>
<PrecompiledAssemblyTitle Condition=" '$(PrecompiledAssemblyTitle)' == '' ">$(RazorTargetName).dll</PrecompiledAssemblyTitle>
<PreserveCompilationContext>false</PreserveCompilationContext>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
@ -39,7 +37,7 @@
</AssemblyAttribute> </AssemblyAttribute>
<RazorAssemblyAttribute Include="System.Reflection.AssemblyDescriptionAttribute"> <RazorAssemblyAttribute Include="System.Reflection.AssemblyDescriptionAttribute">
<_Parameter1>$(PrecompiledDescription)</_Parameter1> <_Parameter1>$(ViewAssemblyDescription)</_Parameter1>
</RazorAssemblyAttribute> </RazorAssemblyAttribute>
<RazorAssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute" Condition="'$(BuildNumber)' != ''"> <RazorAssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute" Condition="'$(BuildNumber)' != ''">
<_Parameter1>BuildNumber</_Parameter1> <_Parameter1>BuildNumber</_Parameter1>
@ -60,8 +58,7 @@
<ExpectedOutputFile>$(OutputPath)$(RazorTargetName).dll</ExpectedOutputFile> <ExpectedOutputFile>$(OutputPath)$(RazorTargetName).dll</ExpectedOutputFile>
</PropertyGroup> </PropertyGroup>
<Error Text="Unable to find precompiled view file $(ExpectedOutputFile)" <Error Text="Unable to find precompiled view file $(ExpectedOutputFile)" Condition="!Exists('$(ExpectedOutputFile)')" />
Condition="!Exists('$(ExpectedOutputFile)')" />
</Target> </Target>
</Project> </Project>