<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/from-dotnet-run-to-foundry-hosted-agent-in-3-lines-of-c--hzr3e26yx" -->

---
title: From dotnet run to Foundry Hosted Agent in 3 lines of C#
description: Microsoft Foundry Hosted Agents let developers deploy an existing Microsoft Agent Framework console app to Azure with just one NuGet package...
canonical: https://daily.dev/posts/from-dotnet-run-to-foundry-hosted-agent-in-3-lines-of-c--hzr3e26yx
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: From dotnet run to Foundry Hosted Agent in 3 lines of C# | daily.dev
og:description: Microsoft Foundry Hosted Agents let developers deploy an existing Microsoft Agent Framework console app to Azure with just one NuGet package...
og:url: https://daily.dev/posts/from-dotnet-run-to-foundry-hosted-agent-in-3-lines-of-c--hzr3e26yx
og:image: https://api.daily.dev/og/posts/Hzr3E26yx.png
og:image:alt: From dotnet run to Foundry Hosted Agent in 3 lines of C#
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# From dotnet run to Foundry Hosted Agent in 3 lines of C#

**[.NET Blog](https://daily.dev/sources/dotnet)** · 9 min read · 2 upvotes · 0 comments

## Summary

Microsoft Foundry Hosted Agents let developers deploy an existing Microsoft Agent Framework console app to Azure with just one NuGet package (Microsoft.Agents.AI.Foundry.Hosting), three lines of C# code, and two azd commands (azd provision, azd deploy). The managed hosting layer handles compute scaling, session state, a dedicated Microsoft Entra identity, an OpenAI-compatible /responses endpoint, telemetry via Application Insights, agent evaluators, and immutable versioning for rollbacks. The post walks through testing locally with azd ai agent run/invoke, then shipping to production, plus a VS Code extension (Microsoft Foundry Toolkit) that automates scaffolding, debugging, and deployment. Hosted Agents is now generally available.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://devblogs.microsoft.com/dotnet/from-dotnet-run-to-foundry-hosted-agent-in-3-lines-of-csharp>

## Questions this post answers

### How do I deploy a Microsoft Agent Framework console agent to Foundry Hosted Agents?

Add the Microsoft.Agents.AI.Foundry.Hosting NuGet package (with --prerelease), then add three lines of C#: AgentHost.CreateBuilder(args), builder.Services.AddFoundryResponses(agent), and builder.RegisterProtocol("responses", endpoints => endpoints.MapFoundryResponses()). Test locally with azd ai agent run, then deploy with azd provision followed by azd deploy.

_Track hands-on walkthroughs like this one for shipping agent deployments on daily.dev._

### What does Foundry Hosted Agents provide automatically after deployment?

Deployed agents get a dedicated endpoint at {project_endpoint}/agents/{name}/endpoint/protocols/openai/responses, a dedicated Microsoft Entra ID for runtime authentication, managed compute that scales to zero when idle, persistent session state across turns, and automatic OpenTelemetry traces visible in Application Insights, without writing storage, identity, or telemetry code.

_Developers evaluating managed agent hosting can follow this kind of infrastructure breakdown on daily.dev._

### How can I deploy a hosted agent from Visual Studio Code without using Docker directly?

Install the Microsoft Foundry Toolkit VS Code extension, use the Command Palette command Foundry Toolkit: Create new Hosted Agent to scaffold the project, press F5 to run locally with a debugger and the Agent Inspector, then use Foundry Toolkit: Deploy Hosted Agent to build the container image, register the version, and assign RBAC roles. A Code ZIP deployment option skips Dockerfiles entirely.

_Anyone comparing agent deployment workflows can keep up with tooling updates like this on daily.dev._

## Similar posts on daily.dev

- [Jaliya's Blog: Microsoft Agent Framework: Hosted Agents in Microsoft Foundry with .NET](https://daily.dev/posts/jaliya-s-blog-microsoft-agent-framework-hosted-agents-in-microsoft-foundry-with-net-dqon0i46y) · We Are .NET · 1 upvotes · 0 comments
- [From Local to Production: Deploy Your Microsoft Agent Framework Agent with Foundry Hosted Agents](https://daily.dev/posts/from-local-to-production-deploy-your-microsoft-agent-framework-agent-with-foundry-hosted-agents-xrsxs4zxt) · DevBlogs · 1 upvotes · 0 comments
- [Building AI apps and agents with Microsoft Foundry](https://daily.dev/posts/building-ai-apps-and-agents-with-microsoft-foundry-tdq7h47dl) · InfoWorld · 0 upvotes · 0 comments
- [From code to cloud: Deploy an AI agent to Microsoft Foundry in minutes with azd](https://daily.dev/posts/from-code-to-cloud-deploy-an-ai-agent-to-microsoft-foundry-in-minutes-with-azd-68bdbsc0i) · DevBlogs · 1 upvotes · 0 comments

---

Tags: [#ai-agents](https://daily.dev/tags/ai-agents), [#azure](https://daily.dev/tags/azure), [#.net](https://daily.dev/tags/.net), [#c#](https://daily.dev/tags/c#)

[View this post on daily.dev](https://daily.dev/posts/from-dotnet-run-to-foundry-hosted-agent-in-3-lines-of-c--hzr3e26yx)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"From dotnet run to Foundry Hosted Agent in 3 lines of C#","url":"https://daily.dev/posts/from-dotnet-run-to-foundry-hosted-agent-in-3-lines-of-c--hzr3e26yx","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/from-dotnet-run-to-foundry-hosted-agent-in-3-lines-of-c--hzr3e26yx"},"datePublished":"2026-08-24T19:00:56.343Z","dateModified":"2026-09-14T07:18:47.694Z","description":"Microsoft Foundry Hosted Agents let developers deploy an existing Microsoft Agent Framework console app to Azure with just one NuGet package...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/710114eca4223d59989528be6eef9643?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/710114eca4223d59989528be6eef9643?_a=AQAEuop","isAccessibleForFree":true,"articleSection":".NET Blog","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":".NET Blog","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/f23eb59371bd4f07aeef64c4eef73266","url":"https://daily.dev/sources/dotnet"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/from-dotnet-run-to-foundry-hosted-agent-in-3-lines-of-c--hzr3e26yx","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":2},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"ai-agents,azure,.net,c#","timeRequired":"PT9M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":".NET Blog","item":"https://daily.dev/sources/dotnet"},{"@type":"ListItem","position":3,"name":"From dotnet run to Foundry Hosted Agent in 3 lines of C#"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/from-dotnet-run-to-foundry-hosted-agent-in-3-lines-of-c--hzr3e26yx#faq","mainEntity":[{"@type":"Question","name":"How do I deploy a Microsoft Agent Framework console agent to Foundry Hosted Agents?","acceptedAnswer":{"@type":"Answer","text":"Add the Microsoft.Agents.AI.Foundry.Hosting NuGet package (with --prerelease), then add three lines of C#: AgentHost.CreateBuilder(args), builder.Services.AddFoundryResponses(agent), and builder.RegisterProtocol(\"responses\", endpoints => endpoints.MapFoundryResponses()). Test locally with azd ai agent run, then deploy with azd provision followed by azd deploy. Track hands-on walkthroughs like this one for shipping agent deployments on daily.dev."}},{"@type":"Question","name":"What does Foundry Hosted Agents provide automatically after deployment?","acceptedAnswer":{"@type":"Answer","text":"Deployed agents get a dedicated endpoint at {project_endpoint}/agents/{name}/endpoint/protocols/openai/responses, a dedicated Microsoft Entra ID for runtime authentication, managed compute that scales to zero when idle, persistent session state across turns, and automatic OpenTelemetry traces visible in Application Insights, without writing storage, identity, or telemetry code. Developers evaluating managed agent hosting can follow this kind of infrastructure breakdown on daily.dev."}},{"@type":"Question","name":"How can I deploy a hosted agent from Visual Studio Code without using Docker directly?","acceptedAnswer":{"@type":"Answer","text":"Install the Microsoft Foundry Toolkit VS Code extension, use the Command Palette command Foundry Toolkit: Create new Hosted Agent to scaffold the project, press F5 to run locally with a debugger and the Agent Inspector, then use Foundry Toolkit: Deploy Hosted Agent to build the container image, register the version, and assign RBAC roles. A Code ZIP deployment option skips Dockerfiles entirely. Anyone comparing agent deployment workflows can keep up with tooling updates like this on daily.dev."}}]}
```

