Skip to content
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

Intermittent Error on Build #57147

Closed
vsfeedback opened this issue Aug 2, 2024 · 21 comments
Closed

Intermittent Error on Build #57147

vsfeedback opened this issue Aug 2, 2024 · 21 comments
Labels
area-blazor Includes: Blazor, Razor Components Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. Needs: Repro Indicates that the team needs a repro project to continue the investigation on this issue

Comments

@vsfeedback
Copy link

This issue has been moved from a ticket on Developer Community.


[severity:It's more difficult to complete my work]
I am getting an intermittent error on building my solution and the error states that a sepcific css file is missing but when i check it does exist on disk. The following is the error in the Error Window of Visual Studio...

Severity Code Description Project File Line Suppression State Details
Error (active) System.InvalidOperationException: No file exists for the asset at either location 'wwwroot\css\dx-reporting-skeleton-screen.css' or 'wwwroot\css\dx-reporting-skeleton-screen.css'.
at Microsoft.AspNetCore.StaticWebAssets.Tasks.StaticWebAsset.ComputeFingerprintAndIntegrity(String identity, String originalItemSpec)
at Microsoft.AspNetCore.StaticWebAssets.Tasks.DefineStaticWebAssets.Execute() Opg.Business.Web.Ui.Realty.Portal C:\Program Files\dotnet\sdk\9.0.100-preview.5.24307.3\Sdks\Microsoft.NET.Sdk.StaticWebAssets\targets\Microsoft.NET.Sdk.StaticWebAssets.targets 597


Original Comments

Feedback Bot on 7/24/2024, 07:06 PM:

(private comment, text removed)


Original Solutions

(no solutions)

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-blazor Includes: Blazor, Razor Components label Aug 2, 2024
@halter73
Copy link
Member

halter73 commented Aug 2, 2024

@javiercn FYI

@javiercn
Copy link
Member

javiercn commented Aug 5, 2024

@halter73 this likely means the file is being added/deleted as part of the build process at the wrong time, hence sometimes its there, sometimes it isn't.

@javiercn javiercn added Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. Needs: Repro Indicates that the team needs a repro project to continue the investigation on this issue labels Aug 5, 2024
@ray440
Copy link

ray440 commented Aug 14, 2024

This is happening to me too.

System.InvalidOperationException: No file exists for the asset at either location 'wwwroot\foo.js' or 'wwwroot\foo.js'.
   at Microsoft.AspNetCore.StaticWebAssets.Tasks.StaticWebAsset.ComputeFingerprintAndIntegrity(String identity, String originalItemSpec)
   at Microsoft.AspNetCore.StaticWebAssets.Tasks.DefineStaticWebAssets.Execute()

Edit: looks like VS was not compiling ts -> js files. Seems to be fixed now.

@drmcclelland
Copy link

This started happening to me as well after .NET 9 was released. I upgraded to Visual Studio 2022 v17.12.0, and tried compiling a .NET 8 ASP.NET MVC Core project (which started being compiled by the latest .NET 9 SDK):

C:\Program Files\dotnet\sdk\9.0.100\Sdks\Microsoft.NET.Sdk.StaticWebAssets\targets\Microsoft.NET.Sdk.StaticWebAssets.targets(662,5): error : System.InvalidOperationException: No file exists for the asset at either location 'wwwroot\css\multiStepIndicator.min.css' or 'wwwroot\css\multiStepIndicator.min.css'.
C:\Program Files\dotnet\sdk\9.0.100\Sdks\Microsoft.NET.Sdk.StaticWebAssets\targets\Microsoft.NET.Sdk.StaticWebAssets.targets(662,5): error :    at Microsoft.AspNetCore.StaticWebAssets.Tasks.StaticWebAsset.ComputeFingerprintAndIntegrity(String identity, String originalItemSpec)
C:\Program Files\dotnet\sdk\9.0.100\Sdks\Microsoft.NET.Sdk.StaticWebAssets\targets\Microsoft.NET.Sdk.StaticWebAssets.targets(662,5): error :    at Microsoft.AspNetCore.StaticWebAssets.Tasks.DefineStaticWebAssets.Execute()

Workaround:

  1. I downloaded the latest .NET 8 SDK (as of now v8.0.404)
  2. Added a global.json at the root level of my C# solution with the following content:
{
  "sdk": {
    "version": "8.0.404",
    "rollForward": "latestPatch"
  }
}

@sandeepksharma15
Copy link

{
"sdk": {
"version": "8.0.404",
"rollForward": "latestPatch"
}
}

This solution works! As long as the right SDK is installed on the system :-) Thanks

@fmir864
Copy link

fmir864 commented Nov 25, 2024

I can confirm this happening again after VS 17.12 update. @drmcclelland solution fixed.

@jeffdahlcorpay
Copy link

Still an issue with VS 17.12.2

@VictorioBerra
Copy link
Contributor

Hitting this with VS Version 17.12.3

@tkardaridis
Copy link

Still an issue with VS 17.12.3

@Elimi81
Copy link

Elimi81 commented Dec 4, 2024

The issue is not resolved, still happens in VS 17.12.3.

Started after installing .net 9 SDK as others mentioned.

@buist-sharris
Copy link

Just updated VS from 17.11.x to 17.12.3 and now running into this as well (and there's nothing intermittent about it).

The solution did not work initially. "Unable to resolve the .NET SDK version as specified in the global.json located at \global.json". Installed the 8.0.404 sdk and it's now working.

Is there an easy way to just roll back VS to an unbroken version? Workarounds and hacks have a tendency to get buried and lost and become like stray cats that never leave.

@ighristov
Copy link

Reproducing it intermittently with latest .NET 9 SDK 9.0.101 and I think I understood what causes it.
The issue is not reproducible with .NET 8 SDK - uninstalled .NET 9 SDK several times to confirm this.

In my scenario the exception is thrown during execution of a MSBuild task in a MSBuild project file. The project file is started from console - not using Visual Studio at all. The exception is thrown when bundling and minifying a bunch of .js files using the BuildBundlerMinifier package.

The exception is thrown every second time when executing the MSBuild task. So it passes one time, then fails next time, then passes again third time and so on. The problem on my end seems to be caused by the contents of the .\wwwroot\js\bundles folder where the bundled assets are copied after processing the BundlerMinifier.BundlerBuildTask. If the .\wwwroot\js\bundles folder is not empty when the build is started, the build fails when it gets to the ResolveProjectStaticWebAssets task:

(ResolveProjectStaticWebAssets target) ->
  C:\Program Files\dotnet\sdk\9.0.101\Sdks\Microsoft.NET.Sdk.StaticWebAssets\targets\Microsoft.NET.Sdk.StaticWebAssets.targets(662,5): error : System.InvalidOperationException: No file exists for the asset at either location 'wwwroot\js\bundles\accessibility.js' or 'wwwroot\js\bundles\accessibility.js'. [D:\Work\my-project-path.csproj] 
  C:\Program Files\dotnet\sdk\9.0.101\Sdks\Microsoft.NET.Sdk.StaticWebAssets\targets\Microsoft.NET.Sdk.StaticWebAssets.targets(662,5): error :    at Microsoft.AspNetCore.StaticWebAssets.Tasks.StaticWebAsset.ComputeFingerprintAndIntegrity(String identity, String originalItemSpec) [D:\Work\my-project-path.csproj]
C:\Program Files\dotnet\sdk\9.0.101\Sdks\Microsoft.NET.Sdk.StaticWebAssets\targets\Microsoft.NET.Sdk.StaticWebAssets.targets(662,5): error :    at Microsoft.AspNetCore.StaticWebAssets.Tasks.DefineStaticWebAssets.Execute() [D:\Work\my-project-path.csproj]

The strange thing is that the .\wwwroot\js\bundles folder gets cleaned even when the build has failed - that's why it passes the next time I started it. So in my scenario the workaround is to manually delete the folder .\wwwroot\js\bundles folder before starting the build.

Hope this helps.

@ltctech
Copy link

ltctech commented Dec 7, 2024

I am using webpack 5 and had the same error with bundled files.

I added a dependency on ResolveBuildRelatedStaticWebAssets by looking through the targets in the source:

https://github.com/dotnet/sdk/blob/main/src/StaticWebAssetsSdk/Targets/Microsoft.NET.Sdk.StaticWebAssets.targets

This is my csproj and now it works for the time being. It'll likely be broken when they get around to fixing this bug:

  <PropertyGroup>
    <ResolveBuildRelatedStaticWebAssetsDependsOn>
      ReleaseBuildClientApp;$(ResolveBuildRelatedStaticWebAssetsDependsOn)
    </ResolveBuildRelatedStaticWebAssetsDependsOn>
  </PropertyGroup>

  <!-- As part of release build, ensure the JS resources are freshly built in production mode -->
  <!-- Runs before compile as webpack layout template is cshtml and needs to be compiled by .NET -->
  <Target Name="ReleaseBuildClientApp" Condition=" '$(Configuration)' == 'Release' And '$(DeployOnBuild)' != 'true' ">
    <!-- Ensure Node.js is installed -->
    <Exec Command="node --version" ContinueOnError="true">
      <Output TaskParameter="ExitCode" PropertyName="ErrorCode" />
    </Exec>
    <Error Condition="'$(ErrorCode)' != '0'" Text="Node.js is required to build and run this project. To continue, please install Node.js from https://nodejs.org/, and then restart your command prompt or IDE." />
    <Message Importance="high" Text="ClientApp production build started!" />
    <Exec WorkingDirectory="$(SpaRoot)" Command="npm install" />
    <Exec WorkingDirectory="$(SpaRoot)" Command="npm run prod" />
    <Message Importance="high" Text="ClientApp production build ended!" />
  </Target>

@pspro0305
Copy link

Same issue exists in VS 17.12.3 using .Net SDK 9.0.101, the exception is thrown when bundling and minifying a bunch of .js files using the BuildBundlerMinifier package as @ighristov mentioned. Workaround is to manually delete the folders everytime before build.
Let me know if anyone has found the fix for this.

@IndigoHealth
Copy link

I just discovered that the problem happens consistently if I "rebuild" the solution. It does not happen if I just build the solution. That's a workaround of sorts...

@Scanixx
Copy link

Scanixx commented Jan 6, 2025

I found a solution here

Set PrepareForBuildDependsOn as following:

<PropertyGroup>
<PrepareForBuildDependsOn>BundleMinify;$(PrepareForBuildDependsOn)</PrepareForBuildDependsOn>
</PropertyGroup>

@onetsmr
Copy link

onetsmr commented Jan 6, 2025

The same issue after updating to latest VS 2022 (17.12.3). And solution with sdk version in global.json doesn't work for me. It's ignored.

@michaeldevenney
Copy link

The solution @Scanixx linked to on the VS Developer Community site worked for me without so much as a restart. Simply pasted that snippet into my web project, saved it and off we went, rebuilding happily.

@tomhonour
Copy link

tomhonour commented Feb 13, 2025

<PrepareForBuildDependsOn>WebCompile</PrepareForBuildDependsOn> solved this for me.

There's something weird going on. WebCompileClean happens during the rebuild which means there's no .css file (hence the error). After the rebuild errors, the .css file is created again through some binding (maybe the WebCompiler VS extension), so it looks like it always existed. If you watch the the .css file in the file explorer closely, you'll see it momentarily disappear (cleaned and then created).

@rahulsaini09
Copy link

rahulsaini09 commented Feb 13, 2025

Add below line in .csproj file
BundleMinify;$(PrepareForBuildDependsOn)
and you are all set to rebuild your project.

Image net6.0 disable enable BundleMinify;$(PrepareForBuildDependsOn)

@tomtheisen
Copy link

None of the solutions in this thread helped me. Here's the evil incantation I came up with. Maybe it will help you. Maybe it will not.

    <Target Name="PreResolveProjectStaticWebAssets" BeforeTargets="ResolveProjectStaticWebAssets">
        <ItemGroup>
            <StashedContent Include="@(Content)" />
            <Content Remove="@(Content)" />
        </ItemGroup>
    </Target>
    <Target Name="PostResolveProjectStaticWebAssets" AfterTargets="ResolveProjectStaticWebAssets">
        <ItemGroup>
            <Content Include="@(StashedContent)" />
        </ItemGroup>
    </Target>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. Needs: Repro Indicates that the team needs a repro project to continue the investigation on this issue
Projects
None yet
Development

No branches or pull requests