Visitar URL original
Add a new Microsoft.Agents.AI.Templates package with an aiagent-webapi project template by jeffhandley · Pull Request #7014 · dotnet/extensions · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
fb18d16
Initial Microsoft.Agents.AI.Templates structure
jeffhandley Nov 5, 2025
577cf99
Refine Microsoft.Agents.AI.Templates infrastructure
jeffhandley Nov 5, 2025
785d8fd
Move project template infrastructure utilities into a shared folder
jeffhandley Nov 5, 2025
d293cc1
Add the webapi-agents project template content with GitHub models
jeffhandley Nov 5, 2025
0b077ed
Support parameterized AI Service Provider
jeffhandley Nov 5, 2025
457c817
Rename to aiagents-webapi
jeffhandley Nov 5, 2025
c8f72a6
Support parameterized chatmodel and update docs with renames
jeffhandley Nov 5, 2025
9d3fced
Add Snapshot tests
jeffhandley Nov 5, 2025
78d399f
Add aiagents-webapi snapshot tests
jeffhandley Nov 5, 2025
94a1d1f
Add aiagents-webapi execution tests (and component governance)
jeffhandley Nov 5, 2025
d28616a
Improve aiagents-webapi template parameters
jeffhandley Nov 5, 2025
0422af7
Apply suggestions from copilot code review
jeffhandley Nov 5, 2025
8f6e573
Move shared ProjectTemplate infrastructure to not get included in Sha…
jeffhandley Nov 5, 2025
4f3e89b
Fix the template sandbox / execution tests after moving infrastructure
jeffhandley Nov 5, 2025
6d85d1d
Ignore CA1716 warning about 'Shared' namespace in template tests
jeffhandley Nov 5, 2025
650fbfb
Clean up template sandbox source/output
jeffhandley Nov 5, 2025
36f45f1
Rename to "aiagent-webapi" and favor singular "Agent". Docs cleanup.
jeffhandley Nov 5, 2025
0fa70aa
Update templates dev doc to cover Microsoft.Agents.AI.Templates too
jeffhandley Nov 5, 2025
e02675a
Fix remaining template sandbox references with new paths
jeffhandley Nov 6, 2025
5640da3
Add a tool call in aiagent-webapi. Update workflow API usage for upco…
jeffhandley Nov 6, 2025
7327c81
Exclude csproj.in file from template package
jeffhandley Nov 6, 2025
19b1d12
Add a survey link to the aiagent-webapi template's generated readme
jeffhandley Nov 6, 2025
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
Next Next commit
Initial Microsoft.Agents.AI.Templates structure
  • Loading branch information
jeffhandley committed Nov 5, 2025
commit fb18d165c747a5248c004d098ff553072f6976b5
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<PackageType>Template</PackageType>
<TargetFrameworks>$(NetCoreTargetFrameworks)</TargetFrameworks>
<Description>Project templates for Microsoft.Agents.AI.</Description>
<PackageTags>dotnet-new;templates;agents;ai</PackageTags>

<Stage>preview</Stage>
<PreReleaseVersionIteration>1</PreReleaseVersionIteration>
<Workstream>AI</Workstream>
<MinCodeCoverage>0</MinCodeCoverage>
<MinMutationScore>0</MinMutationScore>

<IsPackable>true</IsPackable>
<IsProjectReferenceProvider>false</IsProjectReferenceProvider>
<IncludeContentInPack>true</IncludeContentInPack>
<IncludeBuildOutput>false</IncludeBuildOutput>
<IncludeSymbols>false</IncludeSymbols>
<ContentTargetFolders>content</ContentTargetFolders>
<EnableDefaultItems>false</EnableDefaultItems>
<NoDefaultExcludes>true</NoDefaultExcludes>
<NoPackageAnalysis>true</NoPackageAnalysis>
</PropertyGroup>

<ItemGroup>
<!--
Reference the GenerateTemplateContent project so that template content gets generated prior
to building this project.
-->
<ProjectReference
Include="..\GenerateTemplateContent\GenerateTemplateContent.csproj"
ReferenceOutputAssembly="false"
PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
<!-- Template content will be added here once actual templates are implemented -->
<None Include="THIRD-PARTY-NOTICES.TXT" Pack="true" PackagePath="." />
<Compile Remove="**\*" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
# Microsoft.Agents.AI.Templates Project Structure

This document describes the newly created `Microsoft.Agents.AI.Templates` project structure and infrastructure.

## Project Overview

The `Microsoft.Agents.AI.Templates` project is a .NET project template package designed to provide project templates for Microsoft.Agents.AI applications. It follows the same structure and infrastructure as `Microsoft.Extensions.AI.Templates`.

## Project Structure

### Source Project
**Location**: `src/ProjectTemplates/Microsoft.Agents.AI.Templates/`

**Key Files**:
- `Microsoft.Agents.AI.Templates.csproj` - The template package project file
- `THIRD-PARTY-NOTICES.TXT` - Third-party license notices (currently a placeholder)

**Configuration**:
- Package type: `Template`
- Target frameworks: `$(NetCoreTargetFrameworks)` (net8.0, net9.0, net10.0)
- Description: "Project templates for Microsoft.Agents.AI."
- Package tags: `dotnet-new;templates;agents;ai`
- Workstream: AI
- Stage: preview
- PreReleaseVersionIteration: 1

**Project References**:
- References `GenerateTemplateContent` project to ensure template content is generated before building

**Content Items**:
- Template content will be added to the `<Content>` ItemGroup once actual templates are implemented
- Currently includes only `THIRD-PARTY-NOTICES.TXT`

### Test Project
**Location**: `test/ProjectTemplates/Microsoft.Agents.AI.Templates.IntegrationTests/`

**Key Files**:
- `Microsoft.Agents.AI.Templates.Tests.csproj` - The integration test project
- `README.md` - Documentation for running and updating template tests
- `AgentTemplateSnapshotTests.cs` - Placeholder snapshot test class (test is skipped until template content is added)
- `ProjectRootHelper.cs` - Helper to locate the test project root
- `VerifyScrubbers.cs` - Utilities for scrubbing variable content from test snapshots

**Infrastructure Files** (in `Infrastructure/` subdirectory):
- `WellKnownPaths.cs` - Constants for important paths (repo root, template feed location, sandbox paths, etc.)
- `TestCommand.cs` - Base class for executing commands during tests
- `DotNetCommand.cs` - Specialized command for executing dotnet CLI commands
- `TestCommandResult.cs` - Result data from command execution
- `ProcessExtensions.cs` - Extension methods for working with processes

**Test Support Directories**:

1. **TemplateSandbox/** - For manual template testing and debugging
- `.editorconfig` - Prevents repo settings from applying to generated templates
- `.gitignore` - Ignores the `output/` directory
- `activate.ps1` - PowerShell script to set up environment for manual template testing
- `README.md` - Instructions for debugging templates manually

2. **Snapshots/** - For verified template output snapshots
- `README.md` - Documentation about snapshot testing
- Subdirectories for each test scenario will be added when templates are implemented

**Configuration**:
- Project type: Integration Test (`IsIntegrationTestProject = true`)
- Suppressed warnings: CA1063, CA1861, CA2201, VSTHRD003, S104, S125, S2699

**Package References**:
- `Microsoft.TemplateEngine.Authoring.TemplateVerifier` - For template verification
- `Microsoft.TemplateEngine.TestHelper` - For template testing utilities

**Project References**:
- `TestUtilities` - Common test utilities

## Next Steps

When actual template content is ready to be added:

1. **Create Template Directory Structure**:
- Create template directories under `src/ProjectTemplates/Microsoft.Agents.AI.Templates/src/`
- Each template should have a `.template.config/` directory with a `template.json` file

2. **Update Source Project**:
- Add `<Content>` items to the `.csproj` file for the new template directories
- Define exclusion patterns to match the template structure
- Update `THIRD-PARTY-NOTICES.TXT` if the templates use third-party libraries

3. **Add Template Tests**:
- Remove the `Skip` attribute from tests in `AgentTemplateSnapshotTests.cs`
- Add new test methods for different template configurations
- Update the `_verificationExcludePatterns` array to match template output patterns
- Update the template location and short name in test methods

4. **Generate Snapshots**:
- Run the tests to generate initial snapshots
- Use `DiffEngineTray` to review and accept the generated snapshots

5. **Add Execution Tests** (optional):
- Create an `AgentTemplateExecutionTests.cs` file similar to `AIChatWebExecutionTests.cs` if you want to test that generated templates compile and run

## Integration with Build System

The project uses the `GenerateTemplateContent` approach for generating template content, which is consistent with other template projects in the repository.

The test infrastructure is designed to:
- Use the locally built .NET SDK from the repository
- Reference locally built NuGet packages
- Support debugging through the TemplateSandbox directory
- Verify template output matches expected snapshots

## Validation

All created files have been validated:
- Projects compile successfully
- No build errors or warnings
- Infrastructure follows repository conventions
- Namespace consistency (`Microsoft.Agents.AI.Templates.Tests`)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.NET Core uses third-party libraries or other resources that may be
distributed under licenses different than the .NET Core software.

In the event that we accidentally failed to list a required notice, please
bring it to our attention. Post an issue or email us:

dotnet@microsoft.com

The attached notices are provided for information only.
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Microsoft.TemplateEngine.Authoring.TemplateVerifier;
using Microsoft.TemplateEngine.TestHelper;
using Xunit;
using Xunit.Abstractions;

namespace Microsoft.Agents.AI.Templates.Tests;

public class AgentTemplateSnapshotTests
{
// Exclude patterns will be defined here when actual template content is added.
private static readonly string[] _verificationExcludePatterns = [
"**/bin/**",
"**/obj/**",
"**/.vs/**",
"**/node_modules/**",
"**/*.user",
"**/NuGet.config",
"**/Directory.Build.targets",
"**/Directory.Build.props",
];

private readonly ILogger _log;

public AgentTemplateSnapshotTests(ITestOutputHelper log)
{
#pragma warning disable CA2000 // Dispose objects before losing scope
_log = new XunitLoggerProvider(log).CreateLogger("TestRun");
#pragma warning restore CA2000 // Dispose objects before losing scope
}

// Placeholder test - actual template tests will be added when template content is implemented
[Fact(Skip = "Template content not yet implemented")]
public async Task BasicTest()
{
await TestTemplateCoreAsync(scenarioName: "Basic");
}

private async Task TestTemplateCoreAsync(string scenarioName, IEnumerable<string>? templateArgs = null)
{
string workingDir = TestUtils.CreateTemporaryFolder();
string templateShortName = "agentapp"; // Placeholder - will be updated with actual template short name

// Get the template location - will be updated when actual template is implemented
string templateLocation = Path.Combine(WellKnownPaths.TemplateFeedLocation, "Microsoft.Agents.AI.Templates", "src", "PlaceholderTemplate");

var verificationExcludePatterns = Path.DirectorySeparatorChar is '/'
? _verificationExcludePatterns
: _verificationExcludePatterns.Select(p => p.Replace('/', Path.DirectorySeparatorChar)).ToArray();

TemplateVerifierOptions options = new TemplateVerifierOptions(templateName: templateShortName)
{
TemplatePath = templateLocation,
TemplateSpecificArgs = templateArgs,
SnapshotsDirectory = "Snapshots",
OutputDirectory = workingDir,
DoNotPrependCallerMethodNameToScenarioName = true,
DoNotAppendTemplateArgsToScenarioName = true,
ScenarioName = scenarioName,
VerificationExcludePatterns = verificationExcludePatterns,
}
.WithCustomScrubbers(
ScrubbersDefinition.Empty.AddScrubber((path, content) =>
{
string filePath = path.UnixifyDirSeparators();
if (filePath.EndsWith(".sln"))
{
// Scrub .sln file GUIDs.
content.ScrubByRegex(pattern: @"\{.{36}\}", replacement: "{00000000-0000-0000-0000-000000000000}");
}

if (filePath.EndsWith(".csproj"))
{
content.ScrubByRegex("<UserSecretsId>(.*)<\\/UserSecretsId>", "<UserSecretsId>secret</UserSecretsId>");

// Scrub references to just-built packages and remove the suffix, if it exists.
var pattern = @"(?<=<PackageReference\s+Include=""Microsoft\..*""\s+Version="")(\d+\.\d+\.\d+)(?:-[^""]*)?(?=""\s*/>)";
content.ScrubByRegex(pattern, replacement: "$1");
}

if (filePath.EndsWith("launchSettings.json"))
{
content.ScrubByRegex("(http(s?):\\/\\/localhost)\\:(\\d*)", "$1:9999");
}
}));

VerificationEngine engine = new VerificationEngine(_log);
await engine.Execute(options);

#pragma warning disable CA1031 // Do not catch general exception types
try
{
Directory.Delete(workingDir, recursive: true);
}
catch
{
/* don't care */
}
#pragma warning restore CA1031 // Do not catch general exception types
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;

namespace Microsoft.Agents.AI.Templates.Tests;

public class DotNetCommand : TestCommand
{
public DotNetCommand(params ReadOnlySpan<string> args)
{
FileName = WellKnownPaths.RepoDotNetExePath;

foreach (var arg in args)
{
Arguments.Add(arg);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace System.Diagnostics;

public static class ProcessExtensions
{
public static bool TryGetHasExited(this Process process)
{
try
{
return process.HasExited;
}
catch (InvalidOperationException ex) when (ex.Message.Contains("No process is associated with this object"))
{
return true;
}
}
}
Loading