diff --git a/docs/ai/quickstarts/build-chat-app.md b/docs/ai/quickstarts/build-chat-app.md index 23cee375bda01..fa15f67858db4 100644 --- a/docs/ai/quickstarts/build-chat-app.md +++ b/docs/ai/quickstarts/build-chat-app.md @@ -1,6 +1,6 @@ --- title: Quickstart - Build an AI chat app with .NET -description: Create a simple AI powered chat app using Semantic Kernel SDK for .NET and the OpenAI or Azure OpenAI SDKs +description: Create a simple AI powered chat app using Microsoft.Extensions.AI and the OpenAI or Azure OpenAI SDKs ms.date: 04/09/2025 ms.topic: quickstart ms.custom: devx-track-dotnet, devx-track-dotnet-ai @@ -31,8 +31,6 @@ In this quickstart, you learn how to create a conversational .NET console chat a [!INCLUDE [semantic-kernel](includes/semantic-kernel.md)] -[!INCLUDE [clone-sample-repo](includes/clone-sample-repo.md)] - ## Create the app Complete the following steps to create a .NET console app to connect to an AI model. @@ -104,13 +102,13 @@ Complete the following steps to create a .NET console app to connect to an AI mo ## Add the app code -The app uses the [`Microsoft.Extensions.AI`](https://www.nuget.org/packages/Microsoft.Extensions.AI/) package to send and receive requests to the AI model and is designed to provide users with information about hiking trails. +This app uses the [`Microsoft.Extensions.AI`](https://www.nuget.org/packages/Microsoft.Extensions.AI/) package to send and receive requests to the AI model. The app provides users with information about hiking trails. -1. In the **Program.cs** file, add the following code to connect and authenticate to the AI model. +1. In the `Program.cs` file, add the following code to connect and authenticate to the AI model. :::zone target="docs" pivot="azure-openai" - :::code language="csharp" source="snippets/build-chat-app/azure-openai/program.cs" range="1-12"::: + :::code language="csharp" source="snippets/build-chat-app/azure-openai/program.cs" id="GetChatClient"::: > [!NOTE] > searches for authentication credentials from your local tooling. If you aren't using the `azd` template to provision the Azure OpenAI resource, you'll need to assign the `Azure AI Developer` role to the account you used to sign in to Visual Studio or the Azure CLI. For more information, see [Authenticate to Azure AI services with .NET](../azure-ai-services-authentication.md). @@ -119,17 +117,17 @@ The app uses the [`Microsoft.Extensions.AI`](https://www.nuget.org/packages/Micr :::zone target="docs" pivot="openai" - :::code language="csharp" source="snippets/build-chat-app/openai/program.cs" range="1-11"::: + :::code language="csharp" source="snippets/build-chat-app/openai/program.cs" id="GetChatClient"::: :::zone-end 1. Create a system prompt to provide the AI model with initial role context and instructions about hiking recommendations: - :::code language="csharp" source="snippets/build-chat-app/openai/program.cs" range="13-30"::: + :::code language="csharp" source="snippets/build-chat-app/openai/program.cs" id="FirstMessage"::: 1. Create a conversational loop that accepts an input prompt from the user, sends the prompt to the model, and prints the response completion: - :::code language="csharp" source="snippets/build-chat-app/openai/program.cs" range="32-51"::: + :::code language="csharp" source="snippets/build-chat-app/openai/program.cs" id="ChatLoop"::: 1. Use the `dotnet run` command to run the app: @@ -143,11 +141,10 @@ The app uses the [`Microsoft.Extensions.AI`](https://www.nuget.org/packages/Micr ## Clean up resources -When you no longer need the sample application or resources, remove the corresponding deployment and all resources. +If you no longer need them, delete the Azure OpenAI resource and GPT-4 model deployment. -```azdeveloper -azd down -``` +1. In the [Azure Portal](https://aka.ms/azureportal), navigate to the Azure OpenAI resource. +1. Select the Azure OpenAI resource, and then select **Delete**. :::zone-end diff --git a/docs/ai/quickstarts/build-vector-search-app.md b/docs/ai/quickstarts/build-vector-search-app.md index 70a469a21be4b..39c9823f066f4 100644 --- a/docs/ai/quickstarts/build-vector-search-app.md +++ b/docs/ai/quickstarts/build-vector-search-app.md @@ -26,8 +26,6 @@ In this quickstart, you create a .NET console app to perform semantic search on :::zone-end -[!INCLUDE [clone-sample-repo](includes/clone-sample-repo.md)] - ## Interact with your data using vector stores Vector stores or vector databases are essential for tasks like semantic search, Retrieval Augmented Generation (RAG), and other scenarios that require grounding generative AI responses. While relational databases and document databases are optimized for structured and semi-structured data, vector databases are built to efficiently store, index, and manage data represented as embedding vectors. As a result, the indexing and search algorithms used by vector databases are optimized to efficiently retrieve data that can be used downstream in your applications. @@ -171,7 +169,7 @@ Complete the following steps to create a .NET console app that can: :::zone target="docs" pivot="openai" - :::code language="csharp" source="snippets/chat-with-data/openai/program.cs" range="49-57"::: + :::code language="csharp" source="snippets/chat-with-data/openai/program.cs" id="EmbeddingGenerator"::: :::zone-end @@ -197,11 +195,10 @@ Complete the following steps to create a .NET console app that can: ## Clean up resources -When you no longer need the sample application or resources, remove the corresponding deployment and all resources. +If you no longer need them, delete the Azure OpenAI resource and GPT-4 model deployment. -```azdeveloper -azd down -``` +1. In the [Azure Portal](https://aka.ms/azureportal), navigate to the Azure OpenAI resource. +1. Select the Azure OpenAI resource, and then select **Delete**. :::zone-end diff --git a/docs/ai/quickstarts/chat-local-model.md b/docs/ai/quickstarts/chat-local-model.md index bc7ca0c11e373..94c4489987ce5 100644 --- a/docs/ai/quickstarts/chat-local-model.md +++ b/docs/ai/quickstarts/chat-local-model.md @@ -84,12 +84,12 @@ The Semantic Kernel SDK provides many services and features to connect to AI mod The preceding code accomplishes the following: - - Creates an `OllamaChatClient` that implements the `IChatClient` interface. - - This interface provides a loosely coupled abstraction you can use to chat with AI Models. - - You can later change the underlying chat client implementation to another model, such as Azure OpenAI, without changing any other code. - - Creates a `ChatHistory` object to store the messages between the user and the AI model. - - Retrieves a prompt from the user and stores it in the `ChatHistory`. - - Sends the chat data to the AI model to generate a response. + * Creates an `OllamaChatClient` that implements the `IChatClient` interface. + * This interface provides a loosely coupled abstraction you can use to chat with AI Models. + * You can later change the underlying chat client implementation to another model, such as Azure OpenAI, without changing any other code. + * Creates a `ChatHistory` object to store the messages between the user and the AI model. + * Retrieves a prompt from the user and stores it in the `ChatHistory`. + * Sends the chat data to the AI model to generate a response. > [!NOTE] > Ollama runs on port 11434 by default, which is why the AI model endpoint is set to `http://localhost:11434`. @@ -146,4 +146,4 @@ The Semantic Kernel SDK provides many services and features to connect to AI mod ## Next steps -- [Generate text and conversations with .NET and Azure OpenAI Completions](/training/modules/open-ai-dotnet-text-completions/) +* [Generate text and conversations with .NET and Azure OpenAI Completions](/training/modules/open-ai-dotnet-text-completions/) diff --git a/docs/ai/quickstarts/create-assistant.md b/docs/ai/quickstarts/create-assistant.md index a91f448eaad4f..4f0053c4846d5 100644 --- a/docs/ai/quickstarts/create-assistant.md +++ b/docs/ai/quickstarts/create-assistant.md @@ -107,27 +107,27 @@ Complete the following steps to create a .NET console app and add the package ne ## Create the AI assistant client -1. Open the _Program.cs_ file and replace the contents of the file with the following code to create the required clients: +1. Open the `Program.cs` file and replace the contents of the file with the following code to create the required clients: - :::code language="csharp" source="snippets/assistants/program.cs" range="0-17" ::: + :::code language="csharp" source="snippets/assistants/program.cs" id="CreateClient" ::: 1. Create an in-memory sample document and upload it to the `OpenAIFileClient`: - :::code language="csharp" source="snippets/assistants/program.cs" range="19-53" ::: + :::code language="csharp" source="snippets/assistants/program.cs" id="CreateDocument" ::: 1. Enable file search and code interpreter tooling capabilities via the `AssistantCreationOptions`: - :::code language="csharp" source="snippets/assistants/program.cs" range="55-78" ::: + :::code language="csharp" source="snippets/assistants/program.cs" id="EnableTools" ::: 1. Create the `Assistant` and a thread to manage interactions between the user and the assistant: - :::code language="csharp" source="snippets/assistants/program.cs" range="80-105" ::: + :::code language="csharp" source="snippets/assistants/program.cs" id="CreateAssistant" ::: 1. Print the messages and save the generated image from the conversation with the assistant: - :::code language="csharp" source="snippets/assistants/program.cs" range="107-147" ::: + :::code language="csharp" source="snippets/assistants/program.cs" id="ProcessMessages" ::: - Locate and open the saved image in the app *bin* directory, which should resemble the following: + Locate and open the saved image in the app `bin` directory, which should resemble the following: :::image type="content" source="../media/assistants/generated-sales-graph.png" alt-text="A graph showing the visualization generated by the AI model."::: diff --git a/docs/ai/quickstarts/evaluate-ai-response.md b/docs/ai/quickstarts/evaluate-ai-response.md index 7373ac005f6b9..e515cc9b7caff 100644 --- a/docs/ai/quickstarts/evaluate-ai-response.md +++ b/docs/ai/quickstarts/evaluate-ai-response.md @@ -96,6 +96,13 @@ Complete the following steps to create an MSTest project that connects to the `g Run the test using your preferred test workflow, for example, by using the CLI command `dotnet test` or through [Test Explorer](/visualstudio/test/run-unit-tests-with-test-explorer). +## Clean up resources + +If you no longer need them, delete the Azure OpenAI resource and GPT-4 model deployment. + +1. In the [Azure Portal](https://aka.ms/azureportal), navigate to the Azure OpenAI resource. +1. Select the Azure OpenAI resource, and then select **Delete**. + ## Next steps - Evaluate the responses from different OpenAI models. diff --git a/docs/ai/quickstarts/generate-images.md b/docs/ai/quickstarts/generate-images.md index 523948bb2bc94..14dc00733ea6e 100644 --- a/docs/ai/quickstarts/generate-images.md +++ b/docs/ai/quickstarts/generate-images.md @@ -28,8 +28,6 @@ In this quickstart, you learn how to create a .NET console app to generate image [!INCLUDE [semantic-kernel](includes/semantic-kernel.md)] -[!INCLUDE [clone-sample-repo](includes/clone-sample-repo.md)] - ## Create the app Complete the following steps to create a .NET console app to connect to an AI model. @@ -134,11 +132,10 @@ Complete the following steps to create a .NET console app to connect to an AI mo ## Clean up resources -When you no longer need the sample application or resources, remove the corresponding deployment and all resources. +If you no longer need them, delete the Azure OpenAI resource and GPT-4 model deployment. -```azdeveloper -azd down -``` +1. In the [Azure Portal](https://aka.ms/azureportal), navigate to the Azure OpenAI resource. +1. Select the Azure OpenAI resource, and then select **Delete**. :::zone-end diff --git a/docs/ai/quickstarts/includes/clone-sample-repo.md b/docs/ai/quickstarts/includes/clone-sample-repo.md deleted file mode 100644 index f32ffcae527e2..0000000000000 --- a/docs/ai/quickstarts/includes/clone-sample-repo.md +++ /dev/null @@ -1,14 +0,0 @@ ---- -author: jmatthiesen -ms.author: jomatthi -ms.date: 07/03/2024 -ms.topic: include ---- - -## (Optional) Clone the sample repository - -You can create your own app using the steps in the sections ahead, or you can clone the GitHub repository that contains the completed sample apps for all of the quickstarts. If you plan to use Azure OpenAI, the sample repo is also structured as an Azure Developer CLI template that can provision an Azure OpenAI resource for you. - -```bash -git clone https://github.com/dotnet/ai-samples.git -``` diff --git a/docs/ai/quickstarts/includes/create-ai-service.md b/docs/ai/quickstarts/includes/create-ai-service.md index c1d7cdcac7a95..f80d2af925333 100644 --- a/docs/ai/quickstarts/includes/create-ai-service.md +++ b/docs/ai/quickstarts/includes/create-ai-service.md @@ -1,7 +1,5 @@ ## Create the AI service -# [Azure Portal or Azure CLI](#tab/azure-cli) - 1. To provision an Azure OpenAI service and model, complete the steps in the [Create and deploy an Azure OpenAI Service resource](/azure/ai-services/openai/how-to/create-resource) article. 1. From a terminal or command prompt, navigate to the root of your project directory. @@ -13,9 +11,3 @@ dotnet user-secrets set AZURE_OPENAI_ENDPOINT dotnet user-secrets set AZURE_OPENAI_GPT_NAME ``` - -# [Azure Developer CLI](#tab/azd) - -[!INCLUDE [deploy-azd](deploy-azd.md)] - ---- diff --git a/docs/ai/quickstarts/includes/deploy-azd.md b/docs/ai/quickstarts/includes/deploy-azd.md deleted file mode 100644 index 8c9e87040603c..0000000000000 --- a/docs/ai/quickstarts/includes/deploy-azd.md +++ /dev/null @@ -1,17 +0,0 @@ ---- -author: jmatthiesen -ms.author: jomatthi -ms.date: 07/03/2024 -ms.topic: include ---- - -The sample GitHub repository is structured as an Azure Developer CLI (`azd`) template, which `azd` can use to provision the Azure OpenAI service and model for you. - -1. From a terminal or command prompt, navigate to the `src\quickstarts\azure-openai` directory of the sample repo. -1. Run the `azd up` command to provision the Azure OpenAI resources. It might take several minutes to create the Azure OpenAI service and deploy the model. - - ```azdeveloper - azd up - ``` - - `azd` also configures the required user secrets for the sample app, such as the Azure OpenAI endpoint and model name. diff --git a/docs/ai/quickstarts/prompt-model.md b/docs/ai/quickstarts/prompt-model.md index 91ad6212bab08..0e171a3245960 100644 --- a/docs/ai/quickstarts/prompt-model.md +++ b/docs/ai/quickstarts/prompt-model.md @@ -31,8 +31,6 @@ In this quickstart, you learn how to create a .NET console chat app to connect t [!INCLUDE [semantic-kernel](includes/semantic-kernel.md)] -[!INCLUDE [clone-sample-repo](includes/clone-sample-repo.md)] - ## Create the app Complete the following steps to create a .NET console app to connect to an AI model. @@ -141,11 +139,10 @@ The app uses the [`Microsoft.Extensions.AI`](https://www.nuget.org/packages/Micr ## Clean up resources -When you no longer need the sample application or resources, remove the corresponding deployment and all resources. +If you no longer need them, delete the Azure OpenAI resource and GPT-4 model deployment. -```azdeveloper -azd down -``` +1. In the [Azure Portal](https://aka.ms/azureportal), navigate to the Azure OpenAI resource. +1. Select the Azure OpenAI resource, and then select **Delete**. :::zone-end diff --git a/docs/ai/quickstarts/snippets/assistants/Program.cs b/docs/ai/quickstarts/snippets/assistants/Program.cs index a07a79a4ff21f..9aa359ddf995f 100644 --- a/docs/ai/quickstarts/snippets/assistants/Program.cs +++ b/docs/ai/quickstarts/snippets/assistants/Program.cs @@ -1,4 +1,5 @@ -using OpenAI; +// +using OpenAI; using OpenAI.Assistants; using OpenAI.Files; using Azure.AI.OpenAI; @@ -15,7 +16,9 @@ #pragma warning disable OPENAI001 AssistantClient assistantClient = openAIClient.GetAssistantClient(); OpenAIFileClient fileClient = openAIClient.GetOpenAIFileClient(); +// +// // Create an in-memory document to upload to the file client using Stream document = BinaryData.FromBytes(""" { @@ -51,7 +54,9 @@ document, "monthly_sales.json", FileUploadPurpose.Assistants); +// +// // Configure the assistant options AssistantCreationOptions assistantOptions = new() { @@ -76,7 +81,9 @@ } }, }; +// +// // Create the assistant Assistant assistant = assistantClient.CreateAssistant("gpt-4o", assistantOptions); @@ -100,10 +107,13 @@ var messages = assistantClient.GetMessagesAsync( threadRun.ThreadId, new MessageCollectionOptions() - { + { Order = MessageCollectionOrder.Ascending }); +// +// +// Process the messages from the assistant await foreach (ThreadMessage message in messages) { // Print out the messages from the assistant @@ -144,4 +154,5 @@ } } Console.WriteLine(); -} \ No newline at end of file +} +// diff --git a/docs/ai/quickstarts/snippets/build-chat-app/azure-openai/Program.cs b/docs/ai/quickstarts/snippets/build-chat-app/azure-openai/Program.cs index eb552f0715ab8..1e482546971c5 100644 --- a/docs/ai/quickstarts/snippets/build-chat-app/azure-openai/Program.cs +++ b/docs/ai/quickstarts/snippets/build-chat-app/azure-openai/Program.cs @@ -3,6 +3,7 @@ using Azure.AI.OpenAI; using Azure.Identity; +// IConfigurationRoot config = new ConfigurationBuilder().AddUserSecrets().Build(); string endpoint = config["AZURE_OPENAI_ENDPOINT"]; string deployment = config["AZURE_OPENAI_GPT_NAME"]; @@ -11,7 +12,9 @@ new AzureOpenAIClient(new Uri(endpoint), new DefaultAzureCredential()) .GetChatClient(deployment) .AsIChatClient(); +// +// // Start the conversation with context for the AI model List chatHistory = [ @@ -30,7 +33,9 @@ the local nature on the hikes when making a recommendation. At the end of your response, ask if there is anything else you can help with. """) ]; +// +// while (true) { // Get user prompt and add to chat history @@ -50,3 +55,4 @@ the local nature on the hikes when making a recommendation. At the end of your chatHistory.Add(new ChatMessage(ChatRole.Assistant, response)); Console.WriteLine(); } +// diff --git a/docs/ai/quickstarts/snippets/build-chat-app/openai/Program.cs b/docs/ai/quickstarts/snippets/build-chat-app/openai/Program.cs index 81108f8da5feb..3fc36782e7ee9 100644 --- a/docs/ai/quickstarts/snippets/build-chat-app/openai/Program.cs +++ b/docs/ai/quickstarts/snippets/build-chat-app/openai/Program.cs @@ -2,6 +2,7 @@ using Microsoft.Extensions.AI; using OpenAI; +// var config = new ConfigurationBuilder().AddUserSecrets().Build(); string model = config["ModelName"]; string key = config["OpenAIKey"]; @@ -9,7 +10,9 @@ // Create the IChatClient IChatClient chatClient = new OpenAIClient(key).GetChatClient(model).AsIChatClient(); +// +// // Start the conversation with context for the AI model List chatHistory = [ @@ -28,7 +31,10 @@ the local nature on the hikes when making a recommendation. At the end of your response, ask if there is anything else you can help with. """) ]; +// +// +// Loop to get user input and stream AI response while (true) { // Get user prompt and add to chat history @@ -48,3 +54,4 @@ the local nature on the hikes when making a recommendation. At the end of your chatHistory.Add(new ChatMessage(ChatRole.Assistant, response)); Console.WriteLine(); } +// diff --git a/docs/ai/quickstarts/snippets/chat-with-data/openai/Program.cs b/docs/ai/quickstarts/snippets/chat-with-data/openai/Program.cs index 042987331b192..21d7f98c26ee4 100644 --- a/docs/ai/quickstarts/snippets/chat-with-data/openai/Program.cs +++ b/docs/ai/quickstarts/snippets/chat-with-data/openai/Program.cs @@ -45,6 +45,7 @@ string model = config["ModelName"]; string key = config["OpenAIKey"]; +// // Create the embedding generator. IEmbeddingGenerator> generator = new OpenAIClient(new ApiKeyCredential(key)) @@ -55,6 +56,7 @@ var vectorStore = new InMemoryVectorStore(); IVectorStoreRecordCollection cloudServicesStore = vectorStore.GetCollection("cloudServices"); await cloudServicesStore.CreateCollectionIfNotExistsAsync(); +// foreach (CloudService service in cloudServices) { diff --git a/docs/ai/quickstarts/snippets/function-calling/azure-openai/Program.cs b/docs/ai/quickstarts/snippets/function-calling/azure-openai/Program.cs index d3080e4b5626e..a8d3a53750ed0 100644 --- a/docs/ai/quickstarts/snippets/function-calling/azure-openai/Program.cs +++ b/docs/ai/quickstarts/snippets/function-calling/azure-openai/Program.cs @@ -1,4 +1,5 @@ -using Microsoft.Extensions.Configuration; +// +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.AI; using Azure.AI.OpenAI; using Azure.Identity; @@ -13,6 +14,7 @@ .GetChatClient(deployment).AsIChatClient()) .UseFunctionInvocation() .Build(); +// // Add a new plugin with a local .NET function that should be available to the AI model var chatOptions = new ChatOptions diff --git a/docs/ai/quickstarts/snippets/function-calling/openai/Program.cs b/docs/ai/quickstarts/snippets/function-calling/openai/Program.cs index 57f1e6fb4f4b6..d515895d5c11c 100644 --- a/docs/ai/quickstarts/snippets/function-calling/openai/Program.cs +++ b/docs/ai/quickstarts/snippets/function-calling/openai/Program.cs @@ -1,4 +1,5 @@ -using Microsoft.Extensions.AI; +// +using Microsoft.Extensions.AI; using Microsoft.Extensions.Configuration; using OpenAI; @@ -10,7 +11,9 @@ new ChatClientBuilder(new OpenAIClient(key).GetChatClient(model ?? "gpt-4o").AsIChatClient()) .UseFunctionInvocation() .Build(); +// +// // Add a new plugin with a local .NET function // that should be available to the AI model. var chatOptions = new ChatOptions @@ -24,7 +27,9 @@ "get_current_weather", "Get the current weather in a given location")] }; +// +// // System prompt to provide context. List chatHistory = [new(ChatRole.System, """ You are a hiking enthusiast who helps people discover fun hikes in their area. You are upbeat and friendly. @@ -37,3 +42,4 @@ You are a hiking enthusiast who helps people discover fun hikes in their area. Y ChatResponse response = await client.GetResponseAsync(chatHistory, chatOptions); Console.WriteLine($"Assistant >>> {response.Text}"); +// diff --git a/docs/ai/quickstarts/structured-output.md b/docs/ai/quickstarts/structured-output.md index 117d23e0725f6..e4b9656ca1a1a 100644 --- a/docs/ai/quickstarts/structured-output.md +++ b/docs/ai/quickstarts/structured-output.md @@ -111,6 +111,13 @@ Complete the following steps to create a console app that connects to the `gpt-4 Sentiment: Neutral ``` +## Clean up resources + +If you no longer need them, delete the Azure OpenAI resource and GPT-4 model deployment. + +1. In the [Azure Portal](https://aka.ms/azureportal), navigate to the Azure OpenAI resource. +1. Select the Azure OpenAI resource, and then select **Delete**. + ## See also - [Structured outputs (Azure OpenAI Service)](/azure/ai-services/openai/how-to/structured-outputs) diff --git a/docs/ai/quickstarts/use-function-calling.md b/docs/ai/quickstarts/use-function-calling.md index 6f37aa0c7a995..31c7b2443a5bd 100644 --- a/docs/ai/quickstarts/use-function-calling.md +++ b/docs/ai/quickstarts/use-function-calling.md @@ -31,8 +31,6 @@ In this quickstart, you create a .NET console AI chat app to connect to an AI mo [!INCLUDE [semantic-kernel](includes/semantic-kernel.md)] -[!INCLUDE [clone-sample-repo](includes/clone-sample-repo.md)] - ## Create the app Complete the following steps to create a .NET console app to connect to an AI model. @@ -111,7 +109,7 @@ The app uses the [`Microsoft.Extensions.AI`](https://www.nuget.org/packages/Micr :::zone target="docs" pivot="azure-openai" - :::code language="csharp" source="snippets/function-calling/azure-openai/program.cs" range="1-16"::: + :::code language="csharp" source="snippets/function-calling/azure-openai/program.cs" id="GetChatClient"::: > [!NOTE] > searches for authentication credentials from your local tooling. If you aren't using the `azd` template to provision the Azure OpenAI resource, you'll need to assign the `Azure AI Developer` role to the account you used to sign in to Visual Studio or the Azure CLI. For more information, see [Authenticate to Azure AI services with .NET](../azure-ai-services-authentication.md). @@ -120,17 +118,17 @@ The app uses the [`Microsoft.Extensions.AI`](https://www.nuget.org/packages/Micr :::zone target="docs" pivot="openai" - :::code language="csharp" source="snippets/function-calling/openai/program.cs" range="1-14"::: + :::code language="csharp" source="snippets/function-calling/openai/program.cs" id="GetChatClient"::: :::zone-end 1. Create a new `ChatOptions` object that contains an inline function the AI model can call to get the current weather. The function declaration includes a delegate to run logic, and name and description parameters to describe the purpose of the function to the AI model. - :::code language="csharp" source="snippets/function-calling/openai/program.cs" range="16-26"::: + :::code language="csharp" source="snippets/function-calling/openai/program.cs" id="AddOptions"::: 1. Add a system prompt to the `chatHistory` to provide context and instructions to the model. Send a user prompt with a question that requires the AI model to call the registered function to properly answer the question. - :::code language="csharp" source="snippets/function-calling/openai/program.cs" range="28-40"::: + :::code language="csharp" source="snippets/function-calling/openai/program.cs" id="PromptModel"::: 1. Use the `dotnet run` command to run the app: @@ -144,11 +142,10 @@ The app uses the [`Microsoft.Extensions.AI`](https://www.nuget.org/packages/Micr ## Clean up resources -When you no longer need the sample application or resources, remove the corresponding deployment and all resources. +If you no longer need them, delete the Azure OpenAI resource and GPT-4 model deployment. -```azdeveloper -azd down -``` +1. In the [Azure Portal](https://aka.ms/azureportal), navigate to the Azure OpenAI resource. +1. Select the Azure OpenAI resource, and then select **Delete**. :::zone-end diff --git a/docs/azure/includes/dotnet-all.md b/docs/azure/includes/dotnet-all.md index 3d814f377b636..909b6be6959a8 100644 --- a/docs/azure/includes/dotnet-all.md +++ b/docs/azure/includes/dotnet-all.md @@ -6,7 +6,7 @@ | App Configuration | NuGet [1.6.0](https://www.nuget.org/packages/Azure.Data.AppConfiguration/1.6.0) | [docs](/dotnet/api/overview/azure/Data.AppConfiguration-readme) | GitHub [1.6.0](https://github.com/Azure/azure-sdk-for-net/tree/Azure.Data.AppConfiguration_1.6.0/sdk/appconfiguration/Azure.Data.AppConfiguration/) | | App Configuration Provider | NuGet [8.1.2](https://www.nuget.org/packages/Microsoft.Extensions.Configuration.AzureAppConfiguration/8.1.2)
NuGet [8.2.0-preview](https://www.nuget.org/packages/Microsoft.Extensions.Configuration.AzureAppConfiguration/8.2.0-preview) | [docs](/dotnet/api/overview/azure/Microsoft.Extensions.Configuration.AzureAppConfiguration-readme) | GitHub [8.1.2](https://github.com/Azure/AppConfiguration-DotnetProvider) | | Attestation | NuGet [1.0.0](https://www.nuget.org/packages/Azure.Security.Attestation/1.0.0) | [docs](/dotnet/api/overview/azure/Security.Attestation-readme) | GitHub [1.0.0](https://github.com/Azure/azure-sdk-for-net/tree/Azure.Security.Attestation_1.0.0/sdk/attestation/Azure.Security.Attestation/) | -| Azure AI Agents Persistent | NuGet [1.0.0-beta.1](https://www.nuget.org/packages/Azure.AI.Agents.Persistent/1.0.0-beta.1) | | GitHub [1.0.0-beta.1](https://github.com/Azure/azure-sdk-for-net/tree/Azure.AI.Agents.Persistent_1.0.0-beta.1/sdk/ai/Azure.AI.Agents.Persistent/) | +| Azure AI Agents Persistent | NuGet [1.0.0-beta.1](https://www.nuget.org/packages/Azure.AI.Agents.Persistent/1.0.0-beta.1) | [docs](/dotnet/api/overview/azure/AI.Agents.Persistent-readme?view=azure-dotnet-preview&preserve-view=true) | GitHub [1.0.0-beta.1](https://github.com/Azure/azure-sdk-for-net/tree/Azure.AI.Agents.Persistent_1.0.0-beta.1/sdk/ai/Azure.AI.Agents.Persistent/) | | Azure AI Search | NuGet [11.6.0](https://www.nuget.org/packages/Azure.Search.Documents/11.6.0)
NuGet [11.7.0-beta.3](https://www.nuget.org/packages/Azure.Search.Documents/11.7.0-beta.3) | [docs](/dotnet/api/overview/azure/Search.Documents-readme) | GitHub [11.6.0](https://github.com/Azure/azure-sdk-for-net/tree/Azure.Search.Documents_11.6.0/sdk/search/Azure.Search.Documents/)
GitHub [11.7.0-beta.3](https://github.com/Azure/azure-sdk-for-net/tree/Azure.Search.Documents_11.7.0-beta.3/sdk/search/Azure.Search.Documents/) | | Azure Object Anchors Conversion | NuGet [0.3.0-beta.6](https://www.nuget.org/packages/Azure.MixedReality.ObjectAnchors.Conversion/0.3.0-beta.6) | [docs](/dotnet/api/overview/azure/MixedReality.ObjectAnchors.Conversion-readme?view=azure-dotnet-preview&preserve-view=true) | GitHub [0.3.0-beta.6](https://github.com/Azure/azure-sdk-for-net/tree/Azure.MixedReality.ObjectAnchors.Conversion_0.3.0-beta.6/sdk/objectanchors/Azure.MixedReality.ObjectAnchors.Conversion/) | | Azure Remote Rendering | NuGet [1.1.0](https://www.nuget.org/packages/Azure.MixedReality.RemoteRendering/1.1.0) | [docs](/dotnet/api/overview/azure/MixedReality.RemoteRendering-readme) | GitHub [1.1.0](https://github.com/Azure/azure-sdk-for-net/tree/Azure.MixedReality.RemoteRendering_1.1.0/sdk/remoterendering/Azure.MixedReality.RemoteRendering/) | @@ -299,7 +299,7 @@ | Resource Management - Mongo Cluster | NuGet [1.0.0-beta.1](https://www.nuget.org/packages/Azure.ResourceManager.MongoCluster/1.0.0-beta.1) | [docs](/dotnet/api/overview/azure/ResourceManager.MongoCluster-readme?view=azure-dotnet-preview&preserve-view=true) | GitHub [1.0.0-beta.1](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.MongoCluster_1.0.0-beta.1/sdk/mongocluster/Azure.ResourceManager.MongoCluster/) | | Resource Management - Monitor | NuGet [1.3.1](https://www.nuget.org/packages/Azure.ResourceManager.Monitor/1.3.1)
NuGet [1.4.0-beta.3](https://www.nuget.org/packages/Azure.ResourceManager.Monitor/1.4.0-beta.3) | [docs](/dotnet/api/overview/azure/ResourceManager.Monitor-readme) | GitHub [1.3.1](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.Monitor_1.3.1/sdk/monitor/Azure.ResourceManager.Monitor/)
GitHub [1.4.0-beta.3](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.Monitor_1.4.0-beta.3/sdk/monitor/Azure.ResourceManager.Monitor/) | | Resource Management - MySQL | NuGet [1.1.1](https://www.nuget.org/packages/Azure.ResourceManager.MySql/1.1.1) | [docs](/dotnet/api/overview/azure/ResourceManager.MySql-readme) | GitHub [1.1.1](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.MySql_1.1.1/sdk/mysql/Azure.ResourceManager.MySql/) | -| Resource Management - Neon Postgres | NuGet [1.0.0-beta.1](https://www.nuget.org/packages/Azure.ResourceManager.NeonPostgres/1.0.0-beta.1) | [docs](/dotnet/api/overview/azure/ResourceManager.NeonPostgres-readme?view=azure-dotnet-preview&preserve-view=true) | GitHub [1.0.0-beta.1](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.NeonPostgres_1.0.0-beta.1/sdk/neonpostgres/Azure.ResourceManager.NeonPostgres/) | +| Resource Management - Neon Postgres | NuGet [1.0.0-beta.2](https://www.nuget.org/packages/Azure.ResourceManager.NeonPostgres/1.0.0-beta.2) | [docs](/dotnet/api/overview/azure/ResourceManager.NeonPostgres-readme?view=azure-dotnet-preview&preserve-view=true) | GitHub [1.0.0-beta.2](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.NeonPostgres_1.0.0-beta.2/sdk/neonpostgres/Azure.ResourceManager.NeonPostgres/) | | Resource Management - NetApp Files | NuGet [1.10.0](https://www.nuget.org/packages/Azure.ResourceManager.NetApp/1.10.0) | [docs](/dotnet/api/overview/azure/ResourceManager.NetApp-readme) | GitHub [1.10.0](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.NetApp_1.10.0/sdk/netapp/Azure.ResourceManager.NetApp/) | | Resource Management - Network | NuGet [1.10.0](https://www.nuget.org/packages/Azure.ResourceManager.Network/1.10.0)
NuGet [1.11.0-beta.1](https://www.nuget.org/packages/Azure.ResourceManager.Network/1.11.0-beta.1) | [docs](/dotnet/api/overview/azure/ResourceManager.Network-readme) | GitHub [1.10.0](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.Network_1.10.0/sdk/network/Azure.ResourceManager.Network/)
GitHub [1.11.0-beta.1](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.Network_1.11.0-beta.1/sdk/network/Azure.ResourceManager.Network/) | | Resource Management - Network Cloud | NuGet [1.1.0](https://www.nuget.org/packages/Azure.ResourceManager.NetworkCloud/1.1.0)
NuGet [1.2.0-beta.1](https://www.nuget.org/packages/Azure.ResourceManager.NetworkCloud/1.2.0-beta.1) | [docs](/dotnet/api/overview/azure/ResourceManager.NetworkCloud-readme) | GitHub [1.1.0](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.NetworkCloud_1.1.0/sdk/networkcloud/Azure.ResourceManager.NetworkCloud/)
GitHub [1.2.0-beta.1](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.NetworkCloud_1.2.0-beta.1/sdk/networkcloud/Azure.ResourceManager.NetworkCloud/) | @@ -381,8 +381,8 @@ | Content Safety Extension Embedded Text | NuGet [1.0.0](https://www.nuget.org/packages/Azure.AI.ContentSafety.Extension.Embedded.Text/1.0.0)
NuGet [1.0.1-beta.4](https://www.nuget.org/packages/Azure.AI.ContentSafety.Extension.Embedded.Text/1.0.1-beta.4) | | | | Cosmos DB Fault Injection | NuGet [1.0.0-beta.0](https://www.nuget.org/packages/Microsoft.Azure.Cosmos.FaultInjection/1.0.0-beta.0) | | | | DotNetty | NuGet [0.7.6](https://www.nuget.org/packages/DotNetty.Common/0.7.6) | | | -| Functions Extension MCP | NuGet [1.0.0-preview.3](https://www.nuget.org/packages/Microsoft.Azure.Functions.Extensions.Mcp/1.0.0-preview.3) | | | -| Functions Worker Extension MCP | NuGet [1.0.0-preview.3](https://www.nuget.org/packages/Microsoft.Azure.Functions.Worker.Extensions.Mcp/1.0.0-preview.3) | | | +| Functions Extension MCP | NuGet [1.0.0-preview.4](https://www.nuget.org/packages/Microsoft.Azure.Functions.Extensions.Mcp/1.0.0-preview.4) | | | +| Functions Worker Extension MCP | NuGet [1.0.0-preview.4](https://www.nuget.org/packages/Microsoft.Azure.Functions.Worker.Extensions.Mcp/1.0.0-preview.4) | | | | Functions Worker Extension MySQL | NuGet [1.0.129](https://www.nuget.org/packages/Microsoft.Azure.Functions.Worker.Extensions.MySql/1.0.129) | | | | HTTP ASPNETCore Analyzers | NuGet [1.0.3](https://www.nuget.org/packages/Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore.Analyzers/1.0.3) | | | | IoT Operations MQTT | NuGet [0.10.1](https://www.nuget.org/packages/Azure.Iot.Operations.Mqtt/0.10.1) | | | diff --git a/docs/azure/includes/dotnet-new.md b/docs/azure/includes/dotnet-new.md index 25c63e95b7013..34b83dc7b1af7 100644 --- a/docs/azure/includes/dotnet-new.md +++ b/docs/azure/includes/dotnet-new.md @@ -6,7 +6,7 @@ | App Configuration | NuGet [1.6.0](https://www.nuget.org/packages/Azure.Data.AppConfiguration/1.6.0) | [docs](/dotnet/api/overview/azure/Data.AppConfiguration-readme) | GitHub [1.6.0](https://github.com/Azure/azure-sdk-for-net/tree/Azure.Data.AppConfiguration_1.6.0/sdk/appconfiguration/Azure.Data.AppConfiguration/) | | App Configuration Provider | NuGet [8.1.2](https://www.nuget.org/packages/Microsoft.Extensions.Configuration.AzureAppConfiguration/8.1.2)
NuGet [8.2.0-preview](https://www.nuget.org/packages/Microsoft.Extensions.Configuration.AzureAppConfiguration/8.2.0-preview) | [docs](/dotnet/api/overview/azure/Microsoft.Extensions.Configuration.AzureAppConfiguration-readme) | GitHub [8.1.2](https://github.com/Azure/AppConfiguration-DotnetProvider) | | Attestation | NuGet [1.0.0](https://www.nuget.org/packages/Azure.Security.Attestation/1.0.0) | [docs](/dotnet/api/overview/azure/Security.Attestation-readme) | GitHub [1.0.0](https://github.com/Azure/azure-sdk-for-net/tree/Azure.Security.Attestation_1.0.0/sdk/attestation/Azure.Security.Attestation/) | -| Azure AI Agents Persistent | NuGet [1.0.0-beta.1](https://www.nuget.org/packages/Azure.AI.Agents.Persistent/1.0.0-beta.1) | | GitHub [1.0.0-beta.1](https://github.com/Azure/azure-sdk-for-net/tree/Azure.AI.Agents.Persistent_1.0.0-beta.1/sdk/ai/Azure.AI.Agents.Persistent/) | +| Azure AI Agents Persistent | NuGet [1.0.0-beta.1](https://www.nuget.org/packages/Azure.AI.Agents.Persistent/1.0.0-beta.1) | [docs](/dotnet/api/overview/azure/AI.Agents.Persistent-readme?view=azure-dotnet-preview&preserve-view=true) | GitHub [1.0.0-beta.1](https://github.com/Azure/azure-sdk-for-net/tree/Azure.AI.Agents.Persistent_1.0.0-beta.1/sdk/ai/Azure.AI.Agents.Persistent/) | | Azure AI Search | NuGet [11.6.0](https://www.nuget.org/packages/Azure.Search.Documents/11.6.0)
NuGet [11.7.0-beta.3](https://www.nuget.org/packages/Azure.Search.Documents/11.7.0-beta.3) | [docs](/dotnet/api/overview/azure/Search.Documents-readme) | GitHub [11.6.0](https://github.com/Azure/azure-sdk-for-net/tree/Azure.Search.Documents_11.6.0/sdk/search/Azure.Search.Documents/)
GitHub [11.7.0-beta.3](https://github.com/Azure/azure-sdk-for-net/tree/Azure.Search.Documents_11.7.0-beta.3/sdk/search/Azure.Search.Documents/) | | Azure Object Anchors Conversion | NuGet [0.3.0-beta.6](https://www.nuget.org/packages/Azure.MixedReality.ObjectAnchors.Conversion/0.3.0-beta.6) | [docs](/dotnet/api/overview/azure/MixedReality.ObjectAnchors.Conversion-readme?view=azure-dotnet-preview&preserve-view=true) | GitHub [0.3.0-beta.6](https://github.com/Azure/azure-sdk-for-net/tree/Azure.MixedReality.ObjectAnchors.Conversion_0.3.0-beta.6/sdk/objectanchors/Azure.MixedReality.ObjectAnchors.Conversion/) | | Azure Remote Rendering | NuGet [1.1.0](https://www.nuget.org/packages/Azure.MixedReality.RemoteRendering/1.1.0) | [docs](/dotnet/api/overview/azure/MixedReality.RemoteRendering-readme) | GitHub [1.1.0](https://github.com/Azure/azure-sdk-for-net/tree/Azure.MixedReality.RemoteRendering_1.1.0/sdk/remoterendering/Azure.MixedReality.RemoteRendering/) | @@ -306,7 +306,7 @@ | Resource Management - Mongo Cluster | NuGet [1.0.0-beta.1](https://www.nuget.org/packages/Azure.ResourceManager.MongoCluster/1.0.0-beta.1) | [docs](/dotnet/api/overview/azure/ResourceManager.MongoCluster-readme?view=azure-dotnet-preview&preserve-view=true) | GitHub [1.0.0-beta.1](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.MongoCluster_1.0.0-beta.1/sdk/mongocluster/Azure.ResourceManager.MongoCluster/) | | Resource Management - Monitor | NuGet [1.3.1](https://www.nuget.org/packages/Azure.ResourceManager.Monitor/1.3.1)
NuGet [1.4.0-beta.3](https://www.nuget.org/packages/Azure.ResourceManager.Monitor/1.4.0-beta.3) | [docs](/dotnet/api/overview/azure/ResourceManager.Monitor-readme) | GitHub [1.3.1](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.Monitor_1.3.1/sdk/monitor/Azure.ResourceManager.Monitor/)
GitHub [1.4.0-beta.3](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.Monitor_1.4.0-beta.3/sdk/monitor/Azure.ResourceManager.Monitor/) | | Resource Management - MySQL | NuGet [1.1.1](https://www.nuget.org/packages/Azure.ResourceManager.MySql/1.1.1) | [docs](/dotnet/api/overview/azure/ResourceManager.MySql-readme) | GitHub [1.1.1](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.MySql_1.1.1/sdk/mysql/Azure.ResourceManager.MySql/) | -| Resource Management - Neon Postgres | NuGet [1.0.0-beta.1](https://www.nuget.org/packages/Azure.ResourceManager.NeonPostgres/1.0.0-beta.1) | [docs](/dotnet/api/overview/azure/ResourceManager.NeonPostgres-readme?view=azure-dotnet-preview&preserve-view=true) | GitHub [1.0.0-beta.1](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.NeonPostgres_1.0.0-beta.1/sdk/neonpostgres/Azure.ResourceManager.NeonPostgres/) | +| Resource Management - Neon Postgres | NuGet [1.0.0-beta.2](https://www.nuget.org/packages/Azure.ResourceManager.NeonPostgres/1.0.0-beta.2) | [docs](/dotnet/api/overview/azure/ResourceManager.NeonPostgres-readme?view=azure-dotnet-preview&preserve-view=true) | GitHub [1.0.0-beta.2](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.NeonPostgres_1.0.0-beta.2/sdk/neonpostgres/Azure.ResourceManager.NeonPostgres/) | | Resource Management - NetApp Files | NuGet [1.10.0](https://www.nuget.org/packages/Azure.ResourceManager.NetApp/1.10.0) | [docs](/dotnet/api/overview/azure/ResourceManager.NetApp-readme) | GitHub [1.10.0](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.NetApp_1.10.0/sdk/netapp/Azure.ResourceManager.NetApp/) | | Resource Management - Network | NuGet [1.10.0](https://www.nuget.org/packages/Azure.ResourceManager.Network/1.10.0)
NuGet [1.11.0-beta.1](https://www.nuget.org/packages/Azure.ResourceManager.Network/1.11.0-beta.1) | [docs](/dotnet/api/overview/azure/ResourceManager.Network-readme) | GitHub [1.10.0](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.Network_1.10.0/sdk/network/Azure.ResourceManager.Network/)
GitHub [1.11.0-beta.1](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.Network_1.11.0-beta.1/sdk/network/Azure.ResourceManager.Network/) | | Resource Management - Network Analytics | NuGet [1.0.1](https://www.nuget.org/packages/Azure.ResourceManager.NetworkAnalytics/1.0.1) | [docs](/dotnet/api/overview/azure/ResourceManager.NetworkAnalytics-readme) | GitHub [1.0.1](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.NetworkAnalytics_1.0.1/sdk/networkanalytics/Azure.ResourceManager.NetworkAnalytics/) | diff --git a/docs/core/compatibility/10.0.md b/docs/core/compatibility/10.0.md index e9ac7d2247509..e055372443f5a 100644 --- a/docs/core/compatibility/10.0.md +++ b/docs/core/compatibility/10.0.md @@ -48,6 +48,12 @@ If you're migrating an app to .NET 10, the breaking changes listed here might af | [X509Certificate and PublicKey key parameters can be null](cryptography/10.0/x509-publickey-null.md) | Behavioral/source incompatible change | Preview 3 | | [Environment variable renamed to DOTNET_OPENSSL_VERSION_OVERRIDE](cryptography/10.0/version-override.md) | Behavioral change | Preview 1 | +## Interop + +| Title | Type of change | Introduced version | +|------------------------------------------------------------------------------------------------------------------------------------|-------------------|--------------------| +| [Specifying DllImportSearchPath.AssemblyDirectory only searches the assembly directory](interop/10.0/search-assembly-directory.md) | Behavioral change | Preview 5 | + ## Networking | Title | Type of change | Introduced version | diff --git a/docs/core/compatibility/interop/10.0/search-assembly-directory.md b/docs/core/compatibility/interop/10.0/search-assembly-directory.md new file mode 100644 index 0000000000000..27b50dbba4779 --- /dev/null +++ b/docs/core/compatibility/interop/10.0/search-assembly-directory.md @@ -0,0 +1,59 @@ +--- +title: "Breaking change - Specifying DllImportSearchPath.AssemblyDirectory only searches the assembly directory" +description: "Learn about the breaking change in .NET 10 Preview 5 where specifying DllImportSearchPath.AssemblyDirectory as the only search flag restricts the search to the assembly directory." +ms.date: 5/9/2025 +ai-usage: ai-assisted +ms.custom: https://github.com/dotnet/docs/issues/45911 +--- + +# Specifying DllImportSearchPath.AssemblyDirectory only searches the assembly directory + +Starting in .NET 10, if you specify as the only search flag, the runtime searches exclusively in the assembly directory. This change affects the behavior of P/Invokes and the class. + +## Version introduced + +.NET 10 Preview 5 + +## Previous behavior + +When was specified as the only search flag, the runtime searched the assembly directory first. If the library was not found, it fell back to the operating system's default library search behavior. + +Example: + +```csharp +[DllImport("example.dll", DllImportSearchPath = DllImportSearchPath.AssemblyDirectory)] +public static extern void ExampleMethod(); +``` + +In this case, the runtime would search the assembly directory and then fall back to the OS search paths. + +## New behavior + +When is specified as the only search flag, the runtime searches only in the assembly directory. It does not fall back to the operating system's default library search behavior. + +The previous code example would now only search the assembly directory for *example.dll*. If the library is not found there, a will be thrown. + +## Type of breaking change + +This is a [behavioral change](../../categories.md#behavioral-change). + +## Reason for change + +The fallback behavior when specifying caused confusion and was inconsistent with the design of search flags. This change ensures clarity and consistency in behavior. + +## Recommended action + +If fallback behavior is required, avoid specifying an explicit . By default, when no flags are specified, the runtime searches the assembly directory and then falls back to the operating system's default library search behavior. + +Example: + +```csharp +[DllImport("example.dll")] +public static extern void ExampleMethod(); +``` + +## Affected APIs + +- P/Invokes using +- +- diff --git a/docs/core/compatibility/toc.yml b/docs/core/compatibility/toc.yml index 9a68a1eeca6c4..4d0bce476f8ee 100644 --- a/docs/core/compatibility/toc.yml +++ b/docs/core/compatibility/toc.yml @@ -42,6 +42,10 @@ items: items: - name: Environment variable renamed to DOTNET_ICU_VERSION_OVERRIDE href: globalization/10.0/version-override.md + - name: Interop + items: + - name: Specifying DllImportSearchPath.AssemblyDirectory only searches the assembly directory + href: interop/10.0/search-assembly-directory.md - name: Networking items: - name: Streaming HTTP responses enabled by default in browser HTTP clients @@ -1808,6 +1812,10 @@ items: href: globalization.md - name: Interop items: + - name: .NET 10 + items: + - name: Specifying DllImportSearchPath.AssemblyDirectory only searches the assembly directory + href: interop/10.0/search-assembly-directory.md - name: .NET 9 items: - name: CET supported by default