Repository: microsoft/autogen
Pull request: [.NET] Update version of Microsoft.Extension.Ai & System.Text.Json
<!-- Thank you for your contribution! Please review https://microsoft.github.io/autogen/docs/Contribute before opening a pull request. -->

<!-- Please add a reviewer to the assignee section when you create a PR. If you don't have the access to it, we will shortly find a reviewer and assign them to your PR. -->

## Why are these changes needed?
#4031
- Update package 
  -  `Microsoft.Extension.Ai`  to `9.0.0-preview.9.24525.1`
  -  `System.Text.Json` to `8.0.5`
- Add `NoWarnDuplicatePackages` to `Directory.Build.props` and add the noWarn the necessary csproj. This is so the build does not warn about duplicate package reference

<!-- Please give a short summary of the change and the problem this solves. -->

## Related issue number

<!-- For example: "Closes #1234" -->
Closes  #4031

## Checks

- [ ] I've included any doc changes needed for https://microsoft.github.io/autogen/. See https://microsoft.github.io/autogen/docs/Contribute#documentation to build and test documentation locally.
- [ ] I've added tests (if relevant) corresponding to the changes introduced in this PR.
- [x] I've made sure all auto checks have passed.


Problem statement:
[.Net] Update M.E.A.I to 9.0.0-preview.9.24525.1
### What feature would you like to be added?

And S.T.J to `8.0.5`

### Why is this needed?

The latest M.E.A.I now depends on a lower `STJ` version. Much friendly to existing projects which can't update STJ to 9.* for some reason

Hints from issue discussion:
@LittleLittleCloud If we update `Microsoft.Extensions.Ai` to `9.0.0-preview.9.24525.1`, we cannot downgrade `System.Text.Json` because `9.0.0-rc.2.24473.5` is the min version.

https://www.nuget.org/packages/Microsoft.Extensions.AI/9.0.0-preview.9.24525.1#dependencies-body-tab:~:text=9.0.0%2Drc.2.24473.5)-,System.Text.Json%20(%3E%3D%209.0.0%2Drc.2.24473.5),-net9.0

Commit message: remove copilot generated comment

Patch to review:
diff --git a/dotnet/Directory.Build.props b/dotnet/Directory.Build.props
index bb78c84d14f4..81b36c126e2e 100644
--- a/dotnet/Directory.Build.props
+++ b/dotnet/Directory.Build.props
@@ -13,6 +13,10 @@
     <CSNoWarn>CS1998;CS1591;CS8002;</CSNoWarn>
     <SKEXPNoWarn>SKEXP0001;SKEXP0010;SKEXP0020</SKEXPNoWarn>
     <NoWarn>$(NoWarn);$(CSNoWarn);$(SKEXPNoWarn);NU5104</NoWarn>
+
+    <!-- Some properties require a different version of System.Json.Text > 8.0.5
+    Some csprojs override the version and this is a workaround from duplicate package references -->
+    <NoWarnDuplicatePackages>$(NoWarn);NU1504;NU1605</NoWarnDuplicatePackages>
     <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
     <GenerateDocumentationFile>true</GenerateDocumentationFile>
     <IsPackable>false</IsPackable>
diff --git a/dotnet/Directory.Packages.props b/dotnet/Directory.Packages.props
index dd9df7161047..aaf590d70f62 100644
--- a/dotnet/Directory.Packages.props
+++ b/dotnet/Directory.Packages.props
@@ -3,7 +3,7 @@
     <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
     <MicrosoftSemanticKernelVersion>1.22.0</MicrosoftSemanticKernelVersion>
     <MicrosoftSemanticKernelExperimentalVersion>1.22.0-alpha</MicrosoftSemanticKernelExperimentalVersion>
-    <MicrosoftExtensionsAIVersion>9.0.0-preview.9.24507.7</MicrosoftExtensionsAIVersion>
+    <MicrosoftExtensionsAIVersion>9.0.0-preview.9.24525.1</MicrosoftExtensionsAIVersion>
   </PropertyGroup>
   <ItemGroup>
     <PackageVersion Include="Aspire.Hosting" Version="9.0.0-rc.1.24511.1" />
@@ -111,6 +111,6 @@
     <PackageVersion Include="Moq" Version="4.20.72" />
     <PackageVersion Include="Microsoft.PowerShell.SDK" Version="7.4.5" />
     <PackageVersion Include="Microsoft.AspNetCore.TestHost" Version="8.0.10" />
-    <PackageVersion Include="System.Text.Json" Version="9.0.0-rc.2.24473.5" />
+    <PackageVersion Include="System.Text.Json" Version="8.0.5" />
   </ItemGroup>
-</Project>
\ No newline at end of file
+</Project>
diff --git a/dotnet/samples/Hello/HelloAIAgents/HelloAIAgents.csproj b/dotnet/samples/Hello/HelloAIAgents/HelloAIAgents.csproj
index 73f1891b3f22..a93c17980470 100644
--- a/dotnet/samples/Hello/HelloAIAgents/HelloAIAgents.csproj
+++ b/dotnet/samples/Hello/HelloAIAgents/HelloAIAgents.csproj
@@ -16,6 +16,7 @@
     <TargetFramework>net8.0</TargetFramework>
     <ImplicitUsings>enable</ImplicitUsings>
     <Nullable>enable</Nullable>
+    <NoWarn>$(NoWarnDuplicatePackages)</NoWarn>
   </PropertyGroup>
 
 </Project>
diff --git a/dotnet/samples/dev-team/DevTeam.Agents/DevTeam.Agents.csproj b/dotnet/samples/dev-team/DevTeam.Agents/DevTeam.Agents.csproj
index d7dbd1688599..ec336cabd4f7 100644
--- a/dotnet/samples/dev-team/DevTeam.Agents/DevTeam.Agents.csproj
+++ b/dotnet/samples/dev-team/DevTeam.Agents/DevTeam.Agents.csproj
@@ -4,12 +4,13 @@
     <TargetFramework>net8.0</TargetFramework>
     <Nullable>enable</Nullable>
     <ImplicitUsings>enable</ImplicitUsings>
+    <NoWarn>$(NoWarnDuplicatePackages)</NoWarn>
   </PropertyGroup>
 
   <ItemGroup>
-   
+
     <ProjectReference Include="../../../src/Microsoft.AutoGen/Agents/Microsoft.AutoGen.Agents.csproj" />
-   
+
     <ProjectReference Include="../../../src/Microsoft.AutoGen/ServiceDefaults/Microsoft.AutoGen.ServiceDefaults.csproj" />
     <ProjectReference Include="..\DevTeam.Shared\DevTeam.Shared.csproj" />
     <ProjectReference Include="..\..\..\src\Microsoft.AutoGen\Extensions\SemanticKernel\Microsoft.AutoGen.Extensions.SemanticKernel.csproj" />
diff --git a/dotnet/samples/dev-team/DevTeam.Backend/DevTeam.Backend.csproj b/dotnet/samples/dev-team/DevTeam.Backend/DevTeam.Backend.csproj
index 419298430c38..af18e890ecc9 100644
--- a/dotnet/samples/dev-team/DevTeam.Backend/DevTeam.Backend.csproj
+++ b/dotnet/samples/dev-team/DevTeam.Backend/DevTeam.Backend.csproj
@@ -8,6 +8,8 @@
     <TargetFramework>net8.0</TargetFramework>
     <Nullable>enable</Nullable>
     <ImplicitUsings>enable</ImplicitUsings>
+
+    <NoWarn>$(NoWarnDuplicatePackages)</NoWarn>
   </PropertyGroup>
 
   <ItemGroup>
diff --git a/dotnet/src/Microsoft.AutoGen/Extensions/AIModelClientHostingExtensions/AIModelClientHostingExtensions.csproj b/dotnet/src/Microsoft.AutoGen/Extensions/AIModelClientHostingExtensions/AIModelClientHostingExtensions.csproj
index a94921946c09..44fdc49fde2f 100644
--- a/dotnet/src/Microsoft.AutoGen/Extensions/AIModelClientHostingExtensions/AIModelClientHostingExtensions.csproj
+++ b/dotnet/src/Microsoft.AutoGen/Extensions/AIModelClientHostingExtensions/AIModelClientHostingExtensions.csproj
@@ -3,6 +3,8 @@
     <TargetFramework>net8.0</TargetFramework>
     <ImplicitUsings>enable</ImplicitUsings>
     <Nullable>enable</Nullable>
+
+    <NoWarn>$(NoWarnDuplicatePackages)</NoWarn>
   </PropertyGroup>
   <ItemGroup>
     <PackageReference Include="Aspire.Azure.AI.OpenAI" />
@@ -14,5 +16,6 @@
     <PackageReference Include="Microsoft.Extensions.AI.OpenAI" />
     <PackageReference Include="Microsoft.Extensions.DependencyInjection" />
     <PackageReference Include="Microsoft.Extensions.Hosting" />
+    <PackageReference Include="System.Text.Json" VersionOverride="9.0.0-rc.2.24473.5" />
   </ItemGroup>
 </Project>
diff --git a/dotnet/src/Microsoft.AutoGen/Extensions/SemanticKernel/Microsoft.AutoGen.Extensions.SemanticKernel.csproj b/dotnet/src/Microsoft.AutoGen/Extensions/SemanticKernel/Microsoft.AutoGen.Extensions.SemanticKernel.csproj
index a976c007715c..4073bd770c60 100644
--- a/dotnet/src/Microsoft.AutoGen/Extensions/SemanticKernel/Microsoft.AutoGen.Extensions.SemanticKernel.csproj
+++ b/dotnet/src/Microsoft.AutoGen/Extensions/SemanticKernel/Microsoft.AutoGen.Extensions.SemanticKernel.csproj
@@ -9,12 +9,13 @@
     <TargetFramework>net8.0</TargetFramework>
     <ImplicitUsings>enable</ImplicitUsings>
     <Nullable>enable</Nullable>
+    <NoWarn>$(NoWarnDuplicatePackages)</NoWarn>
   </PropertyGroup>
 
   <ItemGroup>
 	<PackageReference Include="Azure.AI.OpenAI" />
 	<PackageReference Include="Microsoft.SemanticKernel" />
-	  
+
     <PackageReference Include="Microsoft.SemanticKernel.Connectors.Qdrant" />
     <PackageReference Include="Microsoft.SemanticKernel.Plugins.Memory" />
   </ItemGroup>


Code review comments:
diff_hunk: @@ -13,6 +13,10 @@
     <CSNoWarn>CS1998;CS1591;CS8002;</CSNoWarn>
     <SKEXPNoWarn>SKEXP0001;SKEXP0010;SKEXP0020</SKEXPNoWarn>
     <NoWarn>$(NoWarn);$(CSNoWarn);$(SKEXPNoWarn);NU5104</NoWarn>
+
+    <!-- Some properties require a different version of System.Json.Text > 8.0.5
+    Some csprojs override the version and this is a workaround from duplicate package references -->
path: dotnet/Directory.Build.props
text: @user1:
Maybe try simply removing the S.T.J package reference in `Directory.Build.props` instead? We probably don't need that global reference after updating M.E.A.I version