Skip to content

Commit 8ef3abc

Browse files
committed
Make Stunts.DynamicProxy an explicit opt-in package
The Stunts package no longer embeds Stunts.DynamicProxy. Compile-time stunts are the default. Projects that can't use them (Visual Basic, C# before 9.0), or don't want them, now install the Stunts.DynamicProxy package explicitly.
1 parent 2a72ba1 commit 8ef3abc

13 files changed

Lines changed: 58 additions & 48 deletions

File tree

‎readme.md‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Stunts is a .NET Standard 2.0 library and runs on any runtime that supports that
4040

4141
Compile-time proxy generation leverages [Roslyn source generators](https://github.com/dotnet/roslyn/blob/master/docs/features/source-generators.cookbook.md) and therefore requires C# 9.0, which at this time is included in Visual Studio 16.8 (preview or later) and the .NET 5.0 SDK (RC or later). Compile-time generated proxies support the broadest possible run-time platforms since they don't require any Reflection.Emit, and also don't pay that performance cost either.
4242

43-
Whenever compile-time proxy generation is not available, a fallback generation strategy is used instead, which leverages [Castle DynamicProxy](https://github.com/castleproject/Core/blob/master/docs/dynamicproxy-introduction.md) to provide the run-time code generation.
43+
Whenever compile-time proxy generation is not available (i.e. Visual Basic or C# versions before 9.0), install the `Stunts.DynamicProxy` package instead, which leverages [Castle DynamicProxy](https://github.com/castleproject/Core/blob/master/docs/dynamicproxy-introduction.md) to provide the run-time code generation.
4444

4545
The client API for configuring proxy behaviors in either case is exactly the same.
4646

@@ -109,17 +109,17 @@ As you can see, the Stunts API itself uses the same extensibility mechanism that
109109

110110
### Static vs Dynamic Stunts
111111

112-
Depending on the project and platform, Stunts will automatically choose whether to use run-time proxies or compile-time ones (powered by Roslyn source generators). The latter are only supported when building C# 9.0+ projects.
112+
By default, Stunts generates proxies at compile-time (powered by Roslyn source generators), which is only supported when building C# 9.0+ projects.
113113

114-
You can opt out of the static stunts by setting `EnableCompileTimeStunts=false` in your project file:
114+
Whenever compile-time stunts are not supported (or not wanted), install the `Stunts.DynamicProxy` package, which switches the project to run-time proxies based on Castle.Core:
115115

116116
```xml
117-
<PropertyGroup>
118-
<EnableCompileTimeStunts>false</EnableCompileTimeStunts>
119-
</PropertyGroup>
117+
<ItemGroup>
118+
<PackageReference Include="Stunts.DynamicProxy" Version="..." />
119+
</ItemGroup>
120120
```
121121

122-
This will switch the project to run-time proxies based on Castle.Core.
122+
The package sets `EnableCompileTimeStunts=false` for you. Projects that can't use compile-time stunts and don't reference `Stunts.DynamicProxy` get a build warning (`ST011`).
123123

124124
## Debugging Optimizations
125125

‎src/Acceptance/Directory.Build.props‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
<ItemGroup>
2020
<PackageVersion Include="Stunts" Version="$(Version)" />
21+
<PackageVersion Include="Stunts.DynamicProxy" Version="$(Version)" />
2122
<PackageVersion Include="ManualStunts" Version="$(Version)" />
2223
</ItemGroup>
2324

‎src/Acceptance/Dynamic.Basic/Dynamic.Basic.vbproj‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<PackageReference Include="xunit" />
1313
<PackageReference Include="xunit.runner.visualstudio" />
1414
<PackageReference Include="Stunts" />
15+
<PackageReference Include="Stunts.DynamicProxy" />
1516
</ItemGroup>
1617

1718
</Project>

‎src/Acceptance/Dynamic/Dynamic.csproj‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
<PropertyGroup>
44
<TargetFramework>net10.0</TargetFramework>
5-
<EnableCompileTimeStunts>false</EnableCompileTimeStunts>
65
</PropertyGroup>
76

87
<ItemGroup>
@@ -11,6 +10,7 @@
1110
<PackageReference Include="xunit" />
1211
<PackageReference Include="xunit.runner.visualstudio" />
1312
<PackageReference Include="Stunts" />
13+
<PackageReference Include="Stunts.DynamicProxy" />
1414
<PackageReference Include="ManualStunts" />
1515
</ItemGroup>
1616

‎src/Stunts.CodeAnalysis/readme.md‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Stunts is a .NET Standard 2.0 library and runs on any runtime that supports that
1818

1919
Compile-time proxy generation leverages [Roslyn source generators](https://github.com/dotnet/roslyn/blob/master/docs/features/source-generators.cookbook.md) and therefore requires C# 9.0, which at this time is included in Visual Studio 16.8 (preview or later) and the .NET 5.0 SDK (RC or later). Compile-time generated proxies support the broadest possible run-time platforms since they don't require any Reflection.Emit, and also don't pay that performance cost either.
2020

21-
Whenever compile-time proxy generation is not available, a fallback generation strategy is used instead, which leverages [Castle DynamicProxy](https://github.com/castleproject/Core/blob/master/docs/dynamicproxy-introduction.md) to provide the run-time code generation.
21+
Whenever compile-time proxy generation is not available (i.e. Visual Basic or C# versions before 9.0), install the `Stunts.DynamicProxy` package instead, which leverages [Castle DynamicProxy](https://github.com/castleproject/Core/blob/master/docs/dynamicproxy-introduction.md) to provide the run-time code generation.
2222

2323
The client API for configuring proxy behaviors in either case is exactly the same.
2424

@@ -87,17 +87,17 @@ As you can see, the Stunts API itself uses the same extensibility mechanism that
8787

8888
### Static vs Dynamic Stunts
8989

90-
Depending on the project and platform, Stunts will automatically choose whether to use run-time proxies or compile-time ones (powered by Roslyn source generators). The latter are only supported when building C# 9.0+ projects.
90+
By default, Stunts generates proxies at compile-time (powered by Roslyn source generators), which is only supported when building C# 9.0+ projects.
9191

92-
You can opt out of the static stunts by setting `EnableCompileTimeStunts=false` in your project file:
92+
Whenever compile-time stunts are not supported (or not wanted), install the `Stunts.DynamicProxy` package, which switches the project to run-time proxies based on Castle.Core:
9393

9494
```xml
95-
<PropertyGroup>
96-
<EnableCompileTimeStunts>false</EnableCompileTimeStunts>
97-
</PropertyGroup>
95+
<ItemGroup>
96+
<PackageReference Include="Stunts.DynamicProxy" Version="..." />
97+
</ItemGroup>
9898
```
9999

100-
This will switch the project to run-time proxies based on Castle.Core.
100+
The package sets `EnableCompileTimeStunts=false` for you. Projects that can't use compile-time stunts and don't reference `Stunts.DynamicProxy` get a build warning (`ST011`).
101101

102102
## Debugging Optimizations
103103

‎src/Stunts.DynamicProxy/Stunts.DynamicProxy.csproj‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
<IsPackable>true</IsPackable>
77
<Description>
88
Provides run-time stunt generation using Castle DynamicProxy, for projects that
9-
cannot use the compile-time stunt generation provided built-in Stunts, which
10-
requires C# 9.0.
9+
cannot use the compile-time stunt generation built into Stunts, which
10+
requires C# 9.0. Installing this package disables compile-time stunts.
1111
</Description>
1212
</PropertyGroup>
1313

@@ -22,14 +22,12 @@
2222

2323
<ItemGroup>
2424
<ProjectReference Include="..\Stunts\Stunts.csproj" Pack="false" />
25+
<ProjectReference Include="..\Stunts.Package\Stunts.Package.msbuildproj" ReferenceOutputAssembly="false" />
2526
</ItemGroup>
2627

2728
<ItemGroup>
28-
<!-- When not packed standalone, include the build targets/sources too.
29-
The project readme is the package readme, not a build asset. -->
30-
<None Remove="readme.md" Condition="'$(IsPackable)' != 'true'" />
31-
<None Update="@(None)" PackFolder="build\netstandard2.0" Condition="'$(IsPackable)' != 'true'" />
32-
<PackageFile Include="@(None)" PackFolder="buildTransitive\netstandard2.0" Condition="'$(IsPackable)' != 'true'" />
29+
<None Update="Stunt.*.*;*.props;*.targets" PackFolder="build\netstandard2.0" />
30+
<PackageFile Include="Stunt.*.*;*.props;*.targets" PackFolder="buildTransitive\netstandard2.0" />
3331
</ItemGroup>
3432

3533
</Project>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Project>
2+
3+
<PropertyGroup>
4+
<EnableCompileTimeStunts>false</EnableCompileTimeStunts>
5+
<StuntsDynamicProxy>true</StuntsDynamicProxy>
6+
</PropertyGroup>
7+
8+
</Project>

‎src/Stunts.DynamicProxy/Stunts.DynamicProxy.targets‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project>
22

3-
<ItemGroup Condition="'$(EnableRunTimeStunts)' != 'false'">
3+
<ItemGroup Condition="'$(EnableCompileTimeStunts)' != 'true'">
44
<Compile Include="$(MSBuildThisFileDirectory)Stunt.DynamicFactory$(DefaultLanguageSourceExtension)"
55
Condition="Exists('$(MSBuildThisFileDirectory)Stunt.DynamicFactory$(DefaultLanguageSourceExtension)')"
66
Visible="false" />

‎src/Stunts.DynamicProxy/readme.md‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Stunts is a .NET Standard 2.0 library and runs on any runtime that supports that
1818

1919
Compile-time proxy generation leverages [Roslyn source generators](https://github.com/dotnet/roslyn/blob/master/docs/features/source-generators.cookbook.md) and therefore requires C# 9.0, which at this time is included in Visual Studio 16.8 (preview or later) and the .NET 5.0 SDK (RC or later). Compile-time generated proxies support the broadest possible run-time platforms since they don't require any Reflection.Emit, and also don't pay that performance cost either.
2020

21-
Whenever compile-time proxy generation is not available, a fallback generation strategy is used instead, which leverages [Castle DynamicProxy](https://github.com/castleproject/Core/blob/master/docs/dynamicproxy-introduction.md) to provide the run-time code generation.
21+
Whenever compile-time proxy generation is not available (i.e. Visual Basic or C# versions before 9.0), install the `Stunts.DynamicProxy` package instead, which leverages [Castle DynamicProxy](https://github.com/castleproject/Core/blob/master/docs/dynamicproxy-introduction.md) to provide the run-time code generation.
2222

2323
The client API for configuring proxy behaviors in either case is exactly the same.
2424

@@ -87,17 +87,17 @@ As you can see, the Stunts API itself uses the same extensibility mechanism that
8787

8888
### Static vs Dynamic Stunts
8989

90-
Depending on the project and platform, Stunts will automatically choose whether to use run-time proxies or compile-time ones (powered by Roslyn source generators). The latter are only supported when building C# 9.0+ projects.
90+
By default, Stunts generates proxies at compile-time (powered by Roslyn source generators), which is only supported when building C# 9.0+ projects.
9191

92-
You can opt out of the static stunts by setting `EnableCompileTimeStunts=false` in your project file:
92+
Whenever compile-time stunts are not supported (or not wanted), install the `Stunts.DynamicProxy` package, which switches the project to run-time proxies based on Castle.Core:
9393

9494
```xml
95-
<PropertyGroup>
96-
<EnableCompileTimeStunts>false</EnableCompileTimeStunts>
97-
</PropertyGroup>
95+
<ItemGroup>
96+
<PackageReference Include="Stunts.DynamicProxy" Version="..." />
97+
</ItemGroup>
9898
```
9999

100-
This will switch the project to run-time proxies based on Castle.Core.
100+
The package sets `EnableCompileTimeStunts=false` for you. Projects that can't use compile-time stunts and don't reference `Stunts.DynamicProxy` get a build warning (`ST011`).
101101

102102
## Debugging Optimizations
103103

‎src/Stunts.Package/Stunts.Package.msbuildproj‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ service.AddBehavior(...);
3030
<ItemGroup>
3131
<ProjectReference Include="..\Stunts\Stunts.csproj" />
3232
<ProjectReference Include="..\Stunts.CodeAnalysis\Stunts.CodeAnalysis.csproj" AdditionalProperties="IsPackable=false" />
33-
<ProjectReference Include="..\Stunts.DynamicProxy\Stunts.DynamicProxy.csproj" AdditionalProperties="IsPackable=false" />
3433
<ProjectReference Include="..\Stunts.StaticProxy\Stunts.StaticProxy.csproj" AdditionalProperties="IsPackable=false" />
3534
</ItemGroup>
3635
<Target Name="CopyVersion" Inputs="Stunts.Version.props" Outputs="$(IntermediateOutputPath)Stunts.Version.props">

0 commit comments

Comments
 (0)