The "StaticWebAssetsGeneratePackManifest" task failed unexpectedly Asp.Net Web Application MVC

Anonymous
2023-03-27T11:17:07.9766667+00:00
hi,

I have created an ASP.net core web application MVC using VS 2022, I have not added any code or any package, and when I try to build the project as soon as it's created I encounter the below error.

Severity	Code	Description	Project	File	Line	Suppression State 

Error	MSB4018	The "StaticWebAssetsGeneratePackManifest" task failed unexpectedly. 

System.TypeInitializationException: The type initializer for 'Microsoft.AspNetCore.Razor.Tasks.StaticWebAssetsGeneratePackManifest' threw an exception. ---> System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. 

   at Microsoft.AspNetCore.Razor.Tasks.StaticWebAssetsGeneratePackManifest..cctor() 

   --- End of inner exception stack trace --- 

   at Microsoft.AspNetCore.Razor.Tasks.StaticWebAssetsGeneratePackManifest.PersistManifest(StaticWebAssetsPackManifest manifest) 

   at Microsoft.AspNetCore.Razor.Tasks.StaticWebAssetsGeneratePackManifest.Execute() 

   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() 

   at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()	AgilePointMiscConnector	C:\Program Files\dotnet\sdk\7.0.202\Sdks\Microsoft.NET.Sdk.Razor\targets\Microsoft.NET.Sdk.Razor.StaticWebAssets.Pack.targets	180	 


Developer technologies | Visual Studio | Other
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Tianyu Sun-MSFT 34,441 Reputation points Microsoft External Staff
    2023-03-28T05:37:31.62+00:00

    Hello @Anonymous ,

    Welcome to Microsoft Q&A forum.

    Please first try to create a new ASP .NET Core web application(MVC) again and check if the same error appears this time.

    If the same error appears, please try to reset VS(run devenv /ResetSettings in Developer Command Prompt for S 2022) and repair VS(VS Installer > More > Repair).

    If no error appears, please go back to your project, right-click the project > Unload Project > right-click it again > Edit Project File. In the .csproj file, make sure that there’s no assembly binding redirects(try to remove it if it exists). Remove the hidden .vs folder in your solution folder and rebuild your project.

    Besides, from the error message looks like the error may be caused by different versions of .NET/targeted framework.

    Can you confirm that your machine has .net 6 and .net 7 installed(run dotnet --list-sdks in CMD), and in VS Installer > Modify > Individual components > .NET 6.0 Runtime and .NET 7.0 Runtime have been checked?

    Feel free to let us know the results.

    Sincerely,

    Tianyu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.