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
2 changes: 1 addition & 1 deletion .github/prompts/error-consolidation.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Rework the highlighted section so the focus is on how to correct each error. Thi

## Verify error messages

For every line in this table, verify that the error message associated with this error code matches the verbatim text in CSharpResources.resx. You can find the mapping using ErrorCodes.cs:
For every line in this list, verify that the error message associated with this error code matches the verbatim text in CSharpResources.resx. You can find the mapping using ErrorCodes.cs:

1. Find that number as a constant in `ErrorCodes.cs`.
2. Locate the corresponding `data` element in CSharpResources.resx. The `name` atttribute should match the number of the constant.
Expand Down
2 changes: 1 addition & 1 deletion docs/azure/includes/dotnet-all.md
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@
| Common | NuGet [2.2.1](https://www.nuget.org/packages/Microsoft.Azure.Common/2.2.1) | | |
| Common - Dependencies | NuGet [1.0.0](https://www.nuget.org/packages/Microsoft.Azure.Common.Dependencies/1.0.0) | | |
| Computer Vision | NuGet [7.0.1](https://www.nuget.org/packages/Microsoft.Azure.CognitiveServices.Vision.ComputerVision/7.0.1) | | GitHub [7.0.1](https://github.com/Azure/azure-sdk-for-net/tree/Microsoft.Azure.CognitiveServices.Vision.ComputerVision_6.0.0-preview.1/sdk/cognitiveservices/Vision.ComputerVision) |
| Cosmos DB | NuGet [3.47.0](https://www.nuget.org/packages/Microsoft.Azure.Cosmos/3.47.0)<br>NuGet [3.56.0-preview.0](https://www.nuget.org/packages/Microsoft.Azure.Cosmos/3.56.0-preview.0) | [docs](/dotnet/api/overview/azure/cosmosdb) | GitHub [3.47.0](https://github.com/Azure/azure-cosmos-dotnet-v3/tree/3.12.0/Microsoft.Azure.Cosmos) |
| Cosmos DB | NuGet [3.47.0](https://www.nuget.org/packages/Microsoft.Azure.Cosmos/3.47.0)<br>NuGet [3.57.0-preview.0](https://www.nuget.org/packages/Microsoft.Azure.Cosmos/3.57.0-preview.0) | [docs](/dotnet/api/overview/azure/cosmosdb) | GitHub [3.47.0](https://github.com/Azure/azure-cosmos-dotnet-v3/tree/3.12.0/Microsoft.Azure.Cosmos) |
| Custom Vision Prediction | NuGet [2.0.0](https://www.nuget.org/packages/Microsoft.Azure.CognitiveServices.Vision.CustomVision.Prediction/2.0.0) | | GitHub [2.0.0](https://github.com/Azure/azure-sdk-for-net/tree/Microsoft.Azure.CognitiveServices.Vision.CustomVision.Prediction_2.0.0/sdk/cognitiveservices/Vision.CustomVision.Prediction) |
| Custom Vision Training | NuGet [2.0.0](https://www.nuget.org/packages/Microsoft.Azure.CognitiveServices.Vision.CustomVision.Training/2.0.0)<br>NuGet [2.1.0-preview](https://www.nuget.org/packages/Microsoft.Azure.CognitiveServices.Vision.CustomVision.Training/2.1.0-preview) | | GitHub [2.0.0](https://github.com/Azure/azure-sdk-for-net/tree/Microsoft.Azure.CognitiveServices.Vision.CustomVision.Training_2.0.0/sdk/cognitiveservices/Vision.CustomVision.Training) |
| Data Lake Analytics | NuGet [1.4.211011](https://www.nuget.org/packages/Microsoft.Azure.DataLake.USQL.SDK/1.4.211011) | | |
Expand Down
36 changes: 34 additions & 2 deletions docs/azure/sdk/authentication/local-development-dev-accounts.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: Authenticate .NET apps to Azure using developer accounts
description: Learn how to authenticate your application to Azure services when using the Azure SDK for .NET during local development using developer accounts.
ms.topic: how-to
ms.date: 03/14/2025
ms.date: 11/25/2025
ms.custom:
- devx-track-dotnet
- engagement-fy23
Expand Down Expand Up @@ -122,4 +122,36 @@ Connect-AzAccount -UseDeviceAuthentication

---

[!INCLUDE [Implement DefaultAzureCredential](<../includes/implement-defaultazurecredential.md>)]
## Authenticate to Azure services from your app

The [Azure Identity library](/dotnet/api/azure.identity?view=azure-dotnet&preserve-view=true) provides implementations of <xref:Azure.Core.TokenCredential> that support various scenarios and Microsoft Entra authentication flows. The steps ahead demonstrate how to use <xref:Azure.Identity.DefaultAzureCredential> or a specific development tool credential when working with user accounts locally.

### Implement the code

Complete the following steps:

1. Add references to the [Azure.Identity](https://www.nuget.org/packages/Azure.Identity) and the [Microsoft.Extensions.Azure](https://www.nuget.org/packages/Microsoft.Extensions.Azure) packages in your project:

```dotnetcli
dotnet add package Azure.Identity
dotnet add package Microsoft.Extensions.Azure
```

1. In `Program.cs`, add `using` directives for the `Azure.Identity` and `Microsoft.Extensions.Azure` namespaces.

1. Register the Azure service client using the corresponding `Add`-prefixed extension method.

Azure services are accessed using specialized client classes from the Azure SDK client libraries. Register these client types so you can access them through dependency injection across your app.

1. Pass a `TokenCredential` instance to the `UseCredential` method. Common `TokenCredential` examples include:

- A `DefaultAzureCredential` instance optimized for local development. This example sets environment variable `AZURE_TOKEN_CREDENTIALS` to `dev`. For more information, see [Exclude a credential type category](credential-chains.md#exclude-a-credential-type-category).

:::code language="csharp" source="../snippets/authentication/local-dev-account/Program.cs" id="snippet_DefaultAzureCredentialDev":::

- An instance of a credential corresponding to a specific development tool, such as `VisualStudioCredential`.

:::code language="csharp" source="../snippets/authentication/local-dev-account/Program.cs" id="snippet_VisualStudioCredential":::

> [!TIP]
> When your team uses multiple development tools to authenticate with Azure, prefer a local development-optimized instance of `DefaultAzureCredential` over tool-specific credentials.
43 changes: 0 additions & 43 deletions docs/azure/sdk/includes/implement-defaultazurecredential.md

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
<PackageVersion Include="Azure.AI.OpenAI" Version="2.1.0" />
<PackageVersion Include="Microsoft.Extensions.AI" Version="9.3.0-preview.1.25114.11" />
<PackageVersion Include="Microsoft.Extensions.AI.OpenAI" Version="9.3.0-preview.1.25114.11" />
<PackageVersion Include="Microsoft.Extensions.Azure" Version="1.13.0" />
<PackageVersion Include="Azure.Identity" Version="1.17.0" />
<PackageVersion Include="Azure.Identity.Broker" Version="1.3.0" />
<PackageVersion Include="Microsoft.Extensions.Azure" Version="1.13.1" />
<PackageVersion Include="Azure.Identity" Version="1.17.1" />
<PackageVersion Include="Azure.Identity.Broker" Version="1.3.1" />
<PackageVersion Include="Azure.Security.KeyVault.Secrets" Version="4.8.0" />
<PackageVersion Include="Azure.Storage.Blobs" Version="12.26.0" />
<!-- ASP.NET Core packages -->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
Expand Down
33 changes: 20 additions & 13 deletions docs/azure/sdk/snippets/authentication/local-dev-account/Program.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
using Azure.Identity;
using Microsoft.Extensions.Azure;
using Microsoft.Extensions.Azure;
using Azure.Storage.Blobs;
using Azure.Core;
using Azure.Identity;

var builder = WebApplication.CreateBuilder(args);

registerUsingServicePrincipal(builder);
registerUsingUserPrincipal(builder);

var app = builder.Build();

Expand Down Expand Up @@ -43,22 +42,30 @@

app.Run();

void registerUsingServicePrincipal(WebApplicationBuilder builder)
void registerUsingUserPrincipal(WebApplicationBuilder builder)
{
#region snippet_DefaultAzureCredential_UseCredential
#region snippet_VisualStudioCredential
builder.Services.AddAzureClients(clientBuilder =>
{
clientBuilder.AddBlobServiceClient(
new Uri("https://<account-name>.blob.core.windows.net"));

VisualStudioCredential credential = new();
clientBuilder.UseCredential(credential);
});
#endregion snippet_DefaultAzureCredential_UseCredential
#endregion snippet_VisualStudioCredential

#region snippet_DefaultAzureCredential
builder.Services.AddSingleton<BlobServiceClient>(_ =>
new BlobServiceClient(
new Uri("https://<account-name>.blob.core.windows.net"),
new DefaultAzureCredential()));
#endregion snippet_DefaultAzureCredential
#region snippet_DefaultAzureCredentialDev
builder.Services.AddAzureClients(clientBuilder =>
{
clientBuilder.AddBlobServiceClient(
new Uri("https://<account-name>.blob.core.windows.net"));

DefaultAzureCredential credential = new(
DefaultAzureCredential.DefaultEnvironmentVariableName);
clientBuilder.UseCredential(credential);
});
#endregion snippet_DefaultAzureCredentialDev
}

internal record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary)
Expand Down
138 changes: 138 additions & 0 deletions docs/core/tools/dotnet-project-convert.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
---
title: dotnet project convert command
description: The 'dotnet project convert' command converts a file-based program to a project-based program.
ms.date: 10/25/2025
ai-usage: ai-assisted
---
# dotnet project convert

**This article applies to:** ✔️ .NET 10 SDK and later versions

## Name

`dotnet project convert` - Converts a file-based program to a project-based program.

## Synopsis

```dotnetcli
dotnet project convert <FILE> [--dry-run] [--force] [--interactive]
[-o|--output <OUTPUT_DIRECTORY>]

dotnet project convert -h|--help
```

## Description

The `dotnet project convert` command converts a file-based program to a project-based program. This command creates a new directory named for your file, scaffolds a *.csproj* file, moves your code into a file with the same name as the input file, and translates any `#:` directives into MSBuild properties and references.

This makes the transition seamless, from a single file to a fully functional, buildable, and extensible project. When your file-based app grows in complexity, or you simply want the extra capabilities afforded in project-based apps, you can convert it to a standard project.

### Conversion process

The command performs the following operations:

1. Creates a new directory named after the input file (without extension).
2. Generates a *.csproj* file with appropriate SDK and properties.
3. Moves the source code to a file with the same name as the input file.
4. Removes `#:` directives from the source code.
5. Translates `#:sdk` directives: the first `#:sdk` directive becomes the `<Project Sdk="Sdk.Id">` or `<Project Sdk="Sdk.Id/version">` attribute, and any additional `#:sdk` directives become `<Sdk Name="Sdk.Id" />` or `<Sdk Name="Sdk.Id" Version="version" />` elements.
6. Translates `#:package` directives to `<PackageReference>` elements in the project file.
7. Translates `#:property` directives to MSBuild properties in the project file.
8. Sets appropriate MSBuild properties based on the SDK and framework detected.

## Arguments

- `FILE`

The path to the file-based program to convert. The file must be a C# source file (typically with a *.cs* extension).

## Options

- **`--dry-run`**

Determines changes without actually modifying the file system. Shows what would be created or modified without performing the conversion.

- **`--force`**

Forces conversion even if there are malformed directives. By default, the command fails if it encounters directives that cannot be properly parsed or converted.

- [!INCLUDE [interactive](../../../includes/cli-interactive.md)]

- **`-o|--output <OUTPUT_DIRECTORY>`**

Specifies the output directory for the converted project. If not specified, a directory is created with the same name as the input file (without extension) in the current directory.

- [!INCLUDE [help](../../../includes/cli-help.md)]

## Examples

- Convert a file-based program to a project:

```dotnetcli
dotnet project convert app.cs
```

Given a folder containing *app.cs* with the following content:

```csharp
#:sdk Microsoft.NET.Sdk.Web
#:package Microsoft.AspNetCore.OpenApi@10.*-*

var builder = WebApplication.CreateBuilder();

builder.Services.AddOpenApi();

var app = builder.Build();

app.MapGet("/", () => "Hello, world!");
app.Run();
```

Running `dotnet project convert app.cs` results in a folder called *app* containing:

*app/app.cs*:

```csharp
var builder = WebApplication.CreateBuilder();

builder.Services.AddOpenApi();

var app = builder.Build();

app.MapGet("/", () => "Hello, world!");
app.Run();
```

*app/app.csproj*:

```xml
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PublishAot>true</PublishAot>
<PackAsTool>true</PackAsTool>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.*-*" />
</ItemGroup>

</Project>
```

- Convert a file-based program to a project in a specific output directory:

```dotnetcli
dotnet project convert app.cs --output MyProject
```

## See also

- [dotnet build](dotnet-build.md)
- [dotnet run](dotnet-run.md)
- [dotnet publish](dotnet-publish.md)
- [Tutorial: Build file-based C# programs](../../csharp/fundamentals/tutorials/file-based-programs.md)
1 change: 1 addition & 0 deletions docs/core/tools/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ The following commands are installed by default:
- [`package remove`](dotnet-package-remove.md)
- [`package search`](dotnet-package-search.md)
- [`package update`](dotnet-package-update.md)
- [`project convert`](dotnet-project-convert.md) (Available since .NET 10 SDK)
- [`reference add`](dotnet-reference-add.md)
- [`reference list`](dotnet-reference-list.md)
- [`reference remove`](dotnet-reference-remove.md)
Expand Down
Loading
Loading