Skip to content

Commit

Permalink
Publish package tool as a .NET tool
Browse files Browse the repository at this point in the history
  • Loading branch information
talenfisher committed Feb 7, 2022
1 parent 7c0246e commit 67e7b20
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 99 deletions.
84 changes: 21 additions & 63 deletions src/Sdk.PackageTool/Program.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.Loader;

using Brighid.Commands.Sdk.PackageTool;

Expand All @@ -15,67 +10,30 @@

#pragma warning disable SA1516 // Elements separated by blank line

SetupDependencyResolver();
Run(args);

static void SetupDependencyResolver()
Host.CreateDefaultBuilder()
.UseConsoleLifetime()
.UseSerilog(dispose: true)
.ConfigureLogging(options =>
{
var additionalProbingPath = Environment.GetEnvironmentVariable("ADDITIONAL_PROBING_PATH")!;
var dllsInProbingPath = from file in Directory.GetFiles(additionalProbingPath, $"*.dll", SearchOption.AllDirectories)
where file.Contains("netstandard") || file.Contains("net6.0") || file.Contains("net5.0")
select file;

AssemblyLoadContext.Default.Resolving += (_, name) =>
options.AddSimpleConsole(consoleOptions =>
{
var query = from dll in dllsInProbingPath
where dll.EndsWith($"{name.Name}.dll", true, null)
let assembly = TryLoadAssembly(dll)
where assembly != null
select assembly;
return query.FirstOrDefault();
};
}

static Assembly? TryLoadAssembly(string path)
consoleOptions.SingleLine = true;
});
})
.ConfigureHostConfiguration(options =>
{
try
{
return Assembly.LoadFile(path);
}
catch (Exception)
if (args.Length > 1)
{
return null;
options.AddCommandLine(args[1..], new Dictionary<string, string>
{
["--bucket-name"] = "CommandLine:S3BucketName",
["--destination"] = "CommandLine:TemplateDestination",
});
}
}

static void Run(string[] args)
})
.ConfigureServices((context, services) =>
{
Host.CreateDefaultBuilder()
.UseConsoleLifetime()
.UseSerilog(dispose: true)
.ConfigureLogging(options =>
{
options.AddSimpleConsole(consoleOptions =>
{
consoleOptions.SingleLine = true;
});
})
.ConfigureHostConfiguration(options =>
{
if (args.Length > 1)
{
options.AddCommandLine(args[1..], new Dictionary<string, string>
{
["--bucket-name"] = "CommandLine:S3BucketName",
["--destination"] = "CommandLine:TemplateDestination",
});
}
})
.ConfigureServices((context, services) =>
{
new Startup(context.Configuration).ConfigureServices(services);
})
.Build()
.Run();
}
new Startup(context.Configuration).ConfigureServices(services);
})
.Build()
.Run();
12 changes: 2 additions & 10 deletions src/Sdk.PackageTool/Sdk.PackageTool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<PackageId>Brighid.Commands.Sdk.PackageTool</PackageId>
<ToolCommandName>pack-brighid-commands</ToolCommandName>
<AssemblyName>$(PackageId)</AssemblyName>
<PackAsTool>true</PackAsTool>
<RollForward>latestMajor</RollForward>
<NoWarn>CS1591</NoWarn>
<BeforePack>IncludeExtraPackItems</BeforePack>
</PropertyGroup>

<ItemGroup>
Expand All @@ -17,15 +18,6 @@
<PackageReference Include="YamlDotNet" Version="11.2.1" />
</ItemGroup>

<ItemGroup></ItemGroup>

<Target Name="IncludeExtraPackItems">
<ItemGroup>
<None Include="buildTransitive/" Pack="true" PackagePath="buildTransitive/" />
<None Include="$(OutputPath)/$(PackageId).deps.json" Pack="true" PackagePath="lib/$(TargetFramework)" />
</ItemGroup>
</Target>

<ItemGroup>
<ProjectReference Include="../Sdk.Models/Sdk.Models.csproj" />
</ItemGroup>
Expand Down

This file was deleted.

This file was deleted.

0 comments on commit 67e7b20

Please sign in to comment.