Skip to content

Commit 4863671

Browse files
authored
Merge pull request #59 from autofac/feature/build-metadata-update
Standardize build metadata and code formatting
2 parents b7ca1f3 + 01a0835 commit 4863671

15 files changed

Lines changed: 462 additions & 276 deletions

.editorconfig

Lines changed: 228 additions & 136 deletions
Large diffs are not rendered by default.

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: 3e8a8703264a2f4a69428a0aa4dcb512790b2c8c # frozen: v6.0.0
3+
rev: "3e8a8703264a2f4a69428a0aa4dcb512790b2c8c" # frozen: v6.0.0
44
hooks:
55
- id: check-json
66
- id: check-yaml
77
- id: check-merge-conflict
88
- id: end-of-file-fixer
99
- id: trailing-whitespace
1010
- repo: https://github.com/igorshubovych/markdownlint-cli
11-
rev: e72a3ca1632f0b11a07d171449fe447a7ff6795e # frozen: v0.48.0
11+
rev: "e72a3ca1632f0b11a07d171449fe447a7ff6795e" # frozen: v0.48.0
1212
hooks:
1313
- id: markdownlint
1414
args:
1515
- --fix
1616
- repo: https://github.com/tillig/json-sort-cli
17-
rev: 2b7e147e0933bd30b58133b6f287e5c695ff4f0e # frozen: v3.0.1
17+
rev: "2b7e147e0933bd30b58133b6f287e5c695ff4f0e" # frozen: v3.0.1
1818
hooks:
1919
- id: json-sort
2020
args:

build/Source.ruleset

Lines changed: 24 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,49 +4,39 @@
44
<Rules AnalyzerId="Microsoft.Usage" RuleNamespace="Microsoft.Usage">
55
<!-- Implement standard exception constructors - not all of the exception constructors (e.g., parameterless) are desired in our system. -->
66
<Rule Id="CA1032" Action="None" />
7+
<!-- Avoid excessive inheritance (must be explicitly enabled). -->
8+
<Rule Id="CA1501" Action="Warning" />
9+
<!-- Avoid excessive complexity (must be explicitly enabled). -->
10+
<Rule Id="CA1502" Action="Warning" />
11+
<!-- Avoid unmaintainable code (must be explicitly enabled). -->
12+
<Rule Id="CA1505" Action="Warning" />
13+
<!-- Avoid excessive class coupling (must be explicitly enabled). -->
14+
<Rule Id="CA1506" Action="Warning" />
15+
<!-- Use ArgumentNullException.ThrowIfNull - this isn't available until we stop targeting netstandard. -->
16+
<Rule Id="CA1510" Action="None" />
17+
<!-- Use ArgumentOutOfRangeException.ThrowIfNegative - this isn't available until we stop targeting anything below net8.0. -->
18+
<Rule Id="CA1512" Action="None" />
19+
<!-- Use ObjectDisposedException.ThrowIf - this isn't available until we stop targeting anything below net8.0. -->
20+
<Rule Id="CA1513" Action="None" />
721
<!-- Change names to avoid reserved word overlaps (e.g., Delegate, GetType, etc.) - too many of these in the public API, we'd break if we fixed it. -->
822
<Rule Id="CA1716" Action="None" />
9-
<!-- Implement serialization constructors - false positive when building .NET Core -->
23+
<!-- Cache a CompositeFormat object for use in String.Format - this isn't available until we stop targeting netstandard, and we only String.Format when throwing exceptions so the work/complexity isn't justified to increase perf just for those situations. -->
24+
<Rule Id="CA1863" Action="None" />
25+
<!-- Implement serialization constructors - false positive when building .NET Core. -->
1026
<Rule Id="CA2229" Action="None" />
11-
<!-- Mark ISerializable types with SerializableAttribute - false positive when building .NET Core -->
27+
<!-- Mark ISerializable types with SerializableAttribute - false positive when building .NET Core. -->
1228
<Rule Id="CA2237" Action="None" />
29+
<!-- Prefer generic overloads to using Type parameters - many aren't available in earlier frameworks; and we do a lot of reflection work in Autofac. -->
30+
<Rule Id="CA2263" Action="None" />
1331
</Rules>
1432
<Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.Analyzers">
15-
<!-- Prefix local calls with this -->
33+
<!-- Prefix local calls with this. -->
1634
<Rule Id="SA1101" Action="None" />
17-
<!-- Use built-in type alias -->
35+
<!-- Use built-in type alias. -->
1836
<Rule Id="SA1121" Action="None" />
19-
<!-- Use String.Empty instead of "" -->
37+
<!-- Use String.Empty instead of "". -->
2038
<Rule Id="SA1122" Action="None" />
21-
<!-- Using statements must be inside a namespace -->
22-
<Rule Id="SA1200" Action="None" />
23-
<!-- Enforce order of class members by member type -->
24-
<Rule Id="SA1201" Action="None" />
25-
<!-- Enforce order of class members by member visibility -->
26-
<Rule Id="SA1202" Action="None" />
27-
<!-- Enforce order of constantand static members -->
28-
<Rule Id="SA1203" Action="None" />
29-
<!-- Enforce order of static vs. non-static members -->
30-
<Rule Id="SA1204" Action="None" />
31-
<!-- Modifiers are not ordered - .editorconfig handles this -->
32-
<Rule Id="SA1206" Action="None" />
33-
<!-- Enforce order of readonly vs. non-readonly members -->
34-
<Rule Id="SA1214" Action="None" />
35-
<!-- Fields can't start with underscore -->
39+
<!-- Fields can't start with underscore. -->
3640
<Rule Id="SA1309" Action="None" />
37-
<!-- Suppressions must have a justification -->
38-
<Rule Id="SA1404" Action="None" />
39-
<!-- Parameter documentation must be in the right order -->
40-
<Rule Id="SA1612" Action="None" />
41-
<!-- Return value must be documented -->
42-
<Rule Id="SA1615" Action="None" />
43-
<!-- Generic type parameters must be documented -->
44-
<Rule Id="SA1618" Action="None" />
45-
<!-- Don't copy/paste documentation -->
46-
<Rule Id="SA1625" Action="None" />
47-
<!-- Exception documentation must not be empty -->
48-
<Rule Id="SA1627" Action="None" />
49-
<!-- Enable XML documentation output-->
50-
<Rule Id="SA1652" Action="None" />
5141
</Rules>
5242
</RuleSet>

build/Test.ruleset

Lines changed: 54 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,65 +2,86 @@
22
<RuleSet Name="Autofac Analyzer Rules" Description="Analyzer rules for Autofac assemblies." ToolsVersion="16.0">
33
<IncludeAll Action="Warning" />
44
<Rules AnalyzerId="Microsoft.Usage" RuleNamespace="Microsoft.Usage">
5+
<!-- Avoid excessive parameters on generic types (must be explicitly enabled). -->
6+
<Rule Id="CA1005" Action="Warning" />
7+
<!-- Don't catch general exceptions - test scenarios sometimes require general exception handling. -->
8+
<Rule Id="CA1031" Action="None" />
59
<!-- Implement standard exception constructors - not all of the exception constructors (e.g., parameterless) are desired in our system. -->
610
<Rule Id="CA1032" Action="None" />
7-
<!-- Do not nest types - we do that special for the DynamicProxy testing because there are lots of overlapping scenarios to test and interfaces/classes do need to be public. -->
8-
<Rule Id="CA1034" Action="None" />
9-
<!-- Identifiers should not contain underscores - underscores are helpful in test naming. -->
11+
<!-- Avoid empty interfaces - in unit tests for service resolution, this happens a lot. -->
12+
<Rule Id="CA1040" Action="None" />
13+
<!-- Do not pass literals as localized parameters - tests don't need to localize. -->
14+
<Rule Id="CA1303" Action="None" />
15+
<!-- Avoid excessive inheritance (must be explicitly enabled). -->
16+
<Rule Id="CA1501" Action="Warning" />
17+
<!-- Avoid excessive complexity (must be explicitly enabled). -->
18+
<Rule Id="CA1502" Action="Warning" />
19+
<!-- Avoid unmaintainable code (must be explicitly enabled). -->
20+
<Rule Id="CA1505" Action="Warning" />
21+
<!-- Avoid excessive class coupling (must be explicitly enabled). -->
22+
<Rule Id="CA1506" Action="Warning" />
23+
<!-- Use ArgumentNullException.ThrowIfNull - this isn't available until we stop targeting netstandard. -->
24+
<Rule Id="CA1510" Action="None" />
25+
<!-- Make API types internal - causes problems with tests and test assemblies. -->
26+
<Rule Id="CA1515" Action="None" />
27+
<!-- Remove the underscores from member name - unit test scenarios may use underscores. -->
1028
<Rule Id="CA1707" Action="None" />
1129
<!-- Change names to avoid reserved word overlaps (e.g., Delegate, GetType, etc.) - too many of these in the public API, we'd break if we fixed it. -->
1230
<Rule Id="CA1716" Action="None" />
31+
<!-- Internal class that appears to never be instantiated - lots of false positives here because they're test stubs created by Autofac registrations. -->
32+
<Rule Id="CA1812" Action="None" />
1333
<!-- Change Dispose() to call GC.SuppressFinalize - in tests we don't really care and it can impact readability. -->
1434
<Rule Id="CA1816" Action="None" />
1535
<!-- Mark members static - test methods may not access member data but also can't be static. -->
1636
<Rule Id="CA1822" Action="None" />
17-
<!-- Implement serialization constructors - false positive when building .NET Core -->
37+
<!-- Seal internal types for performance - in tests we don't really care and it gets painful to enforce. -->
38+
<Rule Id="CA1852" Action="None" />
39+
<!-- Prefer static readonly fields over constant array arguments - constant array arguments happen a lot in unit tests for assertions and test setup. -->
40+
<Rule Id="CA1861" Action="None" />
41+
<!-- Cache a CompositeFormat object for use in String.Format - this makes unit tests harder to read, and performance isn't an issue. -->
42+
<Rule Id="CA1863" Action="None" />
43+
<!-- Call ConfigureAwait on tasks - you shouldn't do this in unit test libraries; XUnit has an opposite analyzer. -->
44+
<Rule Id="CA2007" Action="None" />
45+
<!-- Implement serialization constructors - false positive when building .NET Core. -->
1846
<Rule Id="CA2229" Action="None" />
19-
<!-- Mark ISerializable types with SerializableAttribute - false positive when building .NET Core -->
47+
<!-- Use Uri instead of string parameters - strings are easier for testing. -->
48+
<Rule Id="CA2234" Action="None" />
49+
<!-- Mark ISerializable types with SerializableAttribute - false positive when building .NET Core. -->
2050
<Rule Id="CA2237" Action="None" />
51+
<!-- Prefer generic overloads to using Type parameters - we do a lot of reflection work in Autofac that needs to be tested. -->
52+
<Rule Id="CA2263" Action="None" />
2153
</Rules>
2254
<Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.Analyzers">
23-
<!-- Prefix local calls with this -->
55+
<!-- Prefix local calls with this. -->
2456
<Rule Id="SA1101" Action="None" />
25-
<!-- Use built-in type alias -->
57+
<!-- Use built-in type alias. -->
2658
<Rule Id="SA1121" Action="None" />
27-
<!-- Use String.Empty instead of "" -->
59+
<!-- Use String.Empty instead of "". -->
2860
<Rule Id="SA1122" Action="None" />
29-
<!-- Using statements must be inside a namespace -->
30-
<Rule Id="SA1200" Action="None" />
31-
<!-- Enforce order of class members by member type -->
61+
<!-- Enforce order of class members by member type - sometimes putting test classes/data by the test helps. -->
3262
<Rule Id="SA1201" Action="None" />
33-
<!-- Enforce order of class members by member visibility -->
63+
<!-- Enforce order of class members by member visibility - sometimes putting test classes/data by the test helps. -->
3464
<Rule Id="SA1202" Action="None" />
35-
<!-- Enforce order of constantand static members -->
36-
<Rule Id="SA1203" Action="None" />
37-
<!-- Enforce order of static vs. non-static members -->
65+
<!-- Enforce order of static vs. non-static members - sometimes putting test classes/data by the test helps. -->
3866
<Rule Id="SA1204" Action="None" />
39-
<!-- Modifiers are not ordered - .editorconfig handles this -->
40-
<Rule Id="SA1206" Action="None" />
41-
<!-- Enforce order of readonly vs. non-readonly members -->
42-
<Rule Id="SA1214" Action="None" />
43-
<!-- Fields can't start with underscore -->
67+
<!-- Fields can't start with underscore. -->
4468
<Rule Id="SA1309" Action="None" />
45-
<!-- Suppressions must have a justification -->
46-
<Rule Id="SA1404" Action="None" />
47-
<!-- Elements should be documented -->
69+
<!-- Elements should be documented. -->
4870
<Rule Id="SA1600" Action="None" />
49-
<!-- Enuemration items should be documented -->
71+
<!-- Partial items should be documented. -->
72+
<Rule Id="SA1601" Action="None" />
73+
<!-- Enumeration items should be documented. -->
5074
<Rule Id="SA1602" Action="None" />
51-
<!-- Parameter documentation must be in the right order -->
75+
<!-- Parameter should be documented. -->
76+
<Rule Id="SA1611" Action="None" />
77+
<!-- Parameter documentation must be in the right order. -->
5278
<Rule Id="SA1612" Action="None" />
53-
<!-- Return value must be documented -->
79+
<!-- Return value must be documented. -->
5480
<Rule Id="SA1615" Action="None" />
55-
<!-- Generic type parameters must be documented -->
81+
<!-- Generic type parameters must be documented. -->
5682
<Rule Id="SA1618" Action="None" />
57-
<!-- Don't copy/paste documentation -->
83+
<!-- Don't copy/paste documentation. -->
5884
<Rule Id="SA1625" Action="None" />
59-
<Rule Id="SA1633" Action="None" />
60-
<!-- Exception documentation must not be empty -->
61-
<Rule Id="SA1627" Action="None" />
62-
<!-- Enable XML documentation output-->
63-
<Rule Id="SA1652" Action="None" />
6485
<!-- Private member is unused - tests for reflection require members that may not get used. -->
6586
<Rule Id="IDE0051" Action="None" />
6687
<!-- Private member assigned value never read - tests for reflection require values that may not get used. -->

build/stylecop.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
"licenseName": "MIT"
1010
},
1111
"xmlHeader": false
12+
},
13+
"orderingRules": {
14+
"usingDirectivesPlacement": "outsideNamespace"
1215
}
1316
}
1417
}

default.proj

Lines changed: 57 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,67 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<Project DefaultTargets="Build" ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
<Project DefaultTargets="All" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="Current">
33
<PropertyGroup>
4-
<Configuration Condition="'$(Configuration)' == ''">Release</Configuration>
5-
<PackageVersion Condition="'$(PackageVersion)' == ''">7.1.0</PackageVersion>
6-
<Solution>$(MSBuildThisFileDirectory)Autofac.Extras.DynamicProxy.sln</Solution>
7-
<ArtifactsPath>$(MSBuildThisFileDirectory)artifacts</ArtifactsPath>
8-
<PackagesPath>$(ArtifactsPath)/packages</PackagesPath>
9-
<LogsPath>$(ArtifactsPath)/logs</LogsPath>
4+
<!-- Increment the overall semantic version here. -->
5+
<Version>7.1.0</Version>
6+
<SolutionName>Autofac.Extras.DynamicProxy</SolutionName>
7+
<Configuration Condition="'$(Configuration)'==''">Release</Configuration>
8+
<ArtifactDirectory>$([System.IO.Path]::Combine($(MSBuildProjectDirectory),"artifacts"))</ArtifactDirectory>
9+
<PackageDirectory>$([System.IO.Path]::Combine($(ArtifactDirectory),"packages"))</PackageDirectory>
10+
<LogDirectory>$([System.IO.Path]::Combine($(ArtifactDirectory),"logs"))</LogDirectory>
11+
<CoverageRunSettings>$([System.IO.Path]::Combine($(MSBuildProjectDirectory),'build/Coverage.runsettings'))</CoverageRunSettings>
12+
<BuildDateTime>$([System.DateTimeOffset]::UtcNow.ToString('yyyyMMddTHHmmssZ'))</BuildDateTime>
1013
</PropertyGroup>
11-
12-
<!-- Clean -->
14+
<Choose>
15+
<When Condition="'$(GITHUB_REF_NAME)'==''">
16+
<PropertyGroup>
17+
<Version>$(Version)-local</Version>
18+
</PropertyGroup>
19+
</When>
20+
<When Condition="'$(GITHUB_REF_NAME)'=='master' Or $([System.Text.RegularExpressions.Regex]::IsMatch($(GITHUB_REF_NAME), `^v.+\..+\..+`))">
21+
<PropertyGroup>
22+
<Version>$(Version)</Version>
23+
</PropertyGroup>
24+
</When>
25+
<When Condition="'$(GITHUB_REF_NAME)'=='develop'">
26+
<PropertyGroup>
27+
<Version>$(Version)-beta$(BuildDateTime)</Version>
28+
</PropertyGroup>
29+
</When>
30+
<Otherwise>
31+
<PropertyGroup>
32+
<Version>$(Version)-alpha$(BuildDateTime)</Version>
33+
</PropertyGroup>
34+
</Otherwise>
35+
</Choose>
1336
<ItemGroup>
14-
<FilesToDelete Include="$(ArtifactsPath)/**/*.*" />
37+
<CleanDirectory Include="$(ArtifactDirectory)" />
38+
<SourceProject Include="$(MSBuildProjectDirectory)/src/**/*.csproj" />
39+
<TestProject Include="$(MSBuildProjectDirectory)/test/**/*.csproj" />
40+
<SolutionFile Include="$(SolutionName).sln" />
1541
</ItemGroup>
16-
42+
<Target Name="All">
43+
<Message Text="****************************************" Importance="high" />
44+
<Message Text="$(SolutionName) v$(Version)" Importance="high" />
45+
<Message Text="$(Configuration) Configuration" Importance="high" />
46+
<Message Text="$(BuildDateTime)" Importance="high" />
47+
<Message Text="****************************************" Importance="high" />
48+
<CallTarget Targets="Clean;Compile;Test;Package" />
49+
</Target>
1750
<Target Name="Clean">
18-
<Delete Files="@(FilesToDelete)" />
19-
<RemoveDir Directories="$(ArtifactsPath)" />
51+
<RemoveDir Directories="@(CleanDirectory)" />
52+
<RemoveDir Directories="%(SourceProject.RootDir)%(SourceProject.Directory)bin;%(SourceProject.RootDir)%(SourceProject.Directory)obj" />
53+
<RemoveDir Directories="%(TestProject.RootDir)%(TestProject.Directory)bin;%(TestProject.RootDir)%(TestProject.Directory)obj" />
54+
</Target>
55+
<Target Name="Compile">
56+
<Exec Command="dotnet --info" />
57+
<Exec Command="dotnet build &quot;%(SolutionFile.FullPath)&quot; -c $(Configuration) /p:Version=$(Version)" />
2058
</Target>
21-
22-
<!-- Build and pack -->
23-
<Target Name="BuildPack" DependsOnTargets="Clean">
24-
<Exec Command="dotnet build &quot;$(Solution)&quot; -c $(Configuration) -p:Version=$(PackageVersion) -warnaserror" />
25-
<Exec Command="dotnet pack &quot;$(Solution)&quot; -c $(Configuration) -p:Version=$(PackageVersion) -o &quot;$(PackagesPath)&quot; --no-build -warnaserror" />
59+
<Target Name="Package">
60+
<MakeDir Directories="$(PackageDirectory)" />
61+
<Exec Command="dotnet pack &quot;%(SourceProject.Identity)&quot; -c $(Configuration) --no-build --output &quot;$(PackageDirectory)&quot; /p:Version=$(Version)" />
2662
</Target>
27-
28-
<!-- Test -->
29-
<Target Name="Test" DependsOnTargets="BuildPack">
30-
<ItemGroup>
31-
<TestProjects Include="$(MSBuildThisFileDirectory)test/**/*Test.csproj" />
32-
</ItemGroup>
33-
<PropertyGroup>
34-
<TestCounter>0</TestCounter>
35-
</PropertyGroup>
36-
<Exec Command="dotnet test &quot;%(TestProjects.FullPath)&quot; -c $(Configuration) --no-build --collect &quot;XPlat Code Coverage&quot; --settings:&quot;$(MSBuildThisFileDirectory)build/Coverage.runsettings&quot; --results-directory &quot;$(LogsPath)/%(TestProjects.Filename)&quot; -l:trx" />
63+
<Target Name="Test">
64+
<MakeDir Directories="$(LogDirectory)" />
65+
<Exec Command="dotnet test &quot;%(TestProject.Identity)&quot; -c $(Configuration) --results-directory &quot;$(LogDirectory)&quot; --logger:trx /p:Version=$(Version) --collect:&quot;XPlat Code Coverage&quot; --settings &quot;$(CoverageRunSettings)&quot;" />
3766
</Target>
38-
39-
<!-- Main build target -->
40-
<Target Name="Build" DependsOnTargets="Test" />
4167
</Project>

src/Autofac.Extras.DynamicProxy/InterceptAttribute.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,11 @@ namespace Autofac.Extras.DynamicProxy;
1010
/// Indicates that a type should be intercepted.
1111
/// </summary>
1212
[ExcludeFromCodeCoverage]
13-
[SuppressMessage("Microsoft.Performance", "CA1813:AvoidUnsealedAttributes")]
14-
[SuppressMessage("Microsoft.Design", "CA1019:DefineAccessorsForAttributeArguments")]
13+
[SuppressMessage("Microsoft.Performance", "CA1813:AvoidUnsealedAttributes", Justification = "Attribute is unsealed to allow derived types to provide additional interception metadata.")]
14+
[SuppressMessage("Microsoft.Design", "CA1019:DefineAccessorsForAttributeArguments", Justification = "Constructor arguments are transformed into Service instances and exposed through InterceptorService property.")]
1515
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface, AllowMultiple = true)]
1616
public class InterceptAttribute : Attribute
1717
{
18-
/// <summary>
19-
/// Gets the interceptor service.
20-
/// </summary>
21-
public Service InterceptorService { get; private set; }
22-
2318
/// <summary>
2419
/// Initializes a new instance of the <see cref="InterceptAttribute"/> class.
2520
/// </summary>
@@ -49,4 +44,12 @@ public InterceptAttribute(Type interceptorServiceType)
4944
: this(new TypedService(interceptorServiceType))
5045
{
5146
}
47+
48+
/// <summary>
49+
/// Gets the interceptor service.
50+
/// </summary>
51+
public Service InterceptorService
52+
{
53+
get; private set;
54+
}
5255
}

0 commit comments

Comments
 (0)