(With Visual Studio 17.14.13) Steps to reproduce (sorry this is a bit long but these are the fewest steps I could find):
- From the command line, create the solution folder:
md test1cd test1
- Create an empty solution:
dotnet new sln --name test1 --format slnx
- Create a razor class library project:
dotnet new razorclasslib -n test1 -o .
- Add the razor class library project to solution:
dotnet sln add test1.csproj
- Add TypeScript support:
npm install typescript --save-dev
- Open the
test1solution. - Add a typescript file to the
test1project:- Right-click
test1project and select "Add | New Item" - Select "Web | Scripts" on the left.
- Select "TypeScript File" on the right.
- Click "Add" to use the default name of "file1.ts".
- Add the following TypeScript code to "file1.ts":
export function showAlert(message: string): void { alert(message); } - Right-click
- Add the typescript NuGet package to the "test1.csproj" project file:
<PackageReference Include="Microsoft.TypeScript.MSBuild" Version="5.9.2"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> </PackageReference> - Add a
tsconfig.jsonconfiguration file to the root of the project.
(Menu item is under Add -> New Item, C# Items -> Web -> Scripts -> TypeScript JSON Configuration File.)
The file contents are:{ "compilerOptions": { "target": "ES6", "module": "ES6", "outDir": "./wwwroot/js", "strict": true }, "include": [ "*.ts" ] }
Build/Rebuild
Now select "Build | Rebuild test1" twice.
The first rebuild succeeds, but the second rebuild results in an error message:
System.InvalidOperationException: No file exists for the asset at either location 'D:code\test1\wwwroot\js\file1.js' or 'wwwroot\js\file1.js'. at Microsoft.AspNetCore.StaticWebAssets.Tasks.StaticWebAsset.ResolveFile(String identity, String originalItemSpec) at Microsoft.AspNetCore.StaticWebAssets.Tasks.DefineStaticWebAssets.ResolveFileDetails(String originalItemSpec, String identity) at Microsoft.AspNetCore.StaticWebAssets.Tasks.DefineStaticWebAssets.Execute()
I can then repeatedly select "Build | Rebuild test1" and it will fail on alternate rebuilds.
My questions are:
- What have I done wrong?
- How do I fix it?
- Can anyone else even reproduce this?