Skip to content

Commit 59ebcb9

Browse files
authored
Use ProjectReferences in source build (#79119)
Resolves #78643
2 parents e02d81a + 6490a54 commit 59ebcb9

File tree

19 files changed

+282
-85
lines changed

19 files changed

+282
-85
lines changed

src/RoslynAnalyzers/Directory.Build.props

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@
88

99
<!-- Set 'NoDefaultExcludes' to ensure that we can package .editorconfig files into our analyzer NuGet packages -->
1010
<NoDefaultExcludes>true</NoDefaultExcludes>
11-
11+
1212
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
13+
</PropertyGroup>
14+
15+
<PropertyGroup Condition="'$(DotNetBuildSourceOnly)' != 'true'">
1316
<DefineConstants>$(DefineConstants),ROSLYN_4_12_OR_LOWER</DefineConstants>
1417
</PropertyGroup>
1518

@@ -25,6 +28,12 @@
2528
<DefineConstants Condition="'$(LEGACY_CODE_METRICS_MODE)' == 'true'">$(DefineConstants),LEGACY_CODE_METRICS_MODE</DefineConstants>
2629
</PropertyGroup>
2730

31+
<PropertyGroup Condition="'$(DotNetBuildSourceOnly)' != 'true'">
32+
<!-- Since SourceBuild uses project references and brings additional nullability annotations, -->
33+
<!-- suppressions were added that are unncessary when building against older Roslyn packages. -->
34+
<NoWarn>$(NoWarn);IDE0079</NoWarn>
35+
</PropertyGroup>
36+
2837
<PropertyGroup Condition="'$(DotNetBuildSourceOnly)' == 'true'">
2938
<!-- When building in source build mode, treat this set of warnings not as errors.-->
3039
<!-- Some crefs reference internal APIs not present in the reference package. -->

src/RoslynAnalyzers/Microsoft.CodeAnalysis.AnalyzerUtilities/Microsoft.CodeAnalysis.AnalyzerUtilities.csproj

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,21 @@
1717
<NoWarn>$(NoWarn);RS0026</NoWarn>
1818
</PropertyGroup>
1919
<ItemGroup>
20-
<PackageReference Include="Microsoft.CodeAnalysis.Common" VersionOverride="$(MicrosoftCodeAnalysisVersionForAnalyzers)" />
2120
<PackageReference Include="System.Threading.Channels" />
2221
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" />
2322
</ItemGroup>
23+
<Choose>
24+
<When Condition="'$(DotNetBuildSourceOnly)' != 'true'">
25+
<ItemGroup>
26+
<PackageReference Include="Microsoft.CodeAnalysis.Common" VersionOverride="$(MicrosoftCodeAnalysisVersionForAnalyzers)" />
27+
</ItemGroup>
28+
</When>
29+
<Otherwise>
30+
<ItemGroup>
31+
<ProjectReference Include="..\..\Compilers\Core\Portable\Microsoft.CodeAnalysis.csproj" />
32+
</ItemGroup>
33+
</Otherwise>
34+
</Choose>
2435
<ItemGroup>
2536
<InternalsVisibleTo Include="Analyzer.Utilities.UnitTests" />
2637
</ItemGroup>
@@ -35,7 +46,7 @@
3546
<Import Project="..\..\Dependencies\PooledObjects\Microsoft.CodeAnalysis.PooledObjects.projitems" Label="Shared" />
3647
<Import Project="..\..\Dependencies\Threading\Microsoft.CodeAnalysis.Threading.projitems" Label="Shared" />
3748
<Import Project="..\..\Dependencies\Contracts\Microsoft.CodeAnalysis.Contracts.projitems" Label="Shared" />
38-
49+
3950
<Import Project="..\..\Workspaces\SharedUtilitiesAndExtensions\Compiler\Extensions\Microsoft.CodeAnalysis.Extensions.projitems" Label="Shared"/>
4051
<Import Project="..\..\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\CompilerExtensions.projitems" Label="Shared" />
4152
</Project>

src/RoslynAnalyzers/Microsoft.CodeAnalysis.Analyzers/CSharp/Microsoft.CodeAnalysis.CSharp.Analyzers.csproj

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,22 @@
99
<ItemGroup>
1010
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.Analyzers.UnitTests" />
1111
</ItemGroup>
12-
<ItemGroup>
13-
<PackageReference Include="Microsoft.CodeAnalysis.Common" VersionOverride="$(MicrosoftCodeAnalysisVersionForAnalyzers)" />
14-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" VersionOverride="$(MicrosoftCodeAnalysisVersionForAnalyzers)" />
15-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" VersionOverride="$(MicrosoftCodeAnalysisVersionForAnalyzers)" />
16-
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.Common" VersionOverride="$(MicrosoftCodeAnalysisVersionForAnalyzers)" />
17-
</ItemGroup>
12+
<Choose>
13+
<When Condition="'$(DotNetBuildSourceOnly)' != 'true'">
14+
<ItemGroup>
15+
<PackageReference Include="Microsoft.CodeAnalysis.Common" VersionOverride="$(MicrosoftCodeAnalysisVersionForAnalyzers)" />
16+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" VersionOverride="$(MicrosoftCodeAnalysisVersionForAnalyzers)" />
17+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" VersionOverride="$(MicrosoftCodeAnalysisVersionForAnalyzers)" />
18+
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.Common" VersionOverride="$(MicrosoftCodeAnalysisVersionForAnalyzers)" />
19+
</ItemGroup>
20+
</When>
21+
<Otherwise>
22+
<ItemGroup>
23+
<ProjectReference Include="..\..\..\Compilers\Core\Portable\Microsoft.CodeAnalysis.csproj" />
24+
<ProjectReference Include="..\..\..\Compilers\CSharp\Portable\Microsoft.CodeAnalysis.CSharp.csproj" />
25+
<ProjectReference Include="..\..\..\Workspaces\Core\Portable\Microsoft.CodeAnalysis.Workspaces.csproj" />
26+
<ProjectReference Include="..\..\..\Workspaces\CSharp\Portable\Microsoft.CodeAnalysis.CSharp.Workspaces.csproj" />
27+
</ItemGroup>
28+
</Otherwise>
29+
</Choose>
1830
</Project>

src/RoslynAnalyzers/Microsoft.CodeAnalysis.Analyzers/Core/Microsoft.CodeAnalysis.Analyzers.csproj

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,20 @@
1010
<PackageId>*$(MSBuildProjectFile)*</PackageId>
1111
<RootNamespace>Microsoft.CodeAnalysis</RootNamespace>
1212
</PropertyGroup>
13-
<ItemGroup>
14-
<PackageReference Include="Microsoft.CodeAnalysis.Common" VersionOverride="$(MicrosoftCodeAnalysisVersionForAnalyzers)" />
15-
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.Common" VersionOverride="$(MicrosoftCodeAnalysisVersionForAnalyzers)" />
16-
</ItemGroup>
13+
<Choose>
14+
<When Condition="'$(DotNetBuildSourceOnly)' != 'true'">
15+
<ItemGroup>
16+
<PackageReference Include="Microsoft.CodeAnalysis.Common" VersionOverride="$(MicrosoftCodeAnalysisVersionForAnalyzers)" />
17+
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.Common" VersionOverride="$(MicrosoftCodeAnalysisVersionForAnalyzers)" />
18+
</ItemGroup>
19+
</When>
20+
<Otherwise>
21+
<ItemGroup>
22+
<ProjectReference Include="..\..\..\Compilers\Core\Portable\Microsoft.CodeAnalysis.csproj" />
23+
<ProjectReference Include="..\..\..\Workspaces\Core\Portable\Microsoft.CodeAnalysis.Workspaces.csproj" />
24+
</ItemGroup>
25+
</Otherwise>
26+
</Choose>
1727
<ItemGroup>
1828
<Compile Include="..\..\Microsoft.CodeAnalysis.BannedApiAnalyzers\Core\DocumentationCommentIdParser.cs" Link="DocumentationCommentIdParser.cs" />
1929
<Compile Include="..\..\Microsoft.CodeAnalysis.BannedApiAnalyzers\Core\SymbolIsBannedAnalyzerBase.cs" Link="SymbolIsBannedAnalyzerBase.cs" />

src/RoslynAnalyzers/Microsoft.CodeAnalysis.Analyzers/UnitTests/Microsoft.CodeAnalysis.Analyzers.UnitTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<PropertyGroup>
44
<TargetFramework>$(NetRoslyn)</TargetFramework>
55
<ServerGarbageCollection>true</ServerGarbageCollection>
6+
<ExcludeFromSourceOnlyBuild>true</ExcludeFromSourceOnlyBuild>
67
</PropertyGroup>
78
<ItemGroup>
89
<PackageReference Include="Microsoft.CodeAnalysis.Common" VersionOverride="$(MicrosoftCodeAnalysisVersionForAnalyzerTests)" />

src/RoslynAnalyzers/Microsoft.CodeAnalysis.Analyzers/VisualBasic/Microsoft.CodeAnalysis.VisualBasic.Analyzers.vbproj

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,22 @@
1010
<ItemGroup>
1111
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.Analyzers.UnitTests" />
1212
</ItemGroup>
13-
<ItemGroup>
14-
<PackageReference Include="Microsoft.CodeAnalysis.Common" VersionOverride="$(MicrosoftCodeAnalysisVersionForAnalyzers)" />
15-
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic" VersionOverride="$(MicrosoftCodeAnalysisVersionForAnalyzers)" />
16-
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic.Workspaces" VersionOverride="$(MicrosoftCodeAnalysisVersionForAnalyzers)" />
17-
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.Common" VersionOverride="$(MicrosoftCodeAnalysisVersionForAnalyzers)" />
18-
</ItemGroup>
13+
<Choose>
14+
<When Condition="'$(DotNetBuildSourceOnly)' != 'true'">
15+
<ItemGroup>
16+
<PackageReference Include="Microsoft.CodeAnalysis.Common" VersionOverride="$(MicrosoftCodeAnalysisVersionForAnalyzers)" />
17+
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic" VersionOverride="$(MicrosoftCodeAnalysisVersionForAnalyzers)" />
18+
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic.Workspaces" VersionOverride="$(MicrosoftCodeAnalysisVersionForAnalyzers)" />
19+
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.Common" VersionOverride="$(MicrosoftCodeAnalysisVersionForAnalyzers)" />
20+
</ItemGroup>
21+
</When>
22+
<Otherwise>
23+
<ItemGroup>
24+
<ProjectReference Include="..\..\..\Compilers\Core\Portable\Microsoft.CodeAnalysis.csproj" />
25+
<ProjectReference Include="..\..\..\Compilers\VisualBasic\Portable\Microsoft.CodeAnalysis.VisualBasic.vbproj" />
26+
<ProjectReference Include="..\..\..\Workspaces\Core\Portable\Microsoft.CodeAnalysis.Workspaces.csproj" />
27+
<ProjectReference Include="..\..\..\Workspaces\VisualBasic\Portable\Microsoft.CodeAnalysis.VisualBasic.Workspaces.vbproj" />
28+
</ItemGroup>
29+
</Otherwise>
30+
</Choose>
1931
</Project>

src/RoslynAnalyzers/Microsoft.CodeAnalysis.ResxSourceGenerator/Microsoft.CodeAnalysis.ResxSourceGenerator.CSharp/Microsoft.CodeAnalysis.ResxSourceGenerator.CSharp.csproj

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,20 @@
99
<PackageId>*$(MSBuildProjectFile)*</PackageId>
1010
</PropertyGroup>
1111

12-
<ItemGroup>
13-
<PackageReference Include="Microsoft.CodeAnalysis.Common" VersionOverride="$(MicrosoftCodeAnalysisVersionForAnalyzers)" />
14-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" VersionOverride="$(MicrosoftCodeAnalysisVersionForAnalyzers)" />
15-
</ItemGroup>
12+
<Choose>
13+
<When Condition="'$(DotNetBuildSourceOnly)' != 'true'">
14+
<ItemGroup>
15+
<PackageReference Include="Microsoft.CodeAnalysis.Common" VersionOverride="$(MicrosoftCodeAnalysisVersionForAnalyzers)" />
16+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" VersionOverride="$(MicrosoftCodeAnalysisVersionForAnalyzers)" />
17+
</ItemGroup>
18+
</When>
19+
<Otherwise>
20+
<ItemGroup>
21+
<ProjectReference Include="..\..\..\Compilers\Core\Portable\Microsoft.CodeAnalysis.csproj" />
22+
<ProjectReference Include="..\..\..\Compilers\CSharp\Portable\Microsoft.CodeAnalysis.CSharp.csproj" />
23+
</ItemGroup>
24+
</Otherwise>
25+
</Choose>
1626

1727
<ItemGroup>
1828
<ProjectReference Include="..\Microsoft.CodeAnalysis.ResxSourceGenerator\Microsoft.CodeAnalysis.ResxSourceGenerator.csproj" />

src/RoslynAnalyzers/Microsoft.CodeAnalysis.ResxSourceGenerator/Microsoft.CodeAnalysis.ResxSourceGenerator.UnitTests/Microsoft.CodeAnalysis.ResxSourceGenerator.UnitTests.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
77
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
8+
<ExcludeFromSourceOnlyBuild>true</ExcludeFromSourceOnlyBuild>
89
</PropertyGroup>
910

1011
<ItemGroup>
@@ -14,7 +15,9 @@
1415
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic" VersionOverride="$(MicrosoftCodeAnalysisVersionForAnalyzerTests)" />
1516
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic.Workspaces" VersionOverride="$(MicrosoftCodeAnalysisVersionForAnalyzerTests)" />
1617
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.Common" VersionOverride="$(MicrosoftCodeAnalysisVersionForAnalyzerTests)" />
18+
</ItemGroup>
1719

20+
<ItemGroup>
1821
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Analyzer.Testing" VersionOverride="$(MicrosoftCodeAnalysisTestingVersion)" />
1922
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeFix.Testing" VersionOverride="$(MicrosoftCodeAnalysisTestingVersion)" />
2023
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeRefactoring.Testing" VersionOverride="$(MicrosoftCodeAnalysisTestingVersion)" />

src/RoslynAnalyzers/Microsoft.CodeAnalysis.ResxSourceGenerator/Microsoft.CodeAnalysis.ResxSourceGenerator.VisualBasic/Microsoft.CodeAnalysis.ResxSourceGenerator.VisualBasic.csproj

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,20 @@
99
<PackageId>*$(MSBuildProjectFile)*</PackageId>
1010
</PropertyGroup>
1111

12-
<ItemGroup>
13-
<PackageReference Include="Microsoft.CodeAnalysis.Common" VersionOverride="$(MicrosoftCodeAnalysisVersionForAnalyzers)" />
14-
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic" VersionOverride="$(MicrosoftCodeAnalysisVersionForAnalyzers)" />
15-
</ItemGroup>
12+
<Choose>
13+
<When Condition="'$(DotNetBuildSourceOnly)' != 'true'">
14+
<ItemGroup>
15+
<PackageReference Include="Microsoft.CodeAnalysis.Common" VersionOverride="$(MicrosoftCodeAnalysisVersionForAnalyzers)" />
16+
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic" VersionOverride="$(MicrosoftCodeAnalysisVersionForAnalyzers)" />
17+
</ItemGroup>
18+
</When>
19+
<Otherwise>
20+
<ItemGroup>
21+
<ProjectReference Include="..\..\..\Compilers\Core\Portable\Microsoft.CodeAnalysis.csproj" />
22+
<ProjectReference Include="..\..\..\Compilers\VisualBasic\Portable\Microsoft.CodeAnalysis.VisualBasic.vbproj" />
23+
</ItemGroup>
24+
</Otherwise>
25+
</Choose>
1626

1727
<ItemGroup>
1828
<ProjectReference Include="..\Microsoft.CodeAnalysis.ResxSourceGenerator\Microsoft.CodeAnalysis.ResxSourceGenerator.csproj" />

src/RoslynAnalyzers/Microsoft.CodeAnalysis.ResxSourceGenerator/Microsoft.CodeAnalysis.ResxSourceGenerator/Microsoft.CodeAnalysis.ResxSourceGenerator.csproj

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,29 @@
1717
</ItemGroup>
1818

1919
<ItemGroup>
20-
<PackageReference Include="Microsoft.CodeAnalysis.Common" VersionOverride="$(MicrosoftCodeAnalysisVersionForAnalyzers)" />
2120
<PackageReference Include="System.Threading.Channels" />
2221
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" />
2322
</ItemGroup>
23+
<Choose>
24+
<When Condition="'$(DotNetBuildSourceOnly)' != 'true'">
25+
<ItemGroup>
26+
<PackageReference Include="Microsoft.CodeAnalysis.Common" VersionOverride="$(MicrosoftCodeAnalysisVersionForAnalyzers)" />
27+
</ItemGroup>
28+
</When>
29+
<Otherwise>
30+
<ItemGroup>
31+
<ProjectReference Include="..\..\..\Compilers\Core\Portable\Microsoft.CodeAnalysis.csproj" />
32+
</ItemGroup>
33+
</Otherwise>
34+
</Choose>
2435

2536
<Import Project="..\..\Utilities\Compiler\Analyzer.Utilities.projitems" Label="Shared" />
2637

2738
<Import Project="..\..\..\Dependencies\Collections\Microsoft.CodeAnalysis.Collections.projitems" Label="Shared" />
2839
<Import Project="..\..\..\Dependencies\PooledObjects\Microsoft.CodeAnalysis.PooledObjects.projitems" Label="Shared" />
2940
<Import Project="..\..\..\Dependencies\Threading\Microsoft.CodeAnalysis.Threading.projitems" Label="Shared" />
3041
<Import Project="..\..\..\Dependencies\Contracts\Microsoft.CodeAnalysis.Contracts.projitems" Label="Shared" />
31-
42+
3243
<Import Project="..\..\..\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\CompilerExtensions.projitems" Label="Shared" />
3344
<Import Project="..\..\..\Workspaces\SharedUtilitiesAndExtensions\Compiler\Extensions\Microsoft.CodeAnalysis.Extensions.projitems" Label="Shared" />
3445
</Project>

0 commit comments

Comments
 (0)