Using both `Microsoft.AspNetCore.Components.WebView.Wpf` and `Microsoft.Extensions.Options.ConfigurationExtensions` cause SelfContained publish failed in VS
- Dominant language
- C#
- Stars
- 7.7k
- Forks
- 1.3k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 61
Description
### Description
If install the `Microsoft.AspNetCore.Components.WebView.Wpf` NuGet package and use functions from `Microsoft.Extensions.Options.ConfigurationExtensions`, SelfContained publish in Visual Studio publish page will fail, but it works fine when using the command line `dotnet publish -c Release -r win-x64 --self-contained true`. If the “obj” folder is not deleted after running the command, the page will also publish successfully.
### Reproduction Steps
1. Create a WPF application ( .net9 or 10 ) , install the `Microsoft.AspNetCore.Components.WebView.Wpf` NuGet package, and change the SDK to “Microsoft.NET.Sdk.Razor” to ensure successful compilation.
2. If the webView nuget package just installed is version earlier than 10.0, install `Microsoft.Extensions.Options.ConfigurationExtensions` as well; otherwise, the package already includes this.
3. Call the function `public static IServiceCollection Configure(this IServiceCollection services, IConfiguration config)`, for example:
```csharp
var serviceCollection = new ServiceCollection();
var configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", optional: true).Build();
serviceCollection.Configure(configuration);
public class TestOption { }
```
4. Right-click the project, select publish, choose folder and SelfContained release x64 , click “Publish,” and an error occurs.
### Expected behavior
The button on the publish page should function normally, just like the output of a command-line execution.
### Actual behavior
A window pops up indicating a publishing error, but no specific reason is shown.
### Regression?
_No response_
### Known Workarounds
Add the following property to PropertyGroup like:
```xml
$(InterceptorsNamespaces);Microsoft.Extensions.Configuration.Binder.SourceGeneration
```
Or using the command line.
### Impact
All packages that directly or indirectly reference `Microsoft.Extensions.Options.ConfigurationExtensions`, such as `Microsoft.Extensions.Hosting`
### Configuration
_No response_
### Other information
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.