Skip to content

MSB4018 on Blazor WASM with .NET 9.0.300 #49039

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
MRT-77 opened this issue May 18, 2025 · 11 comments
Open

MSB4018 on Blazor WASM with .NET 9.0.300 #49039

MRT-77 opened this issue May 18, 2025 · 11 comments
Assignees
Labels
Area-AspNetCore RazorSDK, BlazorWebAssemblySDK, dotnet-watch untriaged Request triage from a team member

Comments

@MRT-77
Copy link

MRT-77 commented May 18, 2025

Describe the bug

After upgrading Visual Studio to version 17.14.0, I started encountering this issue.
To resolve it, I first performed a Repair using the Visual Studio Installer, but the problem persisted.

For further troubleshooting, I completely uninstalled Visual Studio and installed only the .NET SDK manually.
Then, I installed the required workloads using the CLI. However, even after creating a clean Blazor WebAssembly project and building it, the same error still occurred.

However, I was able to temporarily work around the problem by manually installing .NET SDK 9.0.204 after reinstalling Visual Studio, and then deleting the folder C:\Program Files\dotnet\sdk\9.0.300.
This resolved the build error both in Visual Studio and when using the CLI.

To Reproduce

  1. Install .Net SDK 9.0.300
  2. Install Workload dotnet workload install wasm-tools
  3. Create New Project dotnet new blazorwasm -o _MyCleanApp --framework net9.0
  4. Just Build

Exceptions

Restore complete (0.5s)
  _MyCleanApp failed with 1 error(s) (0.3s)
    C:\Program Files\dotnet\sdk\9.0.300\Sdks\Microsoft.NET.Sdk.BlazorWebAssembly\targets\Microsoft.NET.Sdk.BlazorWebAssembly.6_0.targets(125,5): error MSB4018:
      The "DefineStaticWebAssetEndpoints" task failed unexpectedly.
      System.AggregateException: One or more errors occurred. (Last write time for 'D:\_MyCleanApp\bin\Debug\net9.0\wwwroot\_framework\blazor.webassembly.js' is not defined.)
       ---> System.InvalidOperationException: Last write time for 'D:\_MyCleanApp\bin\Debug\net9.0\wwwroot\_framework\blazor.webassembly.js' is not defined.
         at Microsoft.AspNetCore.StaticWebAssets.Tasks.StaticWebAsset.Validate()
         at Microsoft.AspNetCore.StaticWebAssets.Tasks.StaticWebAsset.FromTaskItem(ITaskItem item)
         at Microsoft.AspNetCore.StaticWebAssets.Tasks.DefineStaticWebAssetEndpoints.ParallelWorker.Process(Int32 i, ParallelLoopState _)
         at Microsoft.AspNetCore.StaticWebAssets.Tasks.DefineStaticWebAssetEndpoints.<>c.<Execute>b__16_2(Int32 i, ParallelLoopState loop, ParallelWorker state)
         at System.Threading.Tasks.Parallel.<>c__DisplayClass19_0`2.<ForWorker>b__1(RangeWorker& currentWorker, Int64 timeout, Boolean& replicationDelegateYieldedBeforeCompletion)
      --- End of stack trace from previous location ---
         at System.Threading.Tasks.Parallel.<>c__DisplayClass19_0`2.<ForWorker>b__1(RangeWorker& currentWorker, Int64 timeout, Boolean& replicationDelegateYieldedBeforeCompletion)
         at System.Threading.Tasks.TaskReplicator.Replica.Execute()
         --- End of inner exception stack trace ---
         at System.Threading.Tasks.TaskReplicator.Run[TState](ReplicatableUserAction`1 action, ParallelOptions options, Boolean stopOnFirstFailure)
         at System.Threading.Tasks.Parallel.ForWorker[TLocal,TInt](TInt fromInclusive, TInt toExclusive, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState, Func`4 bodyWithLocal, Func`1 localInit, Action`1 localFinally)
      --- End of stack trace from previous location ---
         at System.Threading.Tasks.Parallel.ForWorker[TLocal,TInt](TInt fromInclusive, TInt toExclusive, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState, Func`4 bodyWithLocal, Func`1 localInit, Action`1 localFinally)
         at System.Threading.Tasks.Parallel.For[TLocal](Int32 fromInclusive, Int32 toExclusive, Func`1 localInit, Func`4 body, Action`1 localFinally)
         at Microsoft.AspNetCore.StaticWebAssets.Tasks.DefineStaticWebAssetEndpoints.Execute()
         at Microsoft.Build.BackEnd.TaskExecutionHost.Execute()
         at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(TaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask)

Build failed with 1 error(s) in 1.0s

Further technical details

.NET SDK:
 Version:           9.0.300
 Commit:            15606fe0a8
 Workload version:  9.0.300-manifests.87b8cca8
 MSBuild version:   17.14.5+edd3bbf37

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.26100
 OS Platform: Windows
 RID:         win-x64
 Base Path:   C:\Program Files\dotnet\sdk\9.0.300\

.NET workloads installed:
 [wasm-tools]
   Installation Source: VS 17.14.36109.1
   Manifest Version:    9.0.5/9.0.100
   Manifest Path:       c:\program files\dotnet\sdk-manifests\9.0.100\microsoft.net.workload.mono.toolchain.current\9.0.5\WorkloadManifest.json
   Install Type:              Msi

Configured to use loose manifests when installing new manifests.

Host:
  Version:      9.0.5
  Architecture: x64
  Commit:       e36e4d1a8f

.NET SDKs installed:
  9.0.204 [C:\Program Files\dotnet\sdk]
  9.0.300 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 8.0.16 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 9.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 8.0.16 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 9.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 8.0.16 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 9.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
  x86   [C:\Program Files (x86)\dotnet]
    registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
  Not set

global.json file:
  Not found
@dotnet-policy-service dotnet-policy-service bot added the untriaged Request triage from a team member label May 18, 2025
@PerseusTheGreat
Copy link

Under similar circumstances, I am encountering similar errors across all my ASP.NET Core Razor Class Libraries that include MVC .cshtml files. The errors seem to be associated with each <link> to static files, such as .css, within _Layout.cshtml. It appears that the new .NET 9.0 static asset delivery optimization treats all .cshtml files as if they were Blazor .razor components!"

@baronfel baronfel added the Area-AspNetCore RazorSDK, BlazorWebAssemblySDK, dotnet-watch label May 18, 2025
@baronfel
Copy link
Member

Cc @javiercn

@javiercn
Copy link
Member

@MRT-77 can you provide a binlog/repro so that we can take a look?

@javiercn javiercn self-assigned this May 19, 2025
@aminmashayekhi
Copy link

I just created a new Blazor Web App in Visual Studio with default settings and ran it, but the error occurred!

@MRT-77
Copy link
Author

MRT-77 commented May 20, 2025

R: @javiercn
As I mentioned earlier, you can easily check this error by using visual studio blazor project templates or the dotnet new blazorwasm -o _MyCleanApp --framework net9.0 command. No extra code is needed.

@hyspdrt
Copy link

hyspdrt commented May 21, 2025

I think this might be related to blazor/razor component error, but only on non-windows

#49038

@itoledo
Copy link

itoledo commented May 22, 2025

rolling back to 9.0.204 using global.json allows it to compile. also with plain asp.net core web site, not only with blazor. Happens to me in Windows.

@MRT-77
Copy link
Author

MRT-77 commented May 23, 2025

I was curious so I tested it on Ubuntu 24.04 LTS WSL2 and the build was completed without errors.

install instruction:

wget https://dot.net/v1/dotnet-install.sh -O dotnet-install.sh
chmod +x dotnet-install.sh
./dotnet-install.sh --version 9.0.300 --install-dir $HOME/dotnet

dotnet build output:

Restore complete (0.4s)
  _MyCleanApp succeeded (4.2s) → bin/Debug/net9.0/wwwroot

Build succeeded in 4.9s

@aminmashayekhi
Copy link

same issue with dotnet build and just one custom css in new asp.net core web app (razor pages):

PS D:\source\WebApplication4\WebApplication4> dotnet build
Restore complete (0/3s)
  WebApplication4 failed with 1 error(s) (0/2s)
    C:\Program Files\dotnet\sdk\9.0.300\Sdks\Microsoft.NET.Sdk.StaticWebAssets\targets\Microsoft.NET.Sdk.StaticWebAssets.targets(693,5): error MSB4018:
      The "DefineStaticWebAssetEndpoints" task failed unexpectedly.
      System.AggregateException: One or more errors occurred. (Last write time for 'D:\source\WebApplication4\WebApplica
      tion4\wwwroot\css\request-page.css' is not defined.) (Last write time for 'D:\source\WebApplication4\WebApplicatio
      n4\wwwroot\images\banner3.svg' is not defined.)
       ---> System.InvalidOperationException: Last write time for 'D:\source\WebApplication4\WebApplication4\wwwroot\css
      \request-page.css' is not defined.
         at Microsoft.AspNetCore.StaticWebAssets.Tasks.StaticWebAsset.Validate()
         at Microsoft.AspNetCore.StaticWebAssets.Tasks.StaticWebAsset.FromTaskItem(ITaskItem item)
         at Microsoft.AspNetCore.StaticWebAssets.Tasks.DefineStaticWebAssetEndpoints.ParallelWorker.Process(Int32 i, Par
      allelLoopState _)
         at Microsoft.AspNetCore.StaticWebAssets.Tasks.DefineStaticWebAssetEndpoints.<>c.<Execute>b__16_2(Int32 i, Paral
      lelLoopState loop, ParallelWorker state)
         at System.Threading.Tasks.Parallel.<>c__DisplayClass19_0`2.<ForWorker>b__1(RangeWorker& currentWorker, Int64 ti
      meout, Boolean& replicationDelegateYieldedBeforeCompletion)
      --- End of stack trace from previous location ---
         at System.Threading.Tasks.Parallel.<>c__DisplayClass19_0`2.<ForWorker>b__1(RangeWorker& currentWorker, Int64 ti
      meout, Boolean& replicationDelegateYieldedBeforeCompletion)
         at System.Threading.Tasks.TaskReplicator.Replica.Execute()
         --- End of inner exception stack trace ---
         at System.Threading.Tasks.TaskReplicator.Run[TState](ReplicatableUserAction`1 action, ParallelOptions options,
      Boolean stopOnFirstFailure)
         at System.Threading.Tasks.Parallel.ForWorker[TLocal,TInt](TInt fromInclusive, TInt toExclusive, ParallelOptions
       parallelOptions, Action`1 body, Action`2 bodyWithState, Func`4 bodyWithLocal, Func`1 localInit, Action`1 localFin
      ally)
      --- End of stack trace from previous location ---
         at System.Threading.Tasks.Parallel.ForWorker[TLocal,TInt](TInt fromInclusive, TInt toExclusive, ParallelOptions
       parallelOptions, Action`1 body, Action`2 bodyWithState, Func`4 bodyWithLocal, Func`1 localInit, Action`1 localFin
      ally)
         at System.Threading.Tasks.Parallel.For[TLocal](Int32 fromInclusive, Int32 toExclusive, Func`1 localInit, Func`4
       body, Action`1 localFinally)
         at Microsoft.AspNetCore.StaticWebAssets.Tasks.DefineStaticWebAssetEndpoints.Execute()
         at Microsoft.Build.BackEnd.TaskExecutionHost.Execute()
         at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(TaskExecutionHost taskExecutionHost, TaskLogging
      Context taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask)
       ---> (Inner Exception #1) System.InvalidOperationException: Last write time for 'D:\source\WebApplication4\WebApp
      lication4\wwwroot\images\banner3.svg' is not defined.
         at Microsoft.AspNetCore.StaticWebAssets.Tasks.StaticWebAsset.Validate()
         at Microsoft.AspNetCore.StaticWebAssets.Tasks.StaticWebAsset.FromTaskItem(ITaskItem item)
         at Microsoft.AspNetCore.StaticWebAssets.Tasks.DefineStaticWebAssetEndpoints.ParallelWorker.Process(Int32 i, Par
      allelLoopState _)
         at Microsoft.AspNetCore.StaticWebAssets.Tasks.DefineStaticWebAssetEndpoints.<>c.<Execute>b__16_2(Int32 i, Paral
      lelLoopState loop, ParallelWorker state)
         at System.Threading.Tasks.Parallel.<>c__DisplayClass19_0`2.<ForWorker>b__1(RangeWorker& currentWorker, Int64 ti
      meout, Boolean& replicationDelegateYieldedBeforeCompletion)
      --- End of stack trace from previous location ---
         at System.Threading.Tasks.Parallel.<>c__DisplayClass19_0`2.<ForWorker>b__1(RangeWorker& currentWorker, Int64 ti
      meout, Boolean& replicationDelegateYieldedBeforeCompletion)
         at System.Threading.Tasks.TaskReplicator.Replica.Execute()<---


Build failed with 1 error(s) in 1/2s

@csarigul
Copy link

@javiercn
I also faced with variety of those StaticWebAssets issues.
In the end, I found out it's simply static caching issue cause by StaticWebAssets.

Running dotnet clean or using Visual Studio's Clean Solution does not remove the StaticAsset cache file (rpswa.dswa.cache.json) located in the obj directory.

Workaround:
Simply remove "obj" folder under project, than it should compiled fine.

Especially, when you checkout to another branch and you had different web assets, then you must delete "obj" folder once again. Otherwise, you will face "xxx.js" is not defined ... etc.

Hopefully, it would be patched in future

I also created an issue about it :
#49082

@PerseusTheGreat
Copy link

#49101

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-AspNetCore RazorSDK, BlazorWebAssemblySDK, dotnet-watch untriaged Request triage from a team member
Projects
None yet
Development

No branches or pull requests

8 participants