Skip to content

Commit a150e7f

Browse files
authored
Merge pull request #206 from EFNext/fix/issue-205
Pack analyzer per roslyn version
2 parents fba76e1 + 8d2cd89 commit a150e7f

3 files changed

Lines changed: 60 additions & 8 deletions

File tree

src/EntityFrameworkCore.Projectables.Abstractions/EntityFrameworkCore.Projectables.Abstractions.csproj

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,50 @@
1818
</ProjectReference>
1919
</ItemGroup>
2020

21+
<PropertyGroup>
22+
<_AnalyzerVariantsDir>..\..\artifacts\analyzer-variants</_AnalyzerVariantsDir>
23+
</PropertyGroup>
24+
25+
<ItemGroup>
26+
<_RoslynVariant Include="4.8.0">
27+
<Folder>roslyn4.8</Folder>
28+
</_RoslynVariant>
29+
<_RoslynVariant Include="5.0.0">
30+
<Folder>roslyn5.0</Folder>
31+
</_RoslynVariant>
32+
</ItemGroup>
33+
34+
<Target Name="_BuildAnalyzerVariants" BeforeTargets="GenerateNuspec" Condition="'$(NoBuild)' != 'true'">
35+
<MSBuild
36+
Projects="..\EntityFrameworkCore.Projectables.Generator\EntityFrameworkCore.Projectables.Generator.csproj"
37+
Targets="Restore;Build"
38+
Properties="Configuration=$(Configuration);RoslynAnalyzerVersion=%(_RoslynVariant.Identity);BaseOutputPath=$(_AnalyzerVariantsDir)\Generator-%(_RoslynVariant.Folder)\bin\;BaseIntermediateOutputPath=$(_AnalyzerVariantsDir)\Generator-%(_RoslynVariant.Folder)\obj\"
39+
RemoveProperties="TargetFramework" />
40+
<MSBuild
41+
Projects="..\EntityFrameworkCore.Projectables.CodeFixes\EntityFrameworkCore.Projectables.CodeFixes.csproj"
42+
Targets="Restore;Build"
43+
Properties="Configuration=$(Configuration);RoslynAnalyzerVersion=%(_RoslynVariant.Identity);BaseOutputPath=$(_AnalyzerVariantsDir)\CodeFixes-%(_RoslynVariant.Folder)\bin\;BaseIntermediateOutputPath=$(_AnalyzerVariantsDir)\CodeFixes-%(_RoslynVariant.Folder)\obj\"
44+
RemoveProperties="TargetFramework" />
45+
</Target>
46+
47+
<Target Name="_CheckAnalyzerVariants" BeforeTargets="GenerateNuspec" Condition="'$(NoBuild)' == 'true'">
48+
<Error Condition="!Exists('$(_AnalyzerVariantsDir)\Generator-roslyn4.8\bin\$(Configuration)\netstandard2.0\EntityFrameworkCore.Projectables.Generator.dll') OR !Exists('$(_AnalyzerVariantsDir)\Generator-roslyn5.0\bin\$(Configuration)\netstandard2.0\EntityFrameworkCore.Projectables.Generator.dll')"
49+
Text="Roslyn-variant analyzer DLLs are missing under '$(_AnalyzerVariantsDir)'. Run 'dotnet pack' without --no-build to produce them." />
50+
</Target>
51+
52+
<Target Name="_CleanAnalyzerVariants" AfterTargets="Clean">
53+
<RemoveDir Directories="$(_AnalyzerVariantsDir)\Generator-%(_RoslynVariant.Folder);$(_AnalyzerVariantsDir)\CodeFixes-%(_RoslynVariant.Folder)" />
54+
</Target>
55+
2156
<ItemGroup>
22-
<!-- Package the generator and the code fix provider in the analyzer directory of the nuget package -->
23-
<None Include="..\EntityFrameworkCore.Projectables.Generator\bin\$(Configuration)\netstandard2.0\EntityFrameworkCore.Projectables.Generator.dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
24-
<None Include="..\EntityFrameworkCore.Projectables.CodeFixes\bin\$(Configuration)\netstandard2.0\EntityFrameworkCore.Projectables.CodeFixes.dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
57+
<None Include="$(_AnalyzerVariantsDir)\Generator-roslyn4.8\bin\$(Configuration)\netstandard2.0\EntityFrameworkCore.Projectables.Generator.dll"
58+
Pack="true" PackagePath="analyzers/dotnet/roslyn4.8/cs" Visible="false" />
59+
<None Include="$(_AnalyzerVariantsDir)\CodeFixes-roslyn4.8\bin\$(Configuration)\netstandard2.0\EntityFrameworkCore.Projectables.CodeFixes.dll"
60+
Pack="true" PackagePath="analyzers/dotnet/roslyn4.8/cs" Visible="false" />
61+
<None Include="$(_AnalyzerVariantsDir)\Generator-roslyn5.0\bin\$(Configuration)\netstandard2.0\EntityFrameworkCore.Projectables.Generator.dll"
62+
Pack="true" PackagePath="analyzers/dotnet/roslyn5.0/cs" Visible="false" />
63+
<None Include="$(_AnalyzerVariantsDir)\CodeFixes-roslyn5.0\bin\$(Configuration)\netstandard2.0\EntityFrameworkCore.Projectables.CodeFixes.dll"
64+
Pack="true" PackagePath="analyzers/dotnet/roslyn5.0/cs" Visible="false" />
2565
</ItemGroup>
2666

2767
<ItemGroup>

src/EntityFrameworkCore.Projectables.CodeFixes/EntityFrameworkCore.Projectables.CodeFixes.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
<NoWarn>$(NoWarn);NU5128</NoWarn>
77
<IsPackable>false</IsPackable>
88
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
9+
<!-- See Generator.csproj for rationale. Excludes the canonical bin/obj from the
10+
auto-Compile glob so the Roslyn-variant build doesn't pick up AssemblyInfo
11+
duplicates from the cascaded ProjectReference build. -->
12+
<DefaultItemExcludes>$(DefaultItemExcludes);bin\**;obj\**</DefaultItemExcludes>
913
</PropertyGroup>
1014

1115
<ItemGroup>

src/EntityFrameworkCore.Projectables.Generator/EntityFrameworkCore.Projectables.Generator.csproj

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,21 @@
66
<NoWarn>$(NoWarn);NU5128</NoWarn>
77
<IsPackable>false</IsPackable>
88
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
9+
<!-- Exclude bin/ and obj/ from auto-Compile glob unconditionally. For canonical builds
10+
this duplicates the SDK's existing exclusion (no-op). For Roslyn-variant builds
11+
(BaseOutputPath/BaseIntermediateOutputPath relocated outside the project), it
12+
prevents the canonical obj/ — populated by the cascaded ProjectReference build
13+
in the same pack invocation — from being picked up and CS0579-conflicting with
14+
the variant's own generated AssemblyInfo.cs. -->
15+
<DefaultItemExcludes>$(DefaultItemExcludes);bin\**;obj\**</DefaultItemExcludes>
916
</PropertyGroup>
1017

11-
<!-- Define ROSLYN_5_0_OR_LATER when building with .NET SDK 10+ (NETCoreSdkVersion is set by
12-
Microsoft.NET.Sdk.props, which runs before this project file body is evaluated).
13-
This enables C# 14 extension-type support in the generator code.
14-
On SDK 9 the constant is absent and extension block members are skipped safely. -->
15-
<PropertyGroup Condition="'$(NETCoreSdkVersion)' != '' AND $([MSBuild]::VersionGreaterThanOrEquals('$(NETCoreSdkVersion)', '10.0.0'))">
18+
<!-- Define ROSLYN_5_0_OR_LATER when compiling against Roslyn 5.0+ reference assemblies.
19+
Keyed off $(RoslynAnalyzerVersion) (auto-detected in Directory.Build.props, or
20+
overridden by the dual-build target in EntityFrameworkCore.Projectables.Abstractions.csproj)
21+
so a recursive build with RoslynAnalyzerVersion=4.8.0 produces a Roslyn-4.8-compatible
22+
DLL even on a host running .NET SDK 10. -->
23+
<PropertyGroup Condition="'$(RoslynAnalyzerVersion)' != '' AND $([MSBuild]::VersionGreaterThanOrEquals('$(RoslynAnalyzerVersion)', '5.0.0'))">
1624
<DefineConstants>$(DefineConstants);ROSLYN_5_0_OR_LATER</DefineConstants>
1725
</PropertyGroup>
1826

0 commit comments

Comments
 (0)