Skip to content

Commit e591860

Browse files
committed
Add a check for unused package dependencies lingering in Directory.Packages.Props.
Clean unused `Restsharp` dependency.
1 parent 966bbb6 commit e591860

2 files changed

Lines changed: 150 additions & 92 deletions

File tree

Lines changed: 98 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,100 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
<PropertyGroup>
3-
<TargetFramework>net48</TargetFramework>
4-
<OutputType>Library</OutputType>
5-
</PropertyGroup>
6-
<PropertyGroup>
7-
<RunPostBuildEvent>Always</RunPostBuildEvent>
8-
</PropertyGroup>
9-
<PropertyGroup>
10-
<PostBuildEvent>:: Skip our post-build events when running continuous integration
11-
IF DEFINED CI (
12-
GOTO :EOF :: Set to TRUE in Github Actions
13-
)
14-
IF DEFINED APPVEYOR (
15-
GOTO :EOF :: Set to TRUE in Appveyor
16-
)
17-
18-
:: This is a local build rather than a continuous integration... we will proceed.
19-
20-
cd "$(SolutionDir)"
21-
if exist $(SolutionDir)postBuildTests.bat (
22-
@echo Post-build script exists at: $(SolutionDir)postBuildTests.bat - executing...
23-
call $(SolutionDir)postBuildTests.bat "$(Configuration)" "$(SolutionDir)" "bin\$(Configuration)\"
24-
)
25-
26-
if "$(Configuration)" == "Release" (
27-
build-installer
28-
)
29-
</PostBuildEvent>
30-
</PropertyGroup>
31-
<PropertyGroup>
32-
<PreBuildEvent>xcopy /y "$(SolutionDir)Lexicons.md" "$(SolutionDir)bin\$(Configuration)\Wiki\"
33-
xcopy /y "$(SolutionDir)Lexicons.md" "$(SolutionDir)bin\$(Configuration)\Wiki\"
34-
xcopy /y "$(SolutionDir)images\*.*" "$(SolutionDir)bin\$(Configuration)\Wiki\images\"</PreBuildEvent>
35-
</PropertyGroup>
36-
<ItemGroup>
37-
<PackageReference Include="Microsoft.CSharp" />
38-
<PackageReference Include="System.Runtime" />
39-
<PackageReference Include="System.Runtime.Extensions" />
40-
</ItemGroup>
2+
<PropertyGroup>
3+
<TargetFramework>net48</TargetFramework>
4+
<OutputType>Library</OutputType>
5+
</PropertyGroup>
6+
<PropertyGroup>
7+
<RunPostBuildEvent>Always</RunPostBuildEvent>
8+
</PropertyGroup>
9+
<PropertyGroup>
10+
<PostBuildEvent>
11+
:: Skip our post-build events when running continuous integration
12+
IF DEFINED CI (
13+
GOTO :EOF :: Set to TRUE in Github Actions
14+
)
15+
IF DEFINED APPVEYOR (
16+
GOTO :EOF :: Set to TRUE in Appveyor
17+
)
18+
19+
:: This is a local build rather than a continuous integration... we will proceed.
20+
21+
cd "$(SolutionDir)"
22+
if exist $(SolutionDir)postBuildTests.bat (
23+
@echo Post-build script exists at: $(SolutionDir)postBuildTests.bat - executing...
24+
call $(SolutionDir)postBuildTests.bat "$(Configuration)" "$(SolutionDir)" "bin\$(Configuration)\"
25+
)
26+
27+
if "$(Configuration)" == "Release" (
28+
build-installer
29+
)
30+
</PostBuildEvent>
31+
</PropertyGroup>
32+
<PropertyGroup>
33+
<PreBuildEvent>
34+
xcopy /y "$(SolutionDir)Lexicons.md" "$(SolutionDir)bin\$(Configuration)\Wiki\"
35+
xcopy /y "$(SolutionDir)Lexicons.md" "$(SolutionDir)bin\$(Configuration)\Wiki\"
36+
xcopy /y "$(SolutionDir)images\*.*" "$(SolutionDir)bin\$(Configuration)\Wiki\images\"
37+
</PreBuildEvent>
38+
</PropertyGroup>
39+
<ItemGroup>
40+
<PackageReference Include="Microsoft.CSharp" />
41+
<PackageReference Include="System.Runtime" />
42+
<PackageReference Include="System.Runtime.Extensions" />
43+
</ItemGroup>
44+
45+
<!--Check for unused dependencies in Directory.Packages.props-->
46+
<Target Name="CheckUnusedPackages" AfterTargets="Build">
47+
<Message Importance="High" Text=">>> Running solution-wide unused package check" />
48+
49+
<PropertyGroup>
50+
<PackagesProps>$(MSBuildThisFileDirectory)..\Directory.Packages.props</PackagesProps>
51+
</PropertyGroup>
52+
53+
<!-- Load declared packages -->
54+
<XmlPeek XmlInputPath="$(PackagesProps)"
55+
Query="//PackageVersion/@Include">
56+
<Output TaskParameter="Result" ItemName="DeclaredPackagesRaw"/>
57+
</XmlPeek>
58+
59+
<ItemGroup>
60+
<DeclaredPackages Include="@(DeclaredPackagesRaw->'%(Identity)')" />
61+
</ItemGroup>
62+
63+
<!-- Gather all project files in the solution -->
64+
<ItemGroup>
65+
<ProjectFiles Include="..\**\*.csproj" Exclude="$(MSBuildProjectFullPath)" />
66+
</ItemGroup>
67+
68+
<!-- Ask each project to report its PackageReferences -->
69+
<MSBuild Projects="@(ProjectFiles)"
70+
Targets="CollectPackageReferences"
71+
BuildInParallel="true"
72+
Properties="DesignTimeBuild=true">
73+
<Output TaskParameter="TargetOutputs" ItemName="UsedPackagesRaw"/>
74+
</MSBuild>
75+
76+
<ItemGroup>
77+
<UsedPackages Include="@(UsedPackagesRaw->'%(Identity)')" />
78+
</ItemGroup>
79+
80+
<!-- Compare sets -->
81+
<ItemGroup>
82+
<UnusedPackages Include="@(DeclaredPackages)"
83+
Exclude="@(UsedPackages)" />
84+
</ItemGroup>
85+
86+
<!-- Emit a single consolidated warning -->
87+
<Warning Text="Unused packages in Directory.Packages.props: @(UnusedPackages, ', ')"
88+
Condition=" '@(UnusedPackages)' != '' " />
89+
</Target>
90+
91+
<!-- Helper target: runs inside each project -->
92+
<Target Name="CollectPackageReferences" Returns="@(FilteredPackageRefs)">
93+
<ItemGroup>
94+
<FilteredPackageRefs Include="@(PackageReference->'%(Identity)')"
95+
Condition=" '%(PackageReference.PrivateAssets)' != 'all'
96+
and '%(PackageReference.IncludeAssets)' != 'analyzers' " />
97+
</ItemGroup>
98+
</Target>
99+
41100
</Project>

Directory.Packages.props

Lines changed: 52 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,54 @@
11
<Project>
2-
<PropertyGroup>
3-
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
4-
<CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
5-
<NoWarn>$(NoWarn);NU1507</NoWarn>
6-
</PropertyGroup>
7-
<ItemGroup>
8-
<PackageVersion Include="AvalonEdit" Version="6.3.1.120" />
9-
<PackageVersion Include="CommonMark.NET" Version="0.15.1" />
10-
<PackageVersion Include="Cottle" Version="2.1.0" />
11-
<PackageVersion Include="JetBrains.Annotations" Version="2025.2.0" />
12-
<PackageVersion Include="MathNet.Numerics" Version="5.0.0" />
13-
<PackageVersion Include="Microsoft.CSharp" Version="4.7.0" />
14-
<PackageVersion Include="Microsoft.NETCore.Platforms" Version="7.0.4" />
15-
<PackageVersion Include="Microsoft.Windows.SDK.Contracts" Version="10.0.26100.4188" />
16-
<PackageVersion Include="MSTest.TestAdapter" Version="3.8.3" />
17-
<PackageVersion Include="MSTest.TestFramework" Version="3.8.3" />
18-
<PackageVersion Include="NAudio" Version="2.2.1" />
19-
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
20-
<PackageVersion Include="NWaves" Version="0.9.6" />
21-
<PackageVersion Include="RestSharp" Version="106.13.0" />
22-
<PackageVersion Include="Rollbar" Version="5.2.2" />
23-
<PackageVersion Include="System.Collections" Version="4.3.0" />
24-
<PackageVersion Include="System.Collections.Concurrent" Version="4.3.0" />
25-
<PackageVersion Include="System.Collections.Immutable" Version="9.0.5" />
26-
<PackageVersion Include="System.Data.SQLite" Version="1.0.119" />
27-
<PackageVersion Include="System.Diagnostics.Debug" Version="4.3.0" />
28-
<PackageVersion Include="System.Diagnostics.Tools" Version="4.3.0" />
29-
<PackageVersion Include="System.Diagnostics.Tracing" Version="4.3.0" />
30-
<PackageVersion Include="System.Globalization" Version="4.3.0" />
31-
<PackageVersion Include="System.IO.Compression" Version="4.3.0" />
32-
<PackageVersion Include="System.Linq" Version="4.3.0" />
33-
<PackageVersion Include="System.Linq.Expressions" Version="4.3.0" />
34-
<PackageVersion Include="System.ObjectModel" Version="4.3.0" />
35-
<PackageVersion Include="System.Reflection" Version="4.3.0" />
36-
<PackageVersion Include="System.Reflection.Extensions" Version="4.3.0" />
37-
<PackageVersion Include="System.Reflection.Primitives" Version="4.3.0" />
38-
<PackageVersion Include="System.Resources.ResourceManager" Version="4.3.0" />
39-
<PackageVersion Include="System.Runtime" Version="4.3.1" />
40-
<PackageVersion Include="System.Runtime.Caching" Version="9.0.5" />
41-
<PackageVersion Include="System.Runtime.Extensions" Version="4.3.1" />
42-
<PackageVersion Include="System.Runtime.InteropServices" Version="4.3.0" />
43-
<PackageVersion Include="System.Runtime.InteropServices.RuntimeInformation" Version="4.3.0" />
44-
<PackageVersion Include="System.Runtime.Numerics" Version="4.3.0" />
45-
<PackageVersion Include="System.Security.Cryptography.Algorithms" Version="4.3.1" />
46-
<PackageVersion Include="System.Security.Cryptography.X509Certificates" Version="4.3.2" />
47-
<PackageVersion Include="System.Text.Encoding" Version="4.3.0" />
48-
<PackageVersion Include="System.Text.Encoding.Extensions" Version="4.3.0" />
49-
<PackageVersion Include="System.Threading" Version="4.3.0" />
50-
<PackageVersion Include="System.Threading.Tasks" Version="4.3.0" />
51-
<PackageVersion Include="System.Threading.Timer" Version="4.3.0" />
52-
<PackageVersion Include="System.Xml.ReaderWriter" Version="4.3.1" />
53-
<PackageVersion Include="System.Xml.XDocument" Version="4.3.0" />
54-
</ItemGroup>
2+
<PropertyGroup>
3+
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
4+
<CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
5+
<NoWarn>$(NoWarn);NU1507</NoWarn>
6+
</PropertyGroup>
7+
<ItemGroup>
8+
<PackageVersion Include="AvalonEdit" Version="6.3.1.120" />
9+
<PackageVersion Include="CommonMark.NET" Version="0.15.1" />
10+
<PackageVersion Include="Cottle" Version="2.1.0" />
11+
<PackageVersion Include="JetBrains.Annotations" Version="2025.2.0" />
12+
<PackageVersion Include="MathNet.Numerics" Version="5.0.0" />
13+
<PackageVersion Include="Microsoft.CSharp" Version="4.7.0" />
14+
<PackageVersion Include="Microsoft.NETCore.Platforms" Version="7.0.4" />
15+
<PackageVersion Include="Microsoft.Windows.SDK.Contracts" Version="10.0.26100.4188" />
16+
<PackageVersion Include="MSTest.TestAdapter" Version="3.8.3" />
17+
<PackageVersion Include="MSTest.TestFramework" Version="3.8.3" />
18+
<PackageVersion Include="NAudio" Version="2.2.1" />
19+
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
20+
<PackageVersion Include="NWaves" Version="0.9.6" />
21+
<PackageVersion Include="Rollbar" Version="5.2.2" />
22+
<PackageVersion Include="System.Collections" Version="4.3.0" />
23+
<PackageVersion Include="System.Collections.Concurrent" Version="4.3.0" />
24+
<PackageVersion Include="System.Collections.Immutable" Version="9.0.5" />
25+
<PackageVersion Include="System.Data.SQLite" Version="1.0.119" />
26+
<PackageVersion Include="System.Diagnostics.Debug" Version="4.3.0" />
27+
<PackageVersion Include="System.Diagnostics.Tools" Version="4.3.0" />
28+
<PackageVersion Include="System.Diagnostics.Tracing" Version="4.3.0" />
29+
<PackageVersion Include="System.Globalization" Version="4.3.0" />
30+
<PackageVersion Include="System.IO.Compression" Version="4.3.0" />
31+
<PackageVersion Include="System.Linq" Version="4.3.0" />
32+
<PackageVersion Include="System.Linq.Expressions" Version="4.3.0" />
33+
<PackageVersion Include="System.ObjectModel" Version="4.3.0" />
34+
<PackageVersion Include="System.Reflection" Version="4.3.0" />
35+
<PackageVersion Include="System.Reflection.Extensions" Version="4.3.0" />
36+
<PackageVersion Include="System.Reflection.Primitives" Version="4.3.0" />
37+
<PackageVersion Include="System.Resources.ResourceManager" Version="4.3.0" />
38+
<PackageVersion Include="System.Runtime" Version="4.3.1" />
39+
<PackageVersion Include="System.Runtime.Caching" Version="9.0.5" />
40+
<PackageVersion Include="System.Runtime.Extensions" Version="4.3.1" />
41+
<PackageVersion Include="System.Runtime.InteropServices" Version="4.3.0" />
42+
<PackageVersion Include="System.Runtime.InteropServices.RuntimeInformation" Version="4.3.0" />
43+
<PackageVersion Include="System.Runtime.Numerics" Version="4.3.0" />
44+
<PackageVersion Include="System.Security.Cryptography.Algorithms" Version="4.3.1" />
45+
<PackageVersion Include="System.Security.Cryptography.X509Certificates" Version="4.3.2" />
46+
<PackageVersion Include="System.Text.Encoding" Version="4.3.0" />
47+
<PackageVersion Include="System.Text.Encoding.Extensions" Version="4.3.0" />
48+
<PackageVersion Include="System.Threading" Version="4.3.0" />
49+
<PackageVersion Include="System.Threading.Tasks" Version="4.3.0" />
50+
<PackageVersion Include="System.Threading.Timer" Version="4.3.0" />
51+
<PackageVersion Include="System.Xml.ReaderWriter" Version="4.3.1" />
52+
<PackageVersion Include="System.Xml.XDocument" Version="4.3.0" />
53+
</ItemGroup>
5554
</Project>

0 commit comments

Comments
 (0)