Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.IO;
Expand Down Expand Up @@ -29,15 +30,27 @@ public class FrameworkDependencyInjectionGenerator : IIncrementalGenerator
{
public void Initialize(IncrementalGeneratorInitializationContext context)
{
var options = context.AnalyzerConfigOptionsProvider
.Select((c, _) =>
c.GlobalOptions.TryGetValue("build_property.EnableSystemWebDependencyInjectionGenerator", out var enableSwitch) && enableSwitch.Equals("true", StringComparison.OrdinalIgnoreCase));

var usedFrameworks = context.CompilationProvider.Select((compilation, token) => new FrameworksUsed
{
HttpApplicationHost = compilation.GetTypeByMetadataName("Microsoft.AspNetCore.SystemWebAdapters.Hosting.IDependencyRegistrar") is { },
WebApi = compilation.GetTypeByMetadataName("System.Web.Http.Dependencies.IDependencyResolver") is { },
Mvc = compilation.GetTypeByMetadataName("System.Web.Mvc.IDependencyResolver") is { },
});

context.RegisterSourceOutput(usedFrameworks, (context, frameworks) =>
context.RegisterSourceOutput(usedFrameworks.Combine(options), (context, repoContext) =>
{
var frameworks = repoContext.Left;
var isEnabled = repoContext.Right;

if (!isEnabled)
{
return;
}

// No need to do anything if they're not referencing SystemWebAdapters with the ASP.NET Framework hosting infrastructure
if (!frameworks.HttpApplicationHost)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project>
<PropertyGroup>
<EnableSystemWebDependencyInjectionGenerator Condition=" '$(EnableSystemWebDependencyInjectionGenerator)' == '' ">true</EnableSystemWebDependencyInjectionGenerator>
</PropertyGroup>
<ItemGroup>
<CompilerVisibleProperty Include="EnableSystemWebDependencyInjectionGenerator" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<Project>
<Import Project="$(MSBuildThisFileDirectory)NuGetContentFiles.targets"/>
<Import Project="$(MSBuildThisFileDirectory)DependencyInjectionGenerator.targets"/>
</Project>