Skip to content

Commit

Permalink
Few bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mysticmind committed Nov 12, 2021
1 parent 153fd0d commit fd6e7f9
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 40 deletions.
5 changes: 2 additions & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ os: Visual Studio 2022
environment:
DOTNET_CLI_TELEMETRY_OPTOUT: true
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
TARGET_BUILD_VERSION: '1.0.0'
NUGET_DEPLOY_KEY:
secure: bfIsyEMzYM9AJCFQwxLjAC48zi8/pNgUokbWcEcEo4hzLvrGCKEN6pNYkQIx/w2J

Expand All @@ -19,10 +18,10 @@ before_build:
- dotnet restore .\src\DotNetSortRefs.sln

build_script:
- dotnet build .\src\DotNetSortRefs.sln --configuration Release /p:Version=%TARGET_BUILD_VERSION%
- dotnet build .\src\DotNetSortRefs.sln --configuration Release

after_test:
- dotnet pack .\src\DotNetSortRefs --configuration Release /p:Version=%TARGET_BUILD_VERSION%
- dotnet pack .\src\DotNetSortRefs --configuration Release

artifacts:
- path: '**\dotnet-sort-refs.*.*nupkg' # find all NuGet packages recursively
Expand Down
4 changes: 2 additions & 2 deletions 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>1.0.0</VersionPrefix>
<VersionPrefix>1.0.1</VersionPrefix>
<Authors>Babu Annamalai</Authors>
<OutputType>Exe</OutputType>
<TargetFrameworks>netcoreapp3.1;net5.0;net6.0</TargetFrameworks>
Expand All @@ -19,7 +19,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="McMaster.Extensions.CommandLineUtils" Version="3.1.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.2" />
<PackageReference Include="System.IO.Abstractions" Version="13.2.47" />
</ItemGroup>
</Project>
64 changes: 29 additions & 35 deletions src/DotNetSortRefs/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,30 +31,28 @@ public Program(IFileSystem fileSystem, IReporter reporter)

static int Main(string[] args)
{
using (var services = new ServiceCollection()
.AddSingleton<IConsole, PhysicalConsole>()
.AddSingleton<IReporter>(provider => new ConsoleReporter(provider.GetService<IConsole>()))
using var services = new ServiceCollection()
.AddSingleton(PhysicalConsole.Singleton)
.AddSingleton<IReporter>(provider => new ConsoleReporter(provider.GetService<IConsole>()!))
.AddSingleton<IFileSystem, FileSystem>()
.BuildServiceProvider())
.BuildServiceProvider();
var app = new CommandLineApplication<Program>
{
var app = new CommandLineApplication<Program>
{
UnrecognizedArgumentHandling = UnrecognizedArgumentHandling.Throw
};
UnrecognizedArgumentHandling = UnrecognizedArgumentHandling.Throw
};

app.Conventions
.UseDefaultConventions()
.UseConstructorInjection(services);
app.Conventions
.UseDefaultConventions()
.UseConstructorInjection(services);

try
{
return app.Execute(args);
}
catch (UnrecognizedCommandParsingException)
{
app.ShowHelp();
return 1;
}
try
{
return app.Execute(args);
}
catch (UnrecognizedCommandParsingException)
{
app.ShowHelp();
return 1;
}
}

Expand All @@ -69,7 +67,7 @@ static int Main(string[] args)
private static string GetVersion() => typeof(Program)
.Assembly
.GetCustomAttribute<AssemblyInformationalVersionAttribute>()
.InformationalVersion;
?.InformationalVersion;

private async Task<int> OnExecute(CommandLineApplication app, IConsole console)
{
Expand Down Expand Up @@ -118,7 +116,7 @@ private async Task<int> OnExecute(CommandLineApplication app, IConsole console)
}
catch (Exception e)
{
_reporter.Error(e.StackTrace);
_reporter.Error(e.StackTrace!);
return 1;
}
}
Expand Down Expand Up @@ -181,12 +179,10 @@ private async Task<int> SortReferences(IEnumerable<string> projFiles)
{
_reporter.Output($"» {proj}");

using (var sw = new StringWriter())
{
var doc = XDocument.Parse(System.IO.File.ReadAllText(proj));
xslt.Transform(doc.CreateNavigator(), null, sw);
File.WriteAllText(proj, sw.ToString());
}
await using var sw = new StringWriter();
var doc = XDocument.Parse(await System.IO.File.ReadAllTextAsync(proj));
xslt.Transform(doc.CreateNavigator(), null, sw);
await File.WriteAllTextAsync(proj, sw.ToString());
}

return await Task.FromResult(0);
Expand All @@ -195,13 +191,11 @@ private async Task<int> SortReferences(IEnumerable<string> projFiles)
private static XslCompiledTransform GetXslTransform()
{
var assembly = Assembly.GetExecutingAssembly();
using (var stream = assembly.GetManifestResourceStream("DotNetSortRefs.Sort.xsl"))
using (var reader = XmlReader.Create(stream))
{
var xslt = new XslCompiledTransform();
xslt.Load(reader);
return xslt;
}
using var stream = assembly.GetManifestResourceStream("DotNetSortRefs.Sort.xsl");
using var reader = XmlReader.Create(stream!);
var xslt = new XslCompiledTransform();
xslt.Load(reader);
return xslt;
}
}
}

0 comments on commit fd6e7f9

Please sign in to comment.