Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix logging source-gens duplication on WPF #5024

Merged
merged 10 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
</Target>

<!-- This target will make sure that projects targeting net462 will also have the Microsoft.Extensions.Logging.Abstractions analyzer removed. -->
<Target Name="_Microsoft_Extensions_Logging_AbstractionsRemoveAnalyzers"
<Target Name="_Microsoft_Extensions_Logging_AbstractionsRemoveAnalyzers"
Condition="'$(DisableMicrosoftExtensionsLoggingSourceGenerator)' == 'true'"
AfterTargets="ResolveReferences">
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

<PropertyGroup>
<InjectSharedPools>true</InjectSharedPools>
<SkipSharedPoolsReferences>true</SkipSharedPoolsReferences>
RussKie marked this conversation as resolved.
Show resolved Hide resolved
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion eng/MSBuild/Shared.props
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

<ItemGroup Condition="'$(InjectSharedPools)' == 'true'">
<Compile Include="$(MSBuildThisFileDirectory)\..\..\src\Shared\Pools\*.cs" LinkBase="Shared\Pools" />
<PackageReference Include="Microsoft.Extensions.ObjectPool" />
<PackageReference Condition="'$(SkipSharedPoolsReferences)' != 'true'" Include="Microsoft.Extensions.ObjectPool" />
</ItemGroup>

<ItemGroup Condition="'$(InjectSharedBufferWriterPool)' == 'true'">
Expand Down
4 changes: 2 additions & 2 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"sdk": {
"version": "8.0.200"
"version": "8.0.300"
},
"tools": {
"dotnet": "8.0.200",
"dotnet": "8.0.300",
"runtimes": {
"dotnet/x64": [
"6.0.22"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,36 @@
<Project>
<!-- This package should replace the Microsoft.Extensions.Logging.Abstractions source generator. -->
<Target Name="_Microsoft_Extensions_Logging_AbstractionsRemoveAnalyzers"
<!-- This package should replace the "Microsoft.Extensions.Logging.Abstractions" source generator. -->
<Target Name="_Microsoft_Extensions_Logging_AbstractionsRemoveAnalyzers"
Condition="'$(DisableMicrosoftExtensionsLoggingSourceGenerator)' == 'true'"
AfterTargets="ResolveReferences">
<ItemGroup>
<_Microsoft_Extensions_Logging_AbstractionsAnalyzer Include="@(Analyzer)" Condition="'%(Analyzer.AssemblyName)' == 'Microsoft.Extensions.Logging.Generators' Or
'%(Analyzer.NuGetPackageId)' == 'Microsoft.Extensions.Logging.Abstractions'" />
<_Microsoft_Extensions_Logging_AbstractionsAnalyzer
Include="@(Analyzer)"
Condition="'%(Analyzer.AssemblyName)' == 'Microsoft.Extensions.Logging.Generators' Or
'%(Analyzer.NuGetPackageId)' == 'Microsoft.Extensions.Logging.Abstractions'" />
</ItemGroup>

<!-- Remove Microsoft.Extensions.Logging.Abstractions Analyzer -->
<ItemGroup>
<Analyzer Remove="@(_Microsoft_Extensions_Logging_AbstractionsAnalyzer)" />
</ItemGroup>
</Target>

<!-- We have a WPF-specific target because WPF projects generate and compile a temporary project (via "GenerateTemporaryTargetAssembly" target),
and that temp project doesn't have "ResolveReferences" target we expect.
This leads to the runtime's generator not being removed and to a compile-time error CS0757. This additional target resolves the problem. -->
<Target Name="_Microsoft_Extensions_Logging_AbstractionsRemoveAnalyzersWPF"
xakep139 marked this conversation as resolved.
Show resolved Hide resolved
Condition="'$(DisableMicrosoftExtensionsLoggingSourceGenerator)' == 'true'"
AfterTargets="RemoveDuplicateAnalyzers">
<ItemGroup>
<_Microsoft_Extensions_Logging_AbstractionsAnalyzerWPF
Include="@(Analyzer)"
Condition="'%(Analyzer.AssemblyName)' == 'Microsoft.Extensions.Logging.Generators' Or
'%(Analyzer.NuGetPackageId)' == 'Microsoft.Extensions.Logging.Abstractions'" />
</ItemGroup>
<!-- Remove Microsoft.Extensions.Logging.Abstractions Analyzer for WPF projects -->
<ItemGroup>
<Analyzer Remove="@(_Microsoft_Extensions_Logging_AbstractionsAnalyzerWPF)" />
</ItemGroup>
</Target>
</Project>