Skip to content

Commit 1595ce3

Browse files
fredrikhrjonsequitur
authored andcommitted
Update Generic Host projects for .NET Standard 2.1 / .NET Core 3.0
1 parent 0455e35 commit 1595ce3

File tree

5 files changed

+23
-21
lines changed

5 files changed

+23
-21
lines changed

samples/HostingPlayground/HostingPlayground.csproj

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,9 @@
77
<LangVersion>8</LangVersion>
88
</PropertyGroup>
99

10-
1110
<ItemGroup>
1211
<ProjectReference Include="..\..\src\System.CommandLine.Hosting\System.CommandLine.Hosting.csproj" />
1312
<ProjectReference Include="..\..\src\System.CommandLine\System.CommandLine.csproj" />
1413
</ItemGroup>
1514

16-
17-
<ItemGroup>
18-
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.4" />
19-
<PackageReference Include="microsoft.extensions.hosting" Version="3.1.4" />
20-
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.4" />
21-
</ItemGroup>
22-
2315
</Project>

src/System.CommandLine.Hosting.Tests/System.CommandLine.Hosting.Tests.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515

1616
<ItemGroup>
1717
<PackageReference Include="FluentAssertions" Version="5.10.3" />
18+
</ItemGroup>
19+
20+
<ItemGroup Condition="'$(TargetFramework)'!='netcoreapp3.1'">
1821
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="2.2.0" />
1922
</ItemGroup>
2023

src/System.CommandLine.Hosting/HostingExtensions.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,15 @@ public static CommandLineBuilder UseHost(this CommandLineBuilder builder,
3939
hostBuilder.UseInvocationLifetime(invocation);
4040
configureHost?.Invoke(hostBuilder);
4141

42-
using (var host = hostBuilder.Build())
43-
{
44-
invocation.BindingContext.AddService(typeof(IHost), _ => host);
42+
using var host = hostBuilder.Build();
43+
44+
invocation.BindingContext.AddService(typeof(IHost), _ => host);
4545

46-
await host.StartAsync();
46+
await host.StartAsync();
4747

48-
await next(invocation);
48+
await next(invocation);
4949

50-
await host.StopAsync();
51-
}
50+
await host.StopAsync();
5251
});
5352

5453
public static CommandLineBuilder UseHost(this CommandLineBuilder builder,

src/System.CommandLine.Hosting/InvocationLifetime.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
using Microsoft.Extensions.Logging.Abstractions;
88
using Microsoft.Extensions.Options;
99

10+
#if NETSTANDARD2_0
11+
using IHostEnvironment = Microsoft.Extensions.Hosting.IHostingEnvironment;
12+
using IHostApplicationLifetime = Microsoft.Extensions.Hosting.IApplicationLifetime;
13+
#endif
14+
1015
namespace System.CommandLine.Hosting
1116
{
1217
public class InvocationLifetime : IHostLifetime
@@ -18,8 +23,8 @@ public class InvocationLifetime : IHostLifetime
1823

1924
public InvocationLifetime(
2025
IOptions<InvocationLifetimeOptions> options,
21-
IHostingEnvironment environment,
22-
IApplicationLifetime applicationLifetime,
26+
IHostEnvironment environment,
27+
IHostApplicationLifetime applicationLifetime,
2328
InvocationContext context = null,
2429
ILoggerFactory loggerFactory = null)
2530
{
@@ -40,8 +45,8 @@ public InvocationLifetime(
4045

4146
public InvocationLifetimeOptions Options { get; }
4247
private ILogger Logger { get; }
43-
public IHostingEnvironment Environment { get; }
44-
public IApplicationLifetime ApplicationLifetime { get; }
48+
public IHostEnvironment Environment { get; }
49+
public IHostApplicationLifetime ApplicationLifetime { get; }
4550

4651
public Task WaitForStartAsync(CancellationToken cancellationToken)
4752
{

src/System.CommandLine.Hosting/System.CommandLine.Hosting.csproj

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<IsPackable>true</IsPackable>
5-
<TargetFramework>netstandard2.0</TargetFramework>
5+
<TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>
66
<LangVersion>latest</LangVersion>
77
<Description>This package provides support for using System.CommandLine with Microsoft.Extensions.Hosting.</Description>
88
</PropertyGroup>
@@ -11,9 +11,12 @@
1111
<DebugType>portable</DebugType>
1212
</PropertyGroup>
1313

14-
<ItemGroup>
14+
<ItemGroup Condition="'$(TargetFramework)'=='netstandard2.0'">
1515
<PackageReference Include="Microsoft.Extensions.Hosting" Version="2.2.0" />
1616
</ItemGroup>
17+
<ItemGroup Condition="'$(TargetFramework)'=='netstandard2.1'">
18+
<PackageReference Include="Microsoft.Extensions.Hosting" Version="3.1.5" />
19+
</ItemGroup>
1720

1821
<ItemGroup>
1922
<ProjectReference Include="..\System.CommandLine\System.CommandLine.csproj" />

0 commit comments

Comments
 (0)