mirror of
https://github.com/velopack/velopack.git
synced 2025-10-25 15:19:22 +00:00
Remove unused dependencies
This commit is contained in:
@@ -9,8 +9,6 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AWSSDK.S3" Version="3.7.305.4" />
|
||||
<PackageReference Include="Octokit" Version="9.1.0" />
|
||||
<PackageReference Include="System.Linq.Async" Version="6.0.1" />
|
||||
<PackageReference Include="NuGet.Commands" Version="6.8.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -11,9 +11,4 @@
|
||||
<ProjectReference Include="..\Velopack.Packaging\Velopack.Packaging.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="PeNet" Version="4.0.4" />
|
||||
<PackageReference Include="System.Drawing.Common" Version="8.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -1,85 +0,0 @@
|
||||
using System.Xml.Linq;
|
||||
using Microsoft.Build.Construction;
|
||||
using NuGet.Versioning;
|
||||
|
||||
namespace Velopack.Vpk.Compat;
|
||||
|
||||
public class SdkVersionLocator
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public SdkVersionLocator(ILogger logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public NuGetVersion Search(string solutionDir, string packageName)
|
||||
{
|
||||
var dependencies = GetPackageVersionsFromDir(solutionDir, packageName).Distinct().ToArray();
|
||||
|
||||
if (dependencies.Length == 0) {
|
||||
throw new Exception($"{packageName} nuget package was not found installed in solution.");
|
||||
}
|
||||
|
||||
if (dependencies.Length > 1) {
|
||||
throw new Exception($"Found multiple versions of {packageName} installed in solution ({string.Join(", ", dependencies)}). " +
|
||||
$"Please consolidate to a single version.'");
|
||||
}
|
||||
|
||||
var targetVersion = dependencies.Single();
|
||||
return NuGetVersion.Parse(targetVersion);
|
||||
}
|
||||
|
||||
IEnumerable<string> GetPackageVersionsFromDir(string rootDir, string packageName)
|
||||
{
|
||||
// old-style framework packages.config
|
||||
foreach (var packagesFile in EnumerateFilesUntilSpecificDepth(rootDir, "packages.config", 3)) {
|
||||
using var xmlStream = File.OpenRead(packagesFile);
|
||||
var xdoc = XDocument.Load(xmlStream);
|
||||
|
||||
var sqel = xdoc.Root?.Elements().FirstOrDefault(e => e.Attribute("id")?.Value == packageName);
|
||||
var ver = sqel?.Attribute("version");
|
||||
if (ver == null) continue;
|
||||
|
||||
_logger.Debug($"{packageName} {ver.Value} referenced in {packagesFile}");
|
||||
|
||||
if (ver.Value.Contains('*'))
|
||||
throw new Exception(
|
||||
$"Wildcard versions are not supported in packages.config. Remove wildcard or upgrade csproj format to use PackageReference.");
|
||||
|
||||
yield return ver.Value;
|
||||
}
|
||||
|
||||
// new-style csproj PackageReference
|
||||
foreach (var projFile in EnumerateFilesUntilSpecificDepth(rootDir, "*.csproj", 3)) {
|
||||
var proj = ProjectRootElement.Open(projFile);
|
||||
if (proj == null) continue;
|
||||
|
||||
ProjectItemElement item = proj.Items.FirstOrDefault(i => i.ItemType == "PackageReference" && i.Include == packageName);
|
||||
if (item == null) continue;
|
||||
|
||||
var version = item.Children.FirstOrDefault(x => x.ElementName == "Version") as ProjectMetadataElement;
|
||||
if (version?.Value == null) continue;
|
||||
|
||||
_logger.Debug($"{packageName} {version.Value} referenced in {projFile}");
|
||||
|
||||
yield return version.Value;
|
||||
}
|
||||
}
|
||||
|
||||
static IEnumerable<string> EnumerateFilesUntilSpecificDepth(string rootPath, string searchPattern, int maxDepth, int currentDepth = 0)
|
||||
{
|
||||
var files = Directory.EnumerateFiles(rootPath, searchPattern, SearchOption.TopDirectoryOnly);
|
||||
foreach (var f in files) {
|
||||
yield return f;
|
||||
}
|
||||
|
||||
if (currentDepth < maxDepth) {
|
||||
foreach (var dir in Directory.EnumerateDirectories(rootPath)) {
|
||||
foreach (var file in EnumerateFilesUntilSpecificDepth(dir, searchPattern, maxDepth, currentDepth + 1)) {
|
||||
yield return file;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -42,13 +42,10 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Build" Version="17.3.2" />
|
||||
<PackageReference Include="NuGet.Protocol" Version="6.8.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
|
||||
<PackageReference Include="Serilog.Extensions.Hosting" Version="8.0.0" />
|
||||
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.1" />
|
||||
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.23407.1" />
|
||||
<PackageReference Include="System.Xml.XDocument" Version="4.3.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user