Aspnetcore.docs: ResolveCurrentProjectStaticWebAssetsInputsDependsOn -> MSB4057: The target "TypeScriptCompile" does not exist in the project.

Created on 26 Sep 2019  Â·  9Comments  Â·  Source: dotnet/AspNetCore.Docs

According to https://docs.microsoft.com/en-us/aspnet/core/razor-pages/ui-class?view=aspnetcore-3.0&tabs=visual-studio#create-an-rcl-with-static-assets I added <ResolveCurrentProjectStaticWebAssetsInputsDependsOn>TypeScriptCompile;$(ResolveCurrentProjectStaticWebAssetsInputs)</ResolveCurrentProjectStaticWebAssetsInputsDependsOn> but only get:

C:\Program Files\dotnet\sdk\3.0.100\Sdks\Microsoft.NET.Sdk.Razor\build\netstandard2.0\Microsoft.NET.Sdk.Razor.StaticWebAssets.targets(266,61): error MSB4057: The target "TypeScriptCompile" does not exist in the project.

This single xy.ts file perfectly compiles to wwwroot\xy.js but only gets included after second build -- which CI of course does not.

What is missing? Entire csproj file below:

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

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <RazorLangVersion>3.0</RazorLangVersion>
  </PropertyGroup>

  <PropertyGroup>
    <TypeScriptTarget>es2017</TypeScriptTarget>
    <!--<TypeScriptStrict>true</TypeScriptStrict>-->
    <TypeScriptAlwaysStrict>true</TypeScriptAlwaysStrict>
    <TypeScriptPreserveConstEnums>true</TypeScriptPreserveConstEnums>
    <TypeScriptNoEmitOnError>true</TypeScriptNoEmitOnError>
    <TypeScriptRemoveComments>true</TypeScriptRemoveComments>
    <TypeScriptOutDir>wwwroot</TypeScriptOutDir>

    <!-- see https://docs.microsoft.com/en-us/aspnet/core/razor-pages/ui-class?view=aspnetcore-3.0&tabs=visual-studio#create-an-rcl-with-static-assets -->
    <ResolveCurrentProjectStaticWebAssetsInputsDependsOn>TypeScriptCompile;$(ResolveCurrentProjectStaticWebAssetsInputs)</ResolveCurrentProjectStaticWebAssetsInputsDependsOn>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="3.0.0" />
    <PackageReference Include="Microsoft.TypeScript.MSBuild" Version="3.6.3">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
  </ItemGroup>

</Project>

Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

P1 Source - Docs.ms doc-bug

All 9 comments

From @javiercn ...

@springy76 You need to have the typescript compiler package installed.

@javiercn What is "typescript compiler package" and what is PackageReference Include="Microsoft.TypeScript.MSBuild" Version="3.6.3" then?

The ts>js compilation is working fine, but the static files are missing (404 in browser) after a clean build (as CI systems do) -- only after second build everything is fine.

@springy76 That should be the one.

There exists a target named "CompileTypeScript" (found by the use of dotnet msbuild -pp) but if I use this inside ResolveCurrentProjectStaticWebAssetsInputsDependsOn then the .js file still is missing in consuming BlazorServer project after first build and after second build everything is fine.

The output of dotnet msbuild -pp (and searching aspnetcore github repos) clearly shows that TypeScriptCompile are items within an <ItemGroup> and CompileTypeScript is a msbuild target.

So the code on docs is wrong and should be like this:

<ResolveCurrentProjectStaticWebAssetsInputsDependsOn>
  CompileTypeScript;
  $(ResolveCurrentProjectStaticWebAssetsInputs)
</ResolveCurrentProjectStaticWebAssetsInputsDependsOn>

But for (Ctrl+)F5 inside VS (2019) this seems not to be working correctly, even in combination with webHostBuilder.UseStaticWebAssets(); -- maybe it works when executing "publish".

CompileTypeScript instead of TypeScriptCompile got rid of the nasty target not found, thank you @springy76 for that!
In regards to the assets I see that when building in Debug a file {yourWebProjectName}.StaticWebAssets.xml is put next to the DLL files.
In this file I see that it seems to be using some sort of symlinks to the files,

<StaticWebAssets Version="1.0">
  <ContentRoot BasePath="/Identity" Path="C:\Users\usr\.nuget\packages\microsoft.aspnetcore.identity.ui\3.0.0\staticwebassets\V4" />
  <ContentRoot BasePath="_content/Web.RCL" Path="D:\projects\temp\Web.RCL\wwwroot\" />
</StaticWebAssets>

but in any case the <script src="_content/Web.RCL/app.js"></script> seems to work fine.

@Rick-Anderson Can we update the docs to use CompileTypeScript intead of TypeScriptCompile? This might have been an overlook on my part.

@javiercn The VS experience with the correct setting is still very meh: Publishing works fine but the developer-every-day-use is a PITA. If you have luck then after a Rebuild you only have to do a normal Build afterwards to get the missing pieces from wwwroot get compiled into the assemblies. But sometimes after a Rebuild the wwwroot folder is still missing and so the Build afterwards just does nothing, leaving the final app broken because essential .js/.css files are just missing.
Is this something I should report elsewhere?

@springy76 I would file an issue in the asp.net core repo with a link to a github repo containing a minimal repro project and detailed steps that describe the issue you are facing. That'll help us understand the scenario and evaluate what we can do about it.

Was this page helpful?
0 / 5 - 0 ratings