Skip to content

Commit 3b4db6d

Browse files
authored
[build] Use compiler constant to toggle experimental public apis (#4735)
1 parent a4fae4f commit 3b4db6d

File tree

122 files changed

+1112
-439
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+1112
-439
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ csharp_indent_switch_labels = true
3434
csharp_indent_labels = flush_left
3535

3636
# Modifier preferences
37-
csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:suggestion
37+
csharp_preferred_modifier_order = public,private,protected,internal,file,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,required,volatile,async:suggestion
3838
dotnet_style_require_accessibility_modifiers = for_non_interface_members:silent
3939

4040
# this. preferences

.github/workflows/apicompatibility.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ jobs:
2424
run: dotnet restore
2525

2626
- name: Build
27-
run: dotnet build --configuration Release --no-restore
27+
run: dotnet build --configuration Release --no-restore --property:ExposeExperimentalFeatures=true

.github/workflows/ci.yml

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ on:
1111
- '**.md'
1212

1313
jobs:
14-
build-test:
14+
build-test-stable:
1515
strategy:
1616
fail-fast: false # ensures the entire test matrix is run, even if one permutation fails
1717
matrix:
@@ -34,7 +34,35 @@ jobs:
3434
run: dotnet restore
3535

3636
- name: Build
37-
run: dotnet build --configuration Release --no-restore
37+
run: dotnet build --configuration Release --no-restore --property:ExposeExperimentalFeatures=false
38+
39+
- name: Test ${{ matrix.version }}
40+
run: dotnet test **/bin/**/${{ matrix.version }}/*.Tests.dll --logger:"console;verbosity=detailed"
41+
42+
build-test-experimental:
43+
strategy:
44+
fail-fast: false # ensures the entire test matrix is run, even if one permutation fails
45+
matrix:
46+
os: [ windows-latest, ubuntu-latest ]
47+
version: [ net462, net6.0, net7.0 ]
48+
exclude:
49+
- os: ubuntu-latest
50+
version: net462
51+
52+
runs-on: ${{ matrix.os }}
53+
steps:
54+
- uses: actions/checkout@v3
55+
with:
56+
fetch-depth: 0 # fetching all
57+
58+
- name: Setup dotnet
59+
uses: actions/setup-dotnet@v3
60+
61+
- name: Install dependencies
62+
run: dotnet restore
63+
64+
- name: Build
65+
run: dotnet build --configuration Release --no-restore --property:ExposeExperimentalFeatures=true
3866

3967
- name: Test ${{ matrix.version }}
4068
run: dotnet test **/bin/**/${{ matrix.version }}/*.Tests.dll --logger:"console;verbosity=detailed"

.github/workflows/code-coverage.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
run: dotnet restore
3232

3333
- name: dotnet build
34-
run: dotnet build --configuration Release --no-restore
34+
run: dotnet build --configuration Release --no-restore --property:ExposeExperimentalFeatures=true
3535

3636
# - name: dotnet test
3737
# run: dotnet test --collect:"XPlat Code Coverage" --results-directory:"TestResults" --configuration Release --no-build -- RunConfiguration.DisableAppDomain=true

Directory.Packages.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
<PackageVersion Include="Grpc.Tools" Version="[2.56.2,3.0)" />
6868
<PackageVersion Include="Microsoft.AspNetCore.TestHost" Version="7.0.9" />
6969
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="7.0.9" />
70-
<PackageVersion Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="[3.3.3]" />
70+
<PackageVersion Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="[3.11.0-beta1.23402.2]" />
7171
<PackageVersion Include="Microsoft.CodeCoverage" Version="[17.6.3]" />
7272
<PackageVersion Include="Microsoft.Data.SqlClient" Version="2.1.2" />
7373
<PackageVersion Include="Microsoft.DotNet.ApiCompat" Version="6.0.0-beta.21308.1" />
@@ -81,7 +81,7 @@
8181
<PackageVersion Include="Moq" Version="[4.18.4,5.0)" />
8282
<PackageVersion Include="OpenTelemetry.Instrumentation.Runtime" Version="[1.5.0,2.0)" />
8383
<PackageVersion Include="RabbitMQ.Client" Version="[6.5.0,7.0)" />
84-
<PackageVersion Include="StyleCop.Analyzers" Version="[1.2.0-beta.435,2.0)" />
84+
<PackageVersion Include="StyleCop.Analyzers" Version="[1.2.0-beta.507,2.0)" />
8585
<PackageVersion Include="Swashbuckle.AspNetCore" Version="[6.4.0]" />
8686
<PackageVersion Include="System.Net.Http" Version="4.3.4" />
8787
<PackageVersion Include="Testcontainers.MsSql" Version="3.3.0" />

NuGet.config

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<configuration>
33
<packageSources>
44
<clear />
55
<add key="NuGet" value="https://api.nuget.org/v3/index.json" />
6-
<!--
7-
<add key="dotnet6" value="https://dnceng.pkgs.visualstudio.com/public/_packaging/dotnet6/nuget/v3/index.json" />
8-
-->
6+
<add key="dotnet8" value="https://dnceng.pkgs.visualstudio.com/public/_packaging/dotnet8/nuget/v3/index.json" />
97
<add key=".Net Core Tools" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-eng/nuget/v3/index.json" />
108
</packageSources>
119

@@ -16,8 +14,11 @@
1614
<packageSource key="NuGet">
1715
<package pattern="*" />
1816
</packageSource>
17+
<packageSource key="dotnet8">
18+
<package pattern="Microsoft.CodeAnalysis.PublicApiAnalyzers" />
19+
</packageSource>
1920
<packageSource key=".Net Core Tools">
20-
<package pattern="*.ApiCompat" />
21+
<package pattern="Microsoft.DotNet.ApiCompat" />
2122
</packageSource>
2223
</packageSourceMapping>
2324

build/Common.prod.props

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,17 @@
4646
<NoWarn>$(NoWarn),1573,1712</NoWarn>
4747
<PackageOutputPath Condition="$(Build_ArtifactStagingDirectory) != ''">$(Build_ArtifactStagingDirectory)</PackageOutputPath>
4848
<GenerateDocumentationFile>true</GenerateDocumentationFile>
49-
<!--<MinVerVerbosity>detailed</MinVerVerbosity>-->
5049
<ApiCompatExcludeAttributeList>$(RepoRoot)\build\GlobalAttrExclusions.txt</ApiCompatExcludeAttributeList>
5150
</PropertyGroup>
5251

5352
<Target Name="AssemblyVersionTarget" AfterTargets="MinVer" Condition="'$(MinVerVersion)'!='' AND '$(BuildNumber)' != ''">
5453
<PropertyGroup>
5554
<FileVersion>$(MinVerMajor).$(MinVerMinor).$(MinVerPatch).$(BuildNumber)</FileVersion>
55+
<ExposeExperimentalFeatures Condition="'$(MinVerPreRelease)' != ''">true</ExposeExperimentalFeatures>
56+
<ExposeExperimentalFeatures Condition="'$(MinVerPreRelease)' == ''">false</ExposeExperimentalFeatures>
5657
</PropertyGroup>
58+
59+
<Message Importance="high" Text="**AssemblyVersionDebug** TargetFramework: $(TargetFramework), MinVerVersion: $(MinVerVersion), MinVerMajor: $(MinVerMajor), MinVerMinor: $(MinVerMinor), MinVerPatch: $(MinVerPatch), MinVerPreRelease: $(MinVerPreRelease), BuildNumber: $(BuildNumber), FileVersion: $(FileVersion), ExposeExperimentalFeatures: $(ExposeExperimentalFeatures)" />
5760
</Target>
5861

5962
<PropertyGroup>
@@ -89,10 +92,10 @@
8992

9093
<!--PublicApi Analyzer-->
9194
<ItemGroup>
92-
<AdditionalFiles Include=".publicApi\$(TargetFramework)\PublicAPI.Shipped.txt" />
93-
<AdditionalFiles Include=".publicApi\$(TargetFramework)\PublicAPI.Unshipped.txt" />
94-
<None Include=".publicApi\*\PublicAPI.Shipped.txt" />
95-
<None Include=".publicApi\*\PublicAPI.Unshipped.txt" />
95+
<AdditionalFiles Include=".publicApi\Stable\$(TargetFramework)\PublicAPI.*.txt" />
96+
<AdditionalFiles Include=".publicApi\Experimental\$(TargetFramework)\PublicAPI.*.txt" Condition="'$(ExposeExperimentalFeatures)' == 'true'" />
97+
<AdditionalFiles Include=".publicApi\$(TargetFramework)\PublicAPI.*.txt" />
98+
<None Include=".publicApi\**\PublicAPI.*.txt" />
9699
</ItemGroup>
97100

98101
</Project>

build/Common.props

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project>
22
<PropertyGroup>
3-
<LangVersion>10.0</LangVersion>
3+
<LangVersion>latest</LangVersion>
44
<SignAssembly>true</SignAssembly>
55
<RepoRoot>$([System.IO.Directory]::GetParent($(MSBuildThisFileDirectory)).Parent.FullName)</RepoRoot>
66
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)debug.snk</AssemblyOriginatorKeyFile>
@@ -11,6 +11,11 @@
1111
<ImplicitUsings>enable</ImplicitUsings>
1212
<!--temporarily disable. See 3958-->
1313
<!--<AnalysisLevel>latest-All</AnalysisLevel>-->
14+
<ExposeExperimentalFeatures Condition="'$(ExposeExperimentalFeatures)' == ''">true</ExposeExperimentalFeatures>
15+
</PropertyGroup>
16+
17+
<PropertyGroup Condition="'$(ExposeExperimentalFeatures)' == 'true'">
18+
<DefineConstants>$(DefineConstants);EXPOSE_EXPERIMENTAL_FEATURES</DefineConstants>
1419
</PropertyGroup>
1520

1621
<PropertyGroup Condition="'$(Configuration)'=='Debug'">

build/test-aot-compatibility.ps1

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,40 @@
1-
param([string]$targetNetFramework)
2-
3-
$rootDirectory = Split-Path $PSScriptRoot -Parent
4-
$publishOutput = dotnet publish $rootDirectory/test/OpenTelemetry.AotCompatibility.TestApp/OpenTelemetry.AotCompatibility.TestApp.csproj -nodeReuse:false /p:UseSharedCompilation=false
5-
6-
$actualWarningCount = 0
7-
8-
foreach ($line in $($publishOutput -split "`r`n"))
9-
{
10-
if ($line -like "*analysis warning IL*")
11-
{
12-
Write-Host $line
13-
$actualWarningCount += 1
14-
}
15-
}
16-
17-
pushd $rootDirectory/test/OpenTelemetry.AotCompatibility.TestApp/bin/Debug/$targetNetFramework/linux-x64
18-
19-
Write-Host "Executing test App..."
20-
./OpenTelemetry.AotCompatibility.TestApp
21-
Write-Host "Finished executing test App"
22-
23-
if ($LastExitCode -ne 0)
24-
{
25-
Write-Host "There was an error while executing AotCompatibility Test App. LastExitCode is:", $LastExitCode
26-
}
27-
28-
popd
29-
30-
Write-Host "Actual warning count is:", $actualWarningCount
31-
$expectedWarningCount = 28
32-
33-
$testPassed = 0
34-
if ($actualWarningCount -ne $expectedWarningCount)
35-
{
36-
$testPassed = 1
37-
Write-Host "Actual warning count:", actualWarningCount, "is not as expected. Expected warning count is:", $expectedWarningCount
38-
}
39-
40-
Exit $testPassed
1+
param([string]$targetNetFramework)
2+
3+
$rootDirectory = Split-Path $PSScriptRoot -Parent
4+
$publishOutput = dotnet publish $rootDirectory/test/OpenTelemetry.AotCompatibility.TestApp/OpenTelemetry.AotCompatibility.TestApp.csproj -nodeReuse:false /p:UseSharedCompilation=false /p:ExposeExperimentalFeatures=true
5+
6+
$actualWarningCount = 0
7+
8+
foreach ($line in $($publishOutput -split "`r`n"))
9+
{
10+
if ($line -like "*analysis warning IL*")
11+
{
12+
Write-Host $line
13+
$actualWarningCount += 1
14+
}
15+
}
16+
17+
pushd $rootDirectory/test/OpenTelemetry.AotCompatibility.TestApp/bin/Debug/$targetNetFramework/linux-x64
18+
19+
Write-Host "Executing test App..."
20+
./OpenTelemetry.AotCompatibility.TestApp
21+
Write-Host "Finished executing test App"
22+
23+
if ($LastExitCode -ne 0)
24+
{
25+
Write-Host "There was an error while executing AotCompatibility Test App. LastExitCode is:", $LastExitCode
26+
}
27+
28+
popd
29+
30+
Write-Host "Actual warning count is:", $actualWarningCount
31+
$expectedWarningCount = 28
32+
33+
$testPassed = 0
34+
if ($actualWarningCount -ne $expectedWarningCount)
35+
{
36+
$testPassed = 1
37+
Write-Host "Actual warning count:", actualWarningCount, "is not as expected. Expected warning count is:", $expectedWarningCount
38+
}
39+
40+
Exit $testPassed

examples/AspNetCore/Program.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@
110110
// Ensure the MeterProvider subscribes to any custom Meters.
111111
builder
112112
.AddMeter(Instrumentation.MeterName)
113+
#if EXPOSE_EXPERIMENTAL_FEATURES
113114
.SetExemplarFilter(new TraceBasedExemplarFilter())
115+
#endif
114116
.AddRuntimeInstrumentation()
115117
.AddHttpClientInstrumentation()
116118
.AddAspNetCoreInstrumentation();

0 commit comments

Comments
 (0)