Sdílet prostřednictvím


Create and share packages

APPLIES TO: Composer v2.x

This article describes how to create and publish packages. Packages are elements of Bot Framework Composer bots that you can reuse or share, such as declarative assets, schema files, and components.

At a high level, the steps for creating a package are:

  1. Create the declarative files—use Composer to create them.
  2. Create the components—use your favorite IDE to create them.
  3. Package your files—use NuGet for C# runtime bots or npm for bots using the JavaScript runtime.
  4. Publish your package to a public, private, or local package feed.

Prerequisites

Create packages

This section describes different approaches to create components packages that you can share and reuse. The approach you choose is function of your specific needs.

Create and include declarative files

Tip

Use Composer to create the declarative files, then add them to a folder named exported in the package project.

You can include declarative files (.dialog, .lu, .lg, or .qna) in your packages. Your declarative files must be in a folder named exported at the root of your package. Typically, declarative files aren't included by default (for NuGet, you'd add them in either the .csproj or .nuspec file) when you create your package.

Note

Azure QnA Maker will be retired on 31 March 2025. Beginning 1 October 2022, you won't be able to create new QnA Maker resources or knowledge bases. A newer version of the question and answering capability is now available as part of Azure AI Language.

Custom question answering, a feature of Azure AI Language, is the updated version of the QnA Maker service. For more information about question-and-answer support in Composer, see Natural language processing.

Example .csproj file

This example .csproj file demonstrates including declarative files in the exported folder for a package.

<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <OutputType>Library</OutputType>
        <TargetFramework>netcoreapp3.1</TargetFramework>
        <PackageId>Microsoft.Bot.Components.Samples.MemberUpdates</PackageId>
        <Description>This library implements .NET support for custom triggers for conversation member updates.</Description>
        <Summary>This library implements .NET support for custom triggers for conversation member updates.  OnMembersAdded and OnMembersRemoved.</Summary>
        <ContentTargetFolders>content</ContentTargetFolders>
        <PackageTags>msbot-component;msbot-trigger</PackageTags>
    </PropertyGroup>
    <ItemGroup>
        <Content Include="**/*.schema" />
        <Content Include="**/*.uischema" />
        <None Include="exported/**/*.*" Pack="true" PackagePath="exported" />
        <None Include="README.md" Condition="Exists('README.md')" Pack="true" PackagePath="" />
        <PackageReference Include="Microsoft.Bot.Builder.Dialogs.Adaptive.Runtime" Version="4.13.1" />
    </ItemGroup>
</Project>

Create and include components

The components in a package are the same as what are created when extending your bot with code. Ensure the BotComponent class is used to register any components, as shown in Create the BotComponent class.

Example BotComponent class

To dynamically register your action with the adaptive runtime, define a BotComponent by inheriting from the Microsoft.Bot.Builder.BotComponent class. For example, this registers a simple custom action called MyCustomAction:

using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Dialogs.Declarative;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace MyBot
{
    public class MyBotComponent : BotComponent
    {
        public override void ConfigureServices(IServiceCollection services, IConfiguration configuration)
        {
            // Component type
            services.AddSingleton<DeclarativeType>(sp => new DeclarativeType<MyCustomAction>(MyCustomAction.Kind));
        }
    }
}

Create the component package and add tags

In order for the adaptive runtime and package manager to correctly install a package, it must be tagged appropriately. All packages published to a public feed must be tagged with msbot-component to be displayed correctly in package manager.

Additionally, tag the package with one or more of the tags below depending on its contents.

  • msbot-content
  • msbot-middleware
  • msbot-action
  • msbot-trigger
  • msbot-adapter

Create and publish a NuGet package

This section shows an example of creating and publishing a package. The example uses the DialogAndTriggerPackage C# sample and dotnet CLI to create a NuGet package.

Create your package

  1. Open a command prompt and clone the Bot Framework Samples repository, and change into the correct folder.

    git clone https://github.com/microsoft/BotBuilder-Samples.git
    
    cd BotBuilder-Samples/composer-samples/csharp_dotnetcore/packages/DialogAndTriggerPackage
    
  2. Create your package.

    dotnet pack
    
  3. Verify the package was created in the /bin/debug folder.

Publishing your package

You can publish your package to a local feed, or to a hosted feed (private or public). This walkthrough creates a local feed and adds the package to it.

From a command prompt in the /bin/debug folder:

nuget add ".\Microsoft.Bot.Components.Samples.DialogAndTriggerPackage.1.0.0.nupkg" -Source "c:\someplace\feed"

This creates a new folder, instantiates a local NuGet feed in that folder, and adds the package to it.

Note

Make sure the package version is updated with each package and publish iteration. NuGet will behave unexpectedly if the package is republished with the same version.

Test the package in Composer

  1. Open a bot in Composer to test the package against. Alternatively, create a new Empty Bot for testing.

  2. In the navigation pane select Package manager, then select Edit feeds, in the right pane.

  3. In the popup window, at the bottom, select Add a new feed.

  4. Assign a name to the feed, select NuGet in the Type drop-down, and assign the location of your feed in the URL field - c:\someplace\feed (the -Source argument used previously).

  5. Select Done

  6. Back in package manager, from the drop-down list in the selection box, select the newly added feed. The package Microsoft.Bot.Components.Samples.DialogAndTriggerPackage will be listed.

  7. Select the package, and then Install.

Additional information

Next steps