Skip to content

Commit cf9049b

Browse files
Copilotatifaziz
andauthored
Add multi-Roslyn configuration support (#213)
--------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Atif Aziz <code@raboof.com>
1 parent 796fe42 commit cf9049b

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ jobs:
5050
- name: Build
5151
run: dotnet build --configuration ${{ env.CONFIGURATION }}
5252

53+
- name: Build Roslyn 4.4 variant
54+
run: dotnet build src/DocoptNet/DocoptNet.csproj -f netstandard2.0 -p:RoslynVersion=4.4 --configuration ${{ env.CONFIGURATION }}
55+
5356
- name: Pack (Windows only)
5457
if: runner.os == 'Windows'
5558
shell: pwsh

src/DocoptNet/DocoptNet.csproj

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

3+
<PropertyGroup>
4+
<_Roslyn44AnalyzerDir>$(MSBuildProjectDirectory)/bin/roslyn4.4/</_Roslyn44AnalyzerDir>
5+
</PropertyGroup>
6+
7+
<PropertyGroup Condition="'$(RoslynVersion)' == '4.4'">
8+
<BaseOutputPath>$(_Roslyn44AnalyzerDir)</BaseOutputPath>
9+
<BaseIntermediateOutputPath>$(MSBuildProjectDirectory)/obj/roslyn4.4/</BaseIntermediateOutputPath>
10+
<DefaultItemExcludes>$(DefaultItemExcludes);$(MSBuildProjectDirectory)/obj/**</DefaultItemExcludes>
11+
<DefineConstants>$(DefineConstants);ROSLYN4_4</DefineConstants>
12+
</PropertyGroup>
13+
314
<PropertyGroup>
415
<TargetFrameworks>netstandard2.1;netstandard2.0;net47</TargetFrameworks>
516
<DefineConstants>$(DefineConstants);DOCOPTNET_PUBLIC</DefineConstants>
@@ -49,14 +60,26 @@ Portions Copyright (C) West Wind Technologies, 2008.
4960
<None Include="CodeGeneration\*.cs" />
5061
</ItemGroup>
5162

52-
<ItemGroup Condition="'$(TargetFramework)' != 'net47'">
63+
<ItemGroup Condition="'$(TargetFramework)' != 'net47' And '$(RoslynVersion)' != '4.4'">
5364
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.10.0" PrivateAssets="all" />
65+
</ItemGroup>
66+
67+
<ItemGroup Condition="'$(TargetFramework)' != 'net47' And '$(RoslynVersion)' == '4.4'">
68+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.4.0" PrivateAssets="all" />
69+
</ItemGroup>
70+
71+
<ItemGroup Condition="'$(TargetFramework)' != 'net47'">
5472
<AdditionalFiles Include="CodeGeneration\AnalyzerReleases.*.md" />
5573
</ItemGroup>
5674

5775
<ItemGroup>
58-
<!-- Package the generator in the analyzer directory of the nuget package -->
59-
<None Include="$(OutputPath)\netstandard2.0\$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
76+
<!-- Package the generator in the analyzer directory of the nuget package.
77+
Using a versioned roslyn3.10/ folder instead of the unversioned cs/ path ensures the SDK
78+
selects only the best-matching Roslyn variant (3.10 baseline or 4.4) rather than loading both.
79+
See: https://github.com/dotnet/sdk/issues/20355 -->
80+
<None Include="$(OutputPath)\netstandard2.0\$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/roslyn3.10/cs" Visible="false" />
81+
<!-- Package the Roslyn 4.4 variant of the generator -->
82+
<None Include="$(_Roslyn44AnalyzerDir)$(Configuration)/netstandard2.0/$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/roslyn4.4/cs" Visible="false" />
6083
<!--
6184
Using a "PackagePath" of "build/$(TargetFramework)/%(Filename)%(Extension)" causes the
6285
following error:
@@ -96,4 +119,12 @@ Portions Copyright (C) West Wind Technologies, 2008.
96119
<AdditionalFiles Include="PublicAPI/$(TargetFramework)/PublicAPI.Unshipped.txt" />
97120
</ItemGroup>
98121

122+
<Target Name="_ValidateRoslyn44AnalyzerOutput" BeforeTargets="GenerateNuspec">
123+
<PropertyGroup>
124+
<_Roslyn44AnalyzerPath>$(_Roslyn44AnalyzerDir)$(Configuration)/netstandard2.0/$(AssemblyName).dll</_Roslyn44AnalyzerPath>
125+
</PropertyGroup>
126+
<Error Condition="!Exists('$(_Roslyn44AnalyzerPath)')"
127+
Text="Roslyn 4.4 analyzer output not found at '$(_Roslyn44AnalyzerPath)'. Build all Roslyn variants first by running: ./build.ps1 -Pack" />
128+
</Target>
129+
99130
</Project>

0 commit comments

Comments
 (0)