Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Autofac" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Qwerty\Qwerty.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Asdf
{
public class Class1
{

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.13.36105.23
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Asdf", "Asdf\Asdf.csproj", "{0026E591-BDA2-59CD-C237-1513DA9668F8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Qwerty", "Qwerty\Qwerty.csproj", "{D9EE6D9A-329C-4B70-831C-EBDB4498C490}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{0026E591-BDA2-59CD-C237-1513DA9668F8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0026E591-BDA2-59CD-C237-1513DA9668F8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0026E591-BDA2-59CD-C237-1513DA9668F8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0026E591-BDA2-59CD-C237-1513DA9668F8}.Release|Any CPU.Build.0 = Release|Any CPU
{D9EE6D9A-329C-4B70-831C-EBDB4498C490}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D9EE6D9A-329C-4B70-831C-EBDB4498C490}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D9EE6D9A-329C-4B70-831C-EBDB4498C490}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D9EE6D9A-329C-4B70-831C-EBDB4498C490}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {95C9EDD6-8E73-4BC8-9DD0-D25CE6E91111}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>

<ItemGroup>
<PackageVersion Include="Autofac" Version="4.9.4" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Qwerty
{
public class Class1
{

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Autofac" />
</ItemGroup>

</Project>
13 changes: 13 additions & 0 deletions src/Snitch.Tests/Expectations/Asdf.Default.verified.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Analyzing...
Analyzing CentralizedPackageManagement.sln
Analyzing Asdf...
* Analyzing Qwerty (net8.0)...

╭──────────────────────────────────────────╮
│ Packages that can be removed from Asdf: │
│ ┌──────────────┬───────────────────────┐ │
│ │ Package │ Referenced by │ │
│ ├──────────────┼───────────────────────┤ │
│ │ Autofac │ Qwerty │ │
│ └──────────────┴───────────────────────┘ │
╰──────────────────────────────────────────╯
22 changes: 19 additions & 3 deletions src/Snitch.Tests/ProgramTests.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
using Shouldly;
using Snitch;
using System;
using System.IO;
using System.Threading.Tasks;
using Shouldly;
using Snitch;
using Spectre.Console.Cli;
using Spectre.Console.Testing;
using VerifyTests;
using Xunit;
using VerifyXunit;
using Xunit;

namespace Sntich.Tests
{
Expand Down Expand Up @@ -190,6 +190,22 @@ public async Task Should_Return_Zero_Exit_Code_For_Thuuud_When_Running_With_NoPr
await Verifier.Verify(output);
}

[Fact]
[Expectation("Asdf", "Default")]
public async Task Should_Return_Expected_Result_For_Centralized_Package_Management()
{
// Given
var fixture = new Fixture();
var project = Fixture.GetPath("CentralizedPackageManagement/CentralizedPackageManagement.sln");

// When
var (exitCode, output) = await Fixture.Run(project);

// Then
exitCode.ShouldBe(0);
await Verifier.Verify(output);
}

public sealed class Fixture
{
public static string GetPath(string path)
Expand Down
21 changes: 13 additions & 8 deletions src/Snitch/Analysis/Models/Package.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ public bool IsGreaterThan(Package package, out bool indeterminate)

public bool IsSameVersion(Package package)
{
if (Version != null && package.Version != null)
if (Version == null && package.Version == null && Range == null && package.Range == null)
{
// Both are null, considered equal
return true;
}
else if (Version != null && package.Version != null)
{
// Version == Version
return new VersionComparer().Equals(Version, package.Version);
Expand All @@ -69,7 +74,7 @@ public string GetVersionString()
return Range?.OriginalString ?? "?";
}

public Package(string name, string version, string? privateAssets)
public Package(string name, string? version, string? privateAssets)
{
Name = name ?? throw new ArgumentNullException(nameof(name));
PrivateAssets = privateAssets;
Expand All @@ -79,16 +84,16 @@ public Package(string name, string version, string? privateAssets)
Version = semanticVersion;
Range = null;
}
else
else if (VersionRange.TryParse(version, out var range))
{
if (!VersionRange.TryParse(version, out var range))
{
throw new ArgumentException($"Version '{version}' for package '{name}' is not valid.", nameof(version));
}

Version = null;
Range = range;
}
else
{
Version = null;
Range = null;
}
}
}
}
9 changes: 3 additions & 6 deletions src/Snitch/Analysis/ProjectBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,9 @@ private Project Build(
// Get the package references.
foreach (var packageReference in result.PackageReferences)
{
if (packageReference.Value.TryGetValue("Version", out var version))
{
var privateAssets = packageReference.Value.GetValueOrDefault("PrivateAssets");

project.Packages.Add(new Package(packageReference.Key, version, privateAssets));
}
var version = packageReference.Value.GetValueOrDefault("Version");
var privateAssets = packageReference.Value.GetValueOrDefault("PrivateAssets");
project.Packages.Add(new Package(packageReference.Key, version, privateAssets));
}

// Analyze all project references.
Expand Down