Skip to content

Unable to publish ASP.NET builds with Microsoft.Build and VS2022 #49684

@Androvald

Description

@Androvald

Issue Description

I am maintaining a CI application that uses Microsoft.Build and it now fails to run publish builds for ASP.NET projects. It now fails with the following exception:

C:\Program Files\dotnet\sdk\9.0.301\Sdks\Microsoft.NET.Sdk.StaticWebAssets\targets\Microsoft.NET.Sdk.StaticWebAssets.targets:679
(<Redacted>.csproj) C:\Program Files\dotnet\sdk\9.0.301\Sdks\Microsoft.NET.Sdk.StaticWebAssets\targets\Microsoft.NET.Sdk.StaticWebAssets.targets(679,5): Error MSB4018: The "DefineStaticWebAssets" task failed unexpectedly. System.TypeInitializationException: The type initializer for 'DefineStaticWebAssetsSerializerContext' threw an exception. ---> System.MissingMethodException: Method not found: 'System.Text.Json.JsonEncodedText System.Text.Json.JsonEncodedText.Encode(System.String, System.Text.Encodings.Web.JavaScriptEncoder)'. at Microsoft.AspNetCore.StaticWebAssets.Tasks.DefineStaticWebAssets.DefineStaticWebAssetsSerializerContext..cctor() --- End of inner exception stack trace --- at Microsoft.AspNetCore.StaticWebAssets.Tasks.DefineStaticWebAssets.DefineStaticWebAssetsCache.ReadOrCreateCache(TaskLoggingHelper log, String manifestPath) at Microsoft.AspNetCore.StaticWebAssets.Tasks.DefineStaticWebAssets.GetOrCreateAssetsCache() at Microsoft.AspNetCore.StaticWebAssets.Tasks.DefineStaticWebAssets.Execute() at Microsoft.Build.BackEnd.TaskExecutionHost.Execute() at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext() (Help Keyword: MSBuild.FatalTaskError)

Steps to Reproduce

I've simplified the reproduction to this project:
ASP.NET Publish Broken.zip
It has a sample ASP.NET app with a publish profile added, as well as a simple builder.

Expected Behavior

It should deploy the ASP.NET app to the specified folder.

Actual Behavior

The build fails with the above exception.

Analysis

I am not entirely sure why this fails, as the relevant assemblies do appear to be loaded.
Dump.zip

Versions & Configurations

Visual Studio 2022 17.14.4
Bundled MSBuild version 17.14.10+8b8e13593 for .NET Framework 17.14.10.27608

Machine 1:
Windows 11 24H2 (26100.4349)
dotnet CLI 10.0.100-preview.5.25277.114
SDKs: 2.1.526 / 5.0.416 / 8.0.117 / 8.0.411 / 9.0.300 / 10.0.100-preview.5.25277.114

Machine 2:
Windows Server 2016 version 1607 (14393.7606)
dotnet CLI 9.0.301
SDKs: 2.1.526 / 9.0.301

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions