Skip to content

Using both Microsoft.AspNetCore.Components.WebView.Wpf and Microsoft.Extensions.Options.ConfigurationExtensions cause SelfContained publish failed in VS #11690

Description

@tp1415926535

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<TOptions>(this IServiceCollection services, IConfiguration config), for example:
    var serviceCollection = new ServiceCollection();
    var configuration = new ConfigurationBuilder()
        .AddJsonFile("appsettings.json", optional: true).Build();
    serviceCollection.Configure<TestOption>(configuration);

public class TestOption { }
  1. 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:

<PropertyGroup>
    <InterceptorsNamespaces>$(InterceptorsNamespaces);Microsoft.Extensions.Configuration.Binder.SourceGeneration</InterceptorsNamespaces>
</PropertyGroup>

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugProduct bug (most likely)InvestigateRequires further investigation by the WPF team.area-Build

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions