Skip to content

Update SDK to bring unified assembly changes #31039

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

Merged
3 commits merged into from
Mar 19, 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
4 changes: 2 additions & 2 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"sdk": {
"version": "6.0.100-preview.3.21160.5"
"version": "6.0.100-preview.3.21168.19"
},
"tools": {
"dotnet": "6.0.100-preview.3.21160.5",
"dotnet": "6.0.100-preview.3.21168.19",
"runtimes": {
"dotnet/x64": [
"2.1.25",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,34 +198,12 @@ void TryAddMapping(AzureADSchemeOptions o)

private static void AddAdditionalMvcApplicationParts(IServiceCollection services)
{
var additionalParts = GetAdditionalParts();
var mvcBuilder = services
.AddMvc()
.ConfigureApplicationPartManager(apm =>
{
foreach (var part in additionalParts)
{
if (!apm.ApplicationParts.Any(ap => HasSameName(ap.Name, part.Name)))
{
apm.ApplicationParts.Add(part);
}
}

apm.FeatureProviders.Add(new AzureADAccountControllerFeatureProvider());
});

bool HasSameName(string left, string right) => string.Equals(left, right, StringComparison.Ordinal);
}

private static IEnumerable<ApplicationPart> GetAdditionalParts()
{
var thisAssembly = typeof(AzureADAuthenticationBuilderExtensions).Assembly;
var relatedAssemblies = RelatedAssemblyAttribute.GetRelatedAssemblies(thisAssembly, throwOnError: true);

foreach (var reference in relatedAssemblies)
{
yield return new CompiledRazorAssemblyPart(reference);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>
<PackageTags>aspnetcore;authentication;AzureAD</PackageTags>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<ProvideApplicationPartFactoryAttributeTypeName>Microsoft.AspNetCore.Mvc.ApplicationParts.NullApplicationPartFactory, Microsoft.AspNetCore.Mvc.Core</ProvideApplicationPartFactoryAttributeTypeName>
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>
<PackageTags>aspnetcore;authentication;AzureADB2C</PackageTags>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<ProvideApplicationPartFactoryAttributeTypeName>Microsoft.AspNetCore.Mvc.ApplicationParts.NullApplicationPartFactory, Microsoft.AspNetCore.Mvc.Core</ProvideApplicationPartFactoryAttributeTypeName>
Copy link
Member

Choose a reason for hiding this comment

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

Is this a new feature?

Copy link
Member Author

Choose a reason for hiding this comment

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

NullApplicationPartFactory? No, this was a workaround that was in place to support the old Azure AD UI scenarios.

A user could call an extension method AddAzureAd to configure the app areas and controller routes that would set up signin.

Razor ships with a CompiledRazorItemApplicationPartFactory that discovers and loads view types in the related assembly.

To support the extension method scenario, this project was circumventing the CompiledRazorItemApplicationPartFactory logic and doing the loading on its own in the extension method.

We've removed the concept of a related assembly with the consolidated views work so this is no longer needed.

<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,8 @@ public WebAuthenticationTests(WebApplicationFactory<Startup> fixture)
public static TheoryData<string> NotAddedEndpoints =>
new TheoryData<string>()
{
"/AzureAD/Account/AccessDenied",
"/AzureAD/Account/Error",
"/AzureAD/Account/SignedOut",
"/AzureAD/Account/SignIn",
"/AzureAD/Account/SignOut",
"/AzureADB2C/Account/AccessDenied",
"/AzureADB2C/Account/Error",
"/AzureADB2C/Account/SignedOut",
"/AzureADB2C/Account/SignIn",
"/AzureADB2C/Account/ResetPassword",
"/AzureADB2C/Account/EditProfile",
Expand Down
83 changes: 1 addition & 82 deletions src/Identity/UI/src/IdentityBuilderUIExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static class IdentityBuilderUIExtensions
public static IdentityBuilder AddDefaultUI(this IdentityBuilder builder)
{
builder.AddSignInManager();
AddRelatedParts(builder);
builder.Services.AddMvc();

builder.Services.ConfigureOptions(
typeof(IdentityDefaultUIConfigureOptions<>)
Expand All @@ -44,87 +44,6 @@ public static IdentityBuilder AddDefaultUI(this IdentityBuilder builder)
return builder;
}

private static readonly IDictionary<UIFramework, string> _assemblyMap =
new Dictionary<UIFramework, string>()
{
[UIFramework.Bootstrap4] = "Microsoft.AspNetCore.Identity.UI.Views.V4",
};

private static void AddRelatedParts(IdentityBuilder builder)
{
var mvcBuilder = builder.Services
.AddMvc()
.ConfigureApplicationPartManager(partManager =>
{
// We try to resolve the UI framework that was used by looking at the entry assembly.
// When an app runs, the entry assembly will point to the built app. In some rare cases
// (functional testing) the app assembly will be different, and we'll try to locate it through
// the same mechanism that MVC uses today.
// Finally, if for some reason we aren't able to find the assembly, we'll use our default value
// (Bootstrap4)
if (!TryResolveUIFramework(Assembly.GetEntryAssembly(), out var framework) &&
!TryResolveUIFramework(GetApplicationAssembly(builder), out framework))
{
framework = default;
}

var thisAssembly = typeof(IdentityBuilderUIExtensions).Assembly;
var relatedAssemblies = RelatedAssemblyAttribute.GetRelatedAssemblies(thisAssembly, throwOnError: true);
var relatedParts = relatedAssemblies.ToDictionary(
ra => ra,
CompiledRazorAssemblyApplicationPartFactory.GetDefaultApplicationParts);

var selectedFrameworkAssembly = _assemblyMap[framework];

foreach (var kvp in relatedParts)
{
var assemblyName = kvp.Key.GetName().Name;
if (!IsAssemblyForFramework(selectedFrameworkAssembly, assemblyName))
{
RemoveParts(partManager, kvp.Value);
}
else
{
AddParts(partManager, kvp.Value);
}
}

bool IsAssemblyForFramework(string frameworkAssembly, string assemblyName) =>
string.Equals(assemblyName, frameworkAssembly, StringComparison.OrdinalIgnoreCase);

void RemoveParts(
ApplicationPartManager manager,
IEnumerable<ApplicationPart> partsToRemove)
{
for (var i = 0; i < manager.ApplicationParts.Count; i++)
{
var part = manager.ApplicationParts[i];
if (partsToRemove.Any(p => string.Equals(
p.Name,
part.Name,
StringComparison.OrdinalIgnoreCase)))
{
manager.ApplicationParts.Remove(part);
}
}
}

void AddParts(
ApplicationPartManager manager,
IEnumerable<ApplicationPart> partsToAdd)
{
foreach (var part in partsToAdd)
{
if (!manager.ApplicationParts.Any(p => p.GetType() == part.GetType() &&
string.Equals(p.Name, part.Name, StringComparison.OrdinalIgnoreCase)))
{
manager.ApplicationParts.Add(part);
}
}
}
});
}

private static Assembly GetApplicationAssembly(IdentityBuilder builder)
{
// Whis is the same logic that MVC follows to find the application assembly.
Expand Down
2 changes: 0 additions & 2 deletions src/Identity/UI/src/Microsoft.AspNetCore.Identity.UI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<PackageTags>aspnetcore;identity;membership;razorpages</PackageTags>
<ProvideApplicationPartFactoryAttributeTypeName>Microsoft.AspNetCore.Mvc.ApplicationParts.NullApplicationPartFactory, Microsoft.AspNetCore.Mvc.Core</ProvideApplicationPartFactoryAttributeTypeName>
<EnableDefaultRazorGenerateItems>false</EnableDefaultRazorGenerateItems>
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
<RazorTargetName>Microsoft.AspNetCore.Identity.UI.Views.V4</RazorTargetName>

<DisableStaticWebAssetsBuildPropsFileGeneration>true</DisableStaticWebAssetsBuildPropsFileGeneration>
<StaticWebAssetsDisableProjectBuildPropsFileGeneration>true</StaticWebAssetsDisableProjectBuildPropsFileGeneration>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ protected override void ConfigureWebHost(IWebHostBuilder builder)
}

private void UpdateApplicationParts(IWebHostBuilder builder) =>
builder.ConfigureServices(services => AddRelatedParts(services, BootstrapFrameworkVersion));
builder.ConfigureServices(services => services.AddMvc());

private void UpdateStaticAssets(IWebHostBuilder builder)
{
Expand Down Expand Up @@ -150,75 +150,5 @@ protected override void Dispose(bool disposing)

base.Dispose(disposing);
}

private static void AddRelatedParts(IServiceCollection services, string framework)
{
var _assemblyMap =
new Dictionary<UIFramework, string>()
{
[UIFramework.Bootstrap4] = "Microsoft.AspNetCore.Identity.UI.Views.V4",
};

var mvcBuilder = services
.AddMvc()
.ConfigureApplicationPartManager(partManager =>
{
var thisAssembly = typeof(IdentityBuilderUIExtensions).Assembly;
var relatedAssemblies = RelatedAssemblyAttribute.GetRelatedAssemblies(thisAssembly, throwOnError: true);
var relatedParts = relatedAssemblies.ToDictionary(
ra => ra,
CompiledRazorAssemblyApplicationPartFactory.GetDefaultApplicationParts);

var selectedFrameworkAssembly = _assemblyMap[UIFramework.Bootstrap4];

foreach (var kvp in relatedParts)
{
var assemblyName = kvp.Key.GetName().Name;
if (!IsAssemblyForFramework(selectedFrameworkAssembly, assemblyName))
{
RemoveParts(partManager, kvp.Value);
}
else
{
AddParts(partManager, kvp.Value);
}
}

bool IsAssemblyForFramework(string frameworkAssembly, string assemblyName) =>
string.Equals(assemblyName, frameworkAssembly, StringComparison.OrdinalIgnoreCase);

void RemoveParts(
ApplicationPartManager manager,
IEnumerable<ApplicationPart> partsToRemove)
{
for (var i = 0; i < manager.ApplicationParts.Count; i++)
{
var part = manager.ApplicationParts[i];
if (partsToRemove.Any(p => string.Equals(
p.Name,
part.Name,
StringComparison.OrdinalIgnoreCase)))
{
manager.ApplicationParts.Remove(part);
}
}
}

void AddParts(
ApplicationPartManager manager,
IEnumerable<ApplicationPart> partsToAdd)
{
foreach (var part in partsToAdd)
{
if (!manager.ApplicationParts.Any(p => p.GetType() == part.GetType() &&
string.Equals(p.Name, part.Name, StringComparison.OrdinalIgnoreCase)))
{
manager.ApplicationParts.Add(part);
}
}
}
});
}

}
}
6 changes: 3 additions & 3 deletions src/Mvc/test/Mvc.FunctionalTests/RazorPagesNamespaceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ public async Task Page_DefaultNamespace_IfUnset()
var content = await Client.GetStringAsync("http://localhost/DefaultNamespace");

// Assert
Assert.Equal("AspNetCore", content.Trim());
Assert.Equal("AspNetCoreGeneratedDocument", content.Trim());
}

[Fact]
public async Task Page_ImportedNamespace_UsedFromViewImports()
{
Expand All @@ -41,7 +41,7 @@ public async Task Page_ImportedNamespace_UsedFromViewImports()
// Assert
Assert.Equal("CustomNamespace.Nested.Folder", content.Trim());
}

[Fact]
public async Task Page_OverrideNamespace_SetByPage()
{
Expand Down
4 changes: 2 additions & 2 deletions src/Mvc/test/Mvc.FunctionalTests/RazorPagesTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -932,8 +932,8 @@ public async Task PagePropertiesAreInjected()
// Arrange
var expected =
@"Microsoft.AspNetCore.Mvc.Routing.UrlHelper
Microsoft.AspNetCore.Mvc.ViewFeatures.HtmlHelper`1[AspNetCore.InjectedPageProperties]
Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary`1[AspNetCore.InjectedPageProperties]";
Microsoft.AspNetCore.Mvc.ViewFeatures.HtmlHelper`1[AspNetCoreGeneratedDocument.InjectedPageProperties]
Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary`1[AspNetCoreGeneratedDocument.InjectedPageProperties]";

// Act
var response = await Client.GetStringAsync("InjectedPageProperties");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ public void ConfigureServices(IServiceCollection services)
typeof(ComponentFromServicesViewComponent),
typeof(InServicesTagHelper)));

var relatedAssenbly = RelatedAssemblyAttribute
.GetRelatedAssemblies(GetType().Assembly, throwOnError: true)
.SingleOrDefault();
foreach (var part in CompiledRazorAssemblyApplicationPartFactory.GetDefaultApplicationParts(relatedAssenbly))
foreach (var part in CompiledRazorAssemblyApplicationPartFactory.GetDefaultApplicationParts(Assembly.GetExecutingAssembly()))
{
manager.ApplicationParts.Add(part);
}
Expand Down
4 changes: 4 additions & 0 deletions src/SignalR/clients/ts/yarn.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1