Skip to content

Commit

Permalink
Fix few bugs and regression
Browse files Browse the repository at this point in the history
- Fix regression causing path param to fail
- Fix bug with inspection logic failing for csproj with multiple itemgroups
- Bump up version to 0.2.1
  • Loading branch information
mysticmind committed Jan 14, 2020
1 parent 96bc8ee commit 515536b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ os: Visual Studio 2017
environment:
DOTNET_CLI_TELEMETRY_OPTOUT: true
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
TARGET_BUILD_VERSION: '0.2.0'
TARGET_BUILD_VERSION: '0.2.1'
NUGET_DEPLOY_KEY:
secure: 6yOBK0JyKMTykW1zW6B4mvc9mgQGnRGex15KG8VhOre/DSTkrUYtgbPCpiBlcX/T

Expand Down
2 changes: 1 addition & 1 deletion src/DotNetSortRefs/DotNetSortRefs.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Description>A .NET Core global tool to alphabetically sort package references in csproj or fsproj</Description>
<VersionPrefix>0.2.0</VersionPrefix>
<VersionPrefix>0.2.1</VersionPrefix>
<Authors>Babu Annamalai</Authors>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
Expand Down
31 changes: 21 additions & 10 deletions src/DotNetSortRefs/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,11 @@ private async Task<int> OnExecute(CommandLineApplication app, IConsole console)
{
projFiles.Add(Path);
}

projFiles = _fileSystem.Directory.GetFiles(Path, "*.csproj", SearchOption.AllDirectories)
.Concat(_fileSystem.Directory.GetFiles(Path, "*.fsproj", SearchOption.AllDirectories)).ToList();
else
{
projFiles = _fileSystem.Directory.GetFiles(Path, "*.csproj", SearchOption.AllDirectories)
.Concat(_fileSystem.Directory.GetFiles(Path, "*.fsproj", SearchOption.AllDirectories)).ToList();
}

if (projFiles.Count == 0)
{
Expand Down Expand Up @@ -124,21 +126,30 @@ private async Task<int> OnExecute(CommandLineApplication app, IConsole console)
private static async Task<List<string>> Inspect(IEnumerable<string> projFiles)
{
var projFilesWithNonSortedReferences = new List<string>();

foreach (var proj in projFiles)
{
using (var sw = new StringWriter())
{
var doc = XDocument.Parse(System.IO.File.ReadAllText(proj));

var packages = doc.XPathSelectElements("//ItemGroup[PackageReference|Reference]/*").Select(x => x.Attribute("Include")?.Value.ToLowerInvariant()).ToList();
var sortedPackages = packages.OrderBy(x => x);
var itemGroups = doc.XPathSelectElements("//ItemGroup[PackageReference|Reference]");

var result = packages.SequenceEqual(sortedPackages);

if (!result)
foreach (var itemGroup in itemGroups)
{
projFilesWithNonSortedReferences.Add(proj);
var references = itemGroup.XPathSelectElements("PackageReference|Reference")
.Select(x => x.Attribute("Include")?.Value.ToLowerInvariant()).ToList();

if (references.Count <= 1) continue;

var sortedReferences = references.OrderBy(x => x).ToList();

var result = references.SequenceEqual(sortedReferences);

if (!result && !projFilesWithNonSortedReferences.Contains(proj))
{
projFilesWithNonSortedReferences.Add(proj);
}
}
}
}
Expand Down

0 comments on commit 515536b

Please sign in to comment.