Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions .azdo/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,16 @@ stages:
steps:

- task: UseDotNet@2
displayName: 'Use .NET 9'
displayName: 'Use .NET 8'
inputs:
packageType: 'sdk'
version: '9.0.x'
version: '8.0.x'

- task: UseDotNet@2
displayName: 'Use .NET 10'
inputs:
packageType: 'sdk'
version: '10.0.x'

- script: dotnet restore
displayName: 'Restore'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace Microsoft.Teams.Apps.Annotations;

[AttributeUsage(AttributeTargets.Class, Inherited = true)]
[Obsolete("Use Minimal APIs instead.")]
public class TeamsControllerAttribute(string? name = null) : Attribute
{
public string? Name { get; } = name;
Expand Down
1 change: 1 addition & 0 deletions Libraries/Microsoft.Teams.Apps/AppRouting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public partial class App
{
internal IRouter Router { get; } = new Router();

[Obsolete("Use Minimal APIs instead.")]
public App AddController<T>(T controller) where T : class
{
var type = controller.GetType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace Microsoft.Teams.Plugins.AspNetCore.BotBuilder
{
[ApiController]
[Obsolete("Use Minimal APIs instead.")]
public class MessageController : ControllerBase
{
private readonly IBotFrameworkHttpAdapter _adapter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,18 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using Microsoft.AspNetCore.Mvc.ApplicationParts;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Integration.AspNet.Core;
using Microsoft.Bot.Connector.Authentication;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Teams.Plugins.AspNetCore.Controllers;

namespace Microsoft.Teams.Plugins.AspNetCore.Extensions;

public static class HostApplicationBuilderExtensions
{
public static IHostApplicationBuilder AddBotBuilder(this IHostApplicationBuilder builder)
{
builder.Services.AddControllers().ConfigureApplicationPartManager((apm) =>
{
apm.FeatureProviders.Add(new RemoveDefaultMessageController());
apm.ApplicationParts.Add(new AssemblyPart(typeof(MessageController).Assembly));
});
return builder;
}

Expand All @@ -28,11 +21,7 @@ public static IHostApplicationBuilder AddBotBuilder<TBot>(this IHostApplicationB
builder.Services.AddSingleton(authentication);
builder.Services.AddSingleton(adapter);
builder.Services.AddTransient<IBot, TBot>();
builder.Services.AddControllers().ConfigureApplicationPartManager((apm) =>
{
apm.FeatureProviders.Add(new RemoveDefaultMessageController());
apm.ApplicationParts.Add(new AssemblyPart(typeof(MessageController).Assembly));
});

return builder;
}

Expand All @@ -41,11 +30,7 @@ public static IHostApplicationBuilder AddBotBuilder<TBot, TBotFrameworkHttpAdapt
builder.Services.AddSingleton<BotFrameworkAuthentication, TBotFrameworkAuthentication>();
builder.Services.AddSingleton<IBotFrameworkHttpAdapter, TBotFrameworkHttpAdapter>();
builder.Services.AddTransient<IBot, TBot>();
builder.Services.AddControllers().ConfigureApplicationPartManager((apm) =>
{
apm.FeatureProviders.Add(new RemoveDefaultMessageController());
apm.ApplicationParts.Add(new AssemblyPart(typeof(MessageController).Assembly));
});

return builder;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
namespace Microsoft.Teams.Plugins.AspNetCore.DevTools.Controllers;

[ApiController]
[Obsolete("Use Minimal APIs instead.")]
public class ActivityController : ControllerBase
{
private readonly DevToolsPlugin _plugin;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@
using System.Reflection;

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Teams.Api.Auth;
using Microsoft.Teams.Apps;
using Microsoft.Teams.Apps.Annotations;
using Microsoft.Teams.Apps.Plugins;

using static Microsoft.Teams.Plugins.AspNetCore.Extensions.HostApplicationBuilderExtensions;

namespace Microsoft.Teams.Plugins.AspNetCore.Extensions;

public static partial class ApplicationBuilderExtensions
Expand All @@ -28,7 +32,9 @@ public static App UseTeams(this IApplicationBuilder builder, bool routing = true

foreach (var type in types)
{
#pragma warning disable CS0618 // Type or member is obsolete
var attribute = type.GetCustomAttribute<TeamsControllerAttribute>();
#pragma warning restore CS0618 // Type or member is obsolete

if (attribute is null)
{
Expand All @@ -39,7 +45,9 @@ public static App UseTeams(this IApplicationBuilder builder, bool routing = true

if (controller is not null)
{
#pragma warning disable CS0618 // Type or member is obsolete
app.AddController(controller);
#pragma warning restore CS0618 // Type or member is obsolete
}
}

Expand All @@ -57,7 +65,24 @@ public static App UseTeams(this IApplicationBuilder builder, bool routing = true
{
builder.UseRouting();
builder.UseAuthorization();
builder.UseEndpoints(endpoints => endpoints.MapControllers());

// Get AspNetCorePlugin for endpoint registration
var aspNetCorePlugin = plugins.OfType<AspNetCorePlugin>().FirstOrDefault();

builder.UseEndpoints(endpoints =>
{
// Map AspNetCorePlugin endpoint
if (aspNetCorePlugin is not null)
{
endpoints.MapPost("/api/messages", async (HttpContext httpContext, CancellationToken cancellationToken) =>
{
return await aspNetCorePlugin.Do(httpContext, cancellationToken);
}).RequireAuthorization(TeamsTokenAuthConstants.AuthorizationPolicy);
}

// Map controller endpoints (obsolete)
endpoints.MapControllers();
Comment thread
rido-min marked this conversation as resolved.
});
}

return app;
Expand Down
19 changes: 17 additions & 2 deletions Microsoft.Teams.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
# Visual Studio Version 18
VisualStudioVersion = 18.2.11415.280 d18.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Libraries", "Libraries", "{809F86A1-1C4C-B159-0CD4-DF9D33D876CE}"
EndProject
Expand Down Expand Up @@ -85,6 +85,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Samples.AI", "Samples\Sampl
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Samples.Meetings", "Samples\Samples.Meetings\Samples.Meetings.csproj", "{FCEEF7AD-1E78-4615-8BE4-7B46B034A514}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Deprecated.Controllers", "Samples\Deprecated.Controllers\Deprecated.Controllers.csproj", "{1F0A8B29-3792-4E11-B6A7-43F03F9A591F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -515,6 +517,18 @@ Global
{FCEEF7AD-1E78-4615-8BE4-7B46B034A514}.Release|x64.Build.0 = Release|Any CPU
{FCEEF7AD-1E78-4615-8BE4-7B46B034A514}.Release|x86.ActiveCfg = Release|Any CPU
{FCEEF7AD-1E78-4615-8BE4-7B46B034A514}.Release|x86.Build.0 = Release|Any CPU
{1F0A8B29-3792-4E11-B6A7-43F03F9A591F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1F0A8B29-3792-4E11-B6A7-43F03F9A591F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1F0A8B29-3792-4E11-B6A7-43F03F9A591F}.Debug|x64.ActiveCfg = Debug|Any CPU
{1F0A8B29-3792-4E11-B6A7-43F03F9A591F}.Debug|x64.Build.0 = Debug|Any CPU
{1F0A8B29-3792-4E11-B6A7-43F03F9A591F}.Debug|x86.ActiveCfg = Debug|Any CPU
{1F0A8B29-3792-4E11-B6A7-43F03F9A591F}.Debug|x86.Build.0 = Debug|Any CPU
{1F0A8B29-3792-4E11-B6A7-43F03F9A591F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1F0A8B29-3792-4E11-B6A7-43F03F9A591F}.Release|Any CPU.Build.0 = Release|Any CPU
{1F0A8B29-3792-4E11-B6A7-43F03F9A591F}.Release|x64.ActiveCfg = Release|Any CPU
{1F0A8B29-3792-4E11-B6A7-43F03F9A591F}.Release|x64.Build.0 = Release|Any CPU
{1F0A8B29-3792-4E11-B6A7-43F03F9A591F}.Release|x86.ActiveCfg = Release|Any CPU
{1F0A8B29-3792-4E11-B6A7-43F03F9A591F}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -558,6 +572,7 @@ Global
{783599E3-9841-4377-9590-4A5D9EC0023D} = {0AB3BF05-4346-4AA6-1389-037BE0695223}
{BCD1AE81-8D5D-461F-AB63-7C0E5882F89B} = {5D20AA90-6969-D8BD-9DCD-8634F4692FDA}
{FCEEF7AD-1E78-4615-8BE4-7B46B034A514} = {5D20AA90-6969-D8BD-9DCD-8634F4692FDA}
{1F0A8B29-3792-4E11-B6A7-43F03F9A591F} = {5D20AA90-6969-D8BD-9DCD-8634F4692FDA}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {378263F2-C2B2-4DB1-83CF-CA228AF03ABF}
Expand Down
18 changes: 18 additions & 0 deletions Samples/Deprecated.Controllers/Deprecated.Controllers.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Libraries\Microsoft.Teams.Plugins\Microsoft.Teams.Plugins.AspNetCore.DevTools\Microsoft.Teams.Plugins.AspNetCore.DevTools.csproj" />
<ProjectReference Include="..\..\Libraries\Microsoft.Teams.Plugins\Microsoft.Teams.Plugins.AspNetCore\Microsoft.Teams.Plugins.AspNetCore.csproj" />
</ItemGroup>

</Project>
17 changes: 17 additions & 0 deletions Samples/Deprecated.Controllers/MainController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Microsoft.Teams.Api.Activities;
using Microsoft.Teams.Apps;
using Microsoft.Teams.Apps.Annotations;
using Microsoft.Teams.Apps.Activities;

namespace Deprecated.Controllers;

[TeamsController("main")]
[Obsolete]
public class MainController
{
[Message]
public async Task OnMessage([Context] MessageActivity activity, [Context] IContext.Client client)
{
await client.Send($"you said \"{activity.Text}\"");
}
}
20 changes: 20 additions & 0 deletions Samples/Deprecated.Controllers/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Microsoft.Teams.Plugins.AspNetCore.DevTools.Extensions;
using Microsoft.Teams.Plugins.AspNetCore.Extensions;

using Deprecated.Controllers;

var builder = WebApplication.CreateBuilder(args);
builder.AddTeams().AddTeamsDevTools();
#pragma warning disable CS0612 // Type or member is obsolete
builder.Services.AddTransient<MainController>();
#pragma warning restore CS0612 // Type or member is obsolete

var app = builder.Build();

if (app.Environment.IsDevelopment())
{
app.MapOpenApi();
}

app.UseTeams();
app.Run();
15 changes: 15 additions & 0 deletions Samples/Deprecated.Controllers/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:3978",
"launchUrl": "devtools",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Local"
}
}
}
}
12 changes: 12 additions & 0 deletions Samples/Deprecated.Controllers/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
},
"Microsoft.Teams": {
"Level": "info"
}
},
"AllowedHosts": "*"
}
9 changes: 9 additions & 0 deletions Samples/Deprecated.Controllers/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
3 changes: 2 additions & 1 deletion Samples/Samples.Echo/Program.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using Microsoft.Teams.Apps.Activities;
using Microsoft.Teams.Apps.Extensions;
using Microsoft.Teams.Plugins.AspNetCore.DevTools.Extensions;
using Microsoft.Teams.Plugins.AspNetCore.Extensions;

var builder = WebApplication.CreateBuilder(args);
builder.AddTeams();
builder.AddTeams().AddTeamsDevTools();
var app = builder.Build();
var teams = app.UseTeams();

Expand Down
1 change: 1 addition & 0 deletions Samples/Samples.McpClient/Controller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

namespace Samples.McpClient;

[Obsolete]
[TeamsController]
public class Controller(Func<OpenAIChatPrompt> _promptFactory)
{
Expand Down
2 changes: 2 additions & 0 deletions Samples/Samples.McpClient/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
using Samples.McpClient;

var builder = WebApplication.CreateBuilder(args);
#pragma warning disable CS0612 // Type or member is obsolete
builder.Services.AddTransient<Controller>().AddHttpContextAccessor();
#pragma warning restore CS0612 // Type or member is obsolete
builder.Services.AddSingleton((sp) => new McpClientPlugin().UseMcpServer("https://learn.microsoft.com/api/mcp"));
builder.AddTeams().AddTeamsDevTools().AddOpenAI<DocsPrompt>();

Expand Down
Loading
Loading