Skip to content

Commit c8346a3

Browse files
committed
RelayBot: Upgrade from .netcore2.1 to .net9.0
1 parent 5881d1a commit c8346a3

File tree

4 files changed

+29
-14
lines changed

4 files changed

+29
-14
lines changed

RelayBotSample/Program.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4-
using Microsoft.AspNetCore;
54
using Microsoft.AspNetCore.Hosting;
5+
using Microsoft.Extensions.Hosting;
66

77
namespace Microsoft.PowerVirtualAgents.Samples.RelayBotSample
88
{
99
public class Program
1010
{
1111
public static void Main(string[] args)
1212
{
13-
CreateWebHostBuilder(args).Build().Run();
13+
CreateHostBuilder(args).Build().Run();
1414
}
1515

16-
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
17-
WebHost.CreateDefaultBuilder(args)
18-
.UseStartup<Startup>();
16+
public static IHostBuilder CreateHostBuilder(string[] args) =>
17+
Host.CreateDefaultBuilder(args)
18+
.ConfigureWebHostDefaults(webBuilder =>
19+
{
20+
webBuilder.UseStartup<Startup>();
21+
});
1922
}
2023
}

RelayBotSample/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ This bot has been created based on [Bot Framework](https://dev.botframework.com)
66

77
## Prerequisites
88

9-
- [.NET Core SDK](https://dotnet.microsoft.com/download) version 2.1
9+
- [.NET SDK](https://dotnet.microsoft.com/download) version 9.0
1010

1111
```bash
1212
# determine dotnet version

RelayBotSample/SampleBot.csproj

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp2.1</TargetFramework>
4+
<TargetFramework>net9.0</TargetFramework>
55
<LangVersion>latest</LangVersion>
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="Microsoft.AspNetCore.App" />
10-
<PackageReference Include="Microsoft.Bot.Builder.Integration.AspNet.Core" Version="4.5.1" />
9+
<PackageReference Include="Microsoft.Bot.Builder.Integration.AspNet.Core" Version="4.23.0" />
1110
<PackageReference Include="Microsoft.Bot.Connector.DirectLine" Version="3.0.2" />
1211
</ItemGroup>
1312

RelayBotSample/Startup.cs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33

44
using Microsoft.AspNetCore.Builder;
55
using Microsoft.AspNetCore.Hosting;
6-
using Microsoft.AspNetCore.Mvc;
76
using Microsoft.Bot.Builder;
87
using Microsoft.Bot.Builder.Integration.AspNet.Core;
8+
using Microsoft.Bot.Connector.Authentication;
99
using Microsoft.Extensions.Configuration;
1010
using Microsoft.Extensions.DependencyInjection;
11+
using Microsoft.Extensions.Hosting;
1112
using Microsoft.PowerVirtualAgents.Samples.RelayBotSample.Bots;
1213

1314
namespace Microsoft.PowerVirtualAgents.Samples.RelayBotSample
@@ -24,10 +25,13 @@ public Startup(IConfiguration configuration)
2425
// This method gets called by the runtime. Use this method to add services to the container.
2526
public void ConfigureServices(IServiceCollection services)
2627
{
27-
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
28+
services.AddControllers();
29+
30+
// Create the Bot Framework Authentication to be used with the Bot Adapter.
31+
services.AddSingleton<BotFrameworkAuthentication, ConfigurationBotFrameworkAuthentication>();
2832

2933
// Create the Bot Framework Adapter with error handling enabled.
30-
services.AddSingleton<IBotFrameworkHttpAdapter, AdapterWithErrorHandler>();
34+
services.AddSingleton<CloudAdapter, AdapterWithErrorHandler>();
3135

3236
// Create the bot as a transient. In this case the ASP Controller is expecting an IBot.
3337
services.AddSingleton<IBot, RelayBot>();
@@ -44,7 +48,7 @@ public void ConfigureServices(IServiceCollection services)
4448
}
4549

4650
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
47-
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
51+
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
4852
{
4953
if (env.IsDevelopment())
5054
{
@@ -55,10 +59,19 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env)
5559
app.UseHsts();
5660
}
5761

62+
// app.UseHttpsRedirection();
63+
5864
app.UseDefaultFiles();
5965
app.UseStaticFiles();
6066

61-
app.UseMvc();
67+
app.UseRouting();
68+
69+
app.UseAuthorization();
70+
71+
app.UseEndpoints(endpoints =>
72+
{
73+
endpoints.MapControllers();
74+
});
6275
}
6376
}
6477
}

0 commit comments

Comments
 (0)