Skip to content

Commit 90340ba

Browse files
authored
Assembly Loading Hotfix (#292)
1 parent 85c8d1d commit 90340ba

File tree

3 files changed

+35
-25
lines changed

3 files changed

+35
-25
lines changed

.github/releases/v0.8.0-beta4.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- Adds an IAM Access Analyzer, which will collect the minimum IAM permissions needed for running your lambda or custom resource and output them to a file. By default, this file is located at $(IntermediateOutputPath)IamPermissions.txt, but can be customized via the $(LambdajectionIamPermissionsOutputPath) property.
2+
- Fixed an issue where compilation would sometimes fail for custom resources with an error like 'Could not load file Microsoft.Extensions.Hosting'.

src/Generator/Program.cs

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
using System.Runtime.Loader;
77

88
using Microsoft.CodeAnalysis;
9-
using Microsoft.Extensions.DependencyInjection;
10-
using Microsoft.Extensions.Hosting;
11-
using Microsoft.Extensions.Logging;
129

1310
#pragma warning disable SA1204, SA1009
1411
namespace Lambdajection.Generator
@@ -60,7 +57,8 @@ where file.Contains("netstandard") || file.Contains("net5.0")
6057
};
6158
}
6259

63-
Run(context);
60+
var host = new ProgramHost();
61+
host.Run(context);
6462
}
6563

6664
private IEnumerable<string> GetBuildTimeAssemblies(GeneratorExecutionContext context)
@@ -74,26 +72,5 @@ private IEnumerable<string> GetBuildTimeAssemblies(GeneratorExecutionContext con
7472
where assemblyName != string.Empty
7573
select assemblyName;
7674
}
77-
78-
private void Run(GeneratorExecutionContext context)
79-
{
80-
Host.CreateDefaultBuilder()
81-
.ConfigureServices((builderContext, services) =>
82-
{
83-
services.AddSingleton(new ProgramContext { GeneratorExecutionContext = context });
84-
services.AddSingleton<IHost, GeneratorHost>();
85-
new Startup().ConfigureServices(services);
86-
87-
services.AddLogging(options =>
88-
{
89-
options.ClearProviders();
90-
options.AddConsole();
91-
});
92-
})
93-
.Build()
94-
.RunAsync(context.CancellationToken)
95-
.GetAwaiter()
96-
.GetResult();
97-
}
9875
}
9976
}

src/Generator/ProgramHost.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using Microsoft.CodeAnalysis;
2+
using Microsoft.Extensions.DependencyInjection;
3+
using Microsoft.Extensions.Hosting;
4+
using Microsoft.Extensions.Logging;
5+
6+
namespace Lambdajection.Generator
7+
{
8+
public class ProgramHost
9+
{
10+
public void Run(GeneratorExecutionContext context)
11+
{
12+
Host.CreateDefaultBuilder()
13+
.ConfigureServices((builderContext, services) =>
14+
{
15+
services.AddSingleton(new ProgramContext { GeneratorExecutionContext = context });
16+
services.AddSingleton<IHost, GeneratorHost>();
17+
new Startup().ConfigureServices(services);
18+
19+
services.AddLogging(options =>
20+
{
21+
options.ClearProviders();
22+
options.AddConsole();
23+
});
24+
})
25+
.Build()
26+
.RunAsync(context.CancellationToken)
27+
.GetAwaiter()
28+
.GetResult();
29+
}
30+
}
31+
}

0 commit comments

Comments
 (0)