Authorization - MSB4018 The "GenerateStaticWebAssetsPropsFile: task failed unexpectedly

Dean Everhart 1,536 Reputation points
2023-04-11T16:50:10.4266667+00:00

Creating a project which has individual User Accounts Authorization...

Steps.

  1. In the Authentication type input, select Individual User Accounts
  2. Update-Database
  3. Error...
Severity	Code	Description	Project	File	Line	Suppression State
Error	MSB4018	The "GenerateStaticWebAsssetsPropsFile" task failed unexpectedly.
System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Users\User1\Desktop\_Tech\Net\_Contoso University\ContosoUniversity - Authorization\ContosoUniversityAuthorization\ContosoUniversityAuthorization\obj\Debug\net6.0\staticwebassets\msbuild.ContosoUniversityAuthorization.Microsoft.AspNetCore.StaticWebAssets.props'.
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
   at System.IO.File.InternalWriteAllBytes(String path, Byte[] bytes, Boolean checkHost)
   at Microsoft.AspNetCore.Razor.Tasks.GenerateStaticWebAsssetsPropsFile.ExecuteCore()
   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()	ContosoUniversityAuthorization	C:\Program Files\dotnet\sdk\7.0.100\Sdks\Microsoft.NET.Sdk.Razor\targets\Microsoft.NET.Sdk.Razor.StaticWebAssets.Pack.targets	141	

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,400 questions
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,417 questions
{count} votes

Accepted answer
  1. Kurian, Jose 85 Reputation points
    2023-12-13T19:40:45.9133333+00:00

    I have the same issue.

    Issue:

    Issue is because of the very long file path where it is trying to write the outputs.

    In your case:

    "C:\Users\User1\Desktop_Tech\Net_Contoso University\ContosoUniversity - Authorization\ContosoUniversityAuthorization\ContosoUniversityAuthorization\obj\Debug\net6.0\staticwebassets\msbuild.ContosoUniversityAuthorization.Microsoft.AspNetCore.StaticWebAssets.props"

    Work arounds:

    a) Make the project name shorter, or

    b) move it to a folder with shorter names.

    I confirmed this by opening and debugging the VS solution that I have in a folder path that is shorter.

    Solution:

    This problem started with the Visual Studio update. Hopefully MS Visual Studio team addresses this at root cause.

    2 people found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more