dotnet / dotnet/sdk

InvalidOperationException REBUILD fails due to "no file exists for the asset at either location" BUILD works fine though - and the file does exist

Open
#50,489 5 comments 1 reaction 0 assignees View on GitHub
Area-AspNetCore needs-info untriaged waiting-on-feedback
Dominant language
C#
Stars
3.2k
Forks
1.3k
PR merge metrics
PR metrics pending

Description

_This issue has been moved from [a ticket on Developer Community](https://developercommunity.visualstudio.com/t/InvalidOperationException-REBUILD-fails-/10799774)._

---
[severity:It's more difficult to complete my work] [regression] [worked-in:17.11]
After upgrading to Visual Studio 17.12, several members of my team have reported an issue whereby one of our projects won't **Rebuild**. However, Clean + **Build** works.

Until today, I hadn't seen the issue myself. Now I am getting the same thing (I'm now on 17.12.1).

I am seeing the following output when attempting to Rebuild the project (some project details replaced):

```
12>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\js\site.js' or 'wwwroot\js\site.js'.
12>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)
12>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()
12>Done building project "XXXXX.Web.csproj" -- FAILED.
```

This also appears in the Errors list:

```
Severity Code Description Project File Line Suppression State
Error (active) System.InvalidOperationException: No file exists for the asset at either location 'wwwroot\js\site.js' or 'wwwroot\js\site.js'.
at Microsoft.AspNetCore.StaticWebAssets.Tasks.StaticWebAsset.ComputeFingerprintAndIntegrity(String identity, String originalItemSpec)
at Microsoft.AspNetCore.StaticWebAssets.Tasks.DefineStaticWebAssets.Execute() XXXXX.Web C:\Program Files\dotnet\sdk\9.0.100\Sdks\Microsoft.NET.Sdk.StaticWebAssets\targets\Microsoft.NET.Sdk.StaticWebAssets.targets 662
```

The error appears to be complaining about a missing file, but that file is definitely present:

![image.png](https://aka.ms/dc/image?name=B49b9db67a5cc4550b860f04eca070be7638682097364929984_20241126-092215-image.png&tid=49b9db67a5cc4550b860f04eca070be7638682097364929984)

The project is a . NET8 web project.

The site.js file is actually only 9 lines long and is standard JavaScript/ECMAScript 5.

The following Feedback item seems related, but has been closed as a duplicate (however, the duplicate hasn't been linked, so I can't see any more information):
https://developercommunity.visualstudio.com/t/Getting-build-error-after-VS-update/10788892?sort=newest

A colleague of mine has pointed to the following GitHub issue for ASP.NET Core that may or may not be related:
https://github.com/dotnet/aspnetcore/issues/58948

---
### Original Comments

#### Feedback Bot on 11/27/2024, 02:29 AM:

We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.

#### Gerhard Herre on 11/30/2024, 06:00 PM:

Hello Oliver,


i had a similar problem, that “Clean Project” + Build worked fine but “Rebuild Solution” failed with

an error “no file exists app.min.css”.


I am using BuildWebCompiler2022 and BuildBundlerMinifier2022 to create this file and

BundlerMinifier, even loaded as Extension and bundleconfig.json marked as part of the build-process,

is not run before the Build-process.

I could solve this topic by adding to my csproj-file:

<PropertyGroup>

<PrepareForBuildDependsOn>

BundleMinify;

</PrepareForBuildDependsOn>

</PropertyGroup>


Are you really sure that site.js exists at the beginning of the MS-Build-job, right after Clean Solution

or is it created by some PreBuild-processor, like in my case?


best regards

Gerhard

#### Oliver Clare on 12/2/2024, 09:58 AM:

Hi Gerhard Herre, thanks for the comment and suggestion.


We have tried using the PrepareForBuildDependsOn property during our investigation into this issue. However, it did not solve the problem. This is most likely because the site.js file Rebuild is complaining about is the actual source file.


We do use Web Compiler and Bundler & Minifier, and for that project, the site.js is being minified. There are also other web projects in the solution that are not having a compilation issue on Rebuild. Therefore, it is possible there is something specific about this project’s config that is causing the issue.


Rebuild worked fine until VS 17.12 and we made no changes to the project config, hence our assumption that something in the VS upgrade caused the issue. But your suggestion that this might be something to do with a build process seems like it could be along the right lines. We will spend some more time looking into this and I’ll report back if we find a solution.

#### U_1407084 on 12/2/2024, 10:05 AM:

Hi, in my case using PrepareForBuildDependsOn works


<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BuildBundlerMinifier2022" Version="2.9.11" />
</ItemGroup>

<PropertyGroup>
<PrepareForBuildDependsOn>
BundleMinify;
</PrepareForBuildDependsOn>
</PropertyGroup>

</Project>


https://github.com/failwyn/BundlerMinifier/issues/41

#### Phil Johnson on 1/27/2025, 04:23 PM:

I had the same problem. I’m not impressed that a new visual studio 2022 update introduces a problem that takes hours to understand and which without this post, I would not have understood it, I would have just removed all my .min.css and .min.js files from my solution. Thanks for posting.

#### Gianfranco Percopo on 1/31/2025, 01:31 PM:

Thanks thanks thanks to Oliver Clare. You save me! Thanks a lot…

#### U_1446445 on 3/13/2025, 03:04 PM:

Thanks Oliver!

#### Tony Bolton on 8/5/2025, 04:59 PM:

Thanks @Oliver Clare - saved me a major headache!

---
### Original Solutions

#### Oliver Clare solved on 12/2/2024, 00:00 PM, undefined votes:

After a second attempt at the PrepareForBuildDependsOn update, the following solution has now worked:


<PropertyGroup>  

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

As such, I no longer think this is a Visual Studio issue.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.