Skip to content

Commit 92316fd

Browse files
committed
add MSBuild targets for auto-initializers in Kafka libraries
1 parent f587b0f commit 92316fd

File tree

3 files changed

+126
-0
lines changed

3 files changed

+126
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<Project>
2+
3+
<!-- Automatically inject a module initializer for the Kafka.Avro library -->
4+
<Target Name="InjectKafkaAvroAutoInitializer" BeforeTargets="BeforeCompile">
5+
6+
<!-- Generate the C# content directly -->
7+
<PropertyGroup>
8+
<GeneratedFileContent>// Generated by AWS Lambda Powertools Auto-Initializer
9+
using System.Runtime.CompilerServices%3B
10+
11+
internal static class PowertoolsKafkaAvroAutoInitializer
12+
{
13+
[ModuleInitializer]
14+
internal static void Initialize()
15+
{
16+
try
17+
{
18+
// Force load the Powertools assembly by calling its initialization method
19+
AWS.Lambda.Powertools.Kafka.Avro.Internal.EnvWrapper.SetExecutionEnvironment()%3B
20+
}
21+
catch
22+
{
23+
// Ignore errors - the assembly might not be available in all scenarios
24+
}
25+
}
26+
}</GeneratedFileContent>
27+
</PropertyGroup>
28+
29+
<!-- Write the generated file -->
30+
<WriteLinesToFile
31+
File="$(IntermediateOutputPath)PowertoolsKafkaAvroAutoInitializer.g.cs"
32+
Lines="$(GeneratedFileContent)"
33+
Overwrite="true" />
34+
35+
<!-- Include the generated file in compilation -->
36+
<ItemGroup>
37+
<Compile Include="$(IntermediateOutputPath)PowertoolsKafkaAvroAutoInitializer.g.cs" />
38+
</ItemGroup>
39+
40+
</Target>
41+
42+
</Project>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<Project>
2+
3+
<!-- Automatically inject a module initializer for the Kafka.Json library -->
4+
<Target Name="InjectKafkaJsonAutoInitializer" BeforeTargets="BeforeCompile">
5+
6+
<!-- Generate the C# content directly -->
7+
<PropertyGroup>
8+
<GeneratedFileContent>// Generated by AWS Lambda Powertools Auto-Initializer
9+
using System.Runtime.CompilerServices%3B
10+
11+
internal static class PowertoolsKafkaJsonAutoInitializer
12+
{
13+
[ModuleInitializer]
14+
internal static void Initialize()
15+
{
16+
try
17+
{
18+
// Force load the Powertools assembly by calling its initialization method
19+
AWS.Lambda.Powertools.Kafka.Json.Internal.EnvWrapper.SetExecutionEnvironment()%3B
20+
}
21+
catch
22+
{
23+
// Ignore errors - the assembly might not be available in all scenarios
24+
}
25+
}
26+
}</GeneratedFileContent>
27+
</PropertyGroup>
28+
29+
<!-- Write the generated file -->
30+
<WriteLinesToFile
31+
File="$(IntermediateOutputPath)PowertoolsKafkaJsonAutoInitializer.g.cs"
32+
Lines="$(GeneratedFileContent)"
33+
Overwrite="true" />
34+
35+
<!-- Include the generated file in compilation -->
36+
<ItemGroup>
37+
<Compile Include="$(IntermediateOutputPath)PowertoolsKafkaJsonAutoInitializer.g.cs" />
38+
</ItemGroup>
39+
40+
</Target>
41+
42+
</Project>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<Project>
2+
3+
<!-- Automatically inject a module initializer for the Kafka.Protobuf library -->
4+
<Target Name="InjectKafkaProtobufAutoInitializer" BeforeTargets="BeforeCompile">
5+
6+
<!-- Generate the C# content directly -->
7+
<PropertyGroup>
8+
<GeneratedFileContent>// Generated by AWS Lambda Powertools Auto-Initializer
9+
using System.Runtime.CompilerServices%3B
10+
11+
internal static class PowertoolsKafkaProtobufAutoInitializer
12+
{
13+
[ModuleInitializer]
14+
internal static void Initialize()
15+
{
16+
try
17+
{
18+
// Force load the Powertools assembly by calling its initialization method
19+
AWS.Lambda.Powertools.Kafka.Protobuf.Internal.EnvWrapper.SetExecutionEnvironment()%3B
20+
}
21+
catch
22+
{
23+
// Ignore errors - the assembly might not be available in all scenarios
24+
}
25+
}
26+
}</GeneratedFileContent>
27+
</PropertyGroup>
28+
29+
<!-- Write the generated file -->
30+
<WriteLinesToFile
31+
File="$(IntermediateOutputPath)PowertoolsKafkaProtobufAutoInitializer.g.cs"
32+
Lines="$(GeneratedFileContent)"
33+
Overwrite="true" />
34+
35+
<!-- Include the generated file in compilation -->
36+
<ItemGroup>
37+
<Compile Include="$(IntermediateOutputPath)PowertoolsKafkaProtobufAutoInitializer.g.cs" />
38+
</ItemGroup>
39+
40+
</Target>
41+
42+
</Project>

0 commit comments

Comments
 (0)