-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Cannot have colocated javascript when using typescript and asp.net razor pages app. #41921
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
Comments
@solrevdev thanks for contacting us. The likely case for this is that you are not integrating your build pipeline with static web assets. The first build happens without the content being present and the content gets generated. The second time the build happens the content is already there, so it gets detected and when you do the build, it gets added again, so it gets duplicated. The best way to solve this is to put some code in your project file to make sure static web assets is able to pick up your content. <PropertyGroup>
<PrepareForBuildDependsOn><<your-targets>>;$(PrepareForBuildDependsOn)</PrepareForBuildDependsOn>
</PropertyGroup> Should make your targets run early enough to prevent this from happening. |
We do have designs to make this integration easier in a future release here so we are closing this issue as a dupe as we are keeping track on the mentioned issue. |
@javiercn Thanks for replying. I assume there is a typo there somewhere as I get dotnet build
Microsoft (R) Build Engine version 17.2.0+41abc5629 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.
dotnetissue.csproj(18,32): error MSB4025: The project file could not be loaded. Name cannot begin with the '<' character, hexadecimal value 0x3C. Line 18, position 32.
Build FAILED.
/Users/solrevdev/Desktop/dotnetissue/dotnetissue.csproj(18,32): error MSB4025: The project file could not be loaded. Name cannot begin with the '<' character, hexadecimal value 0x3C. Line 18, position 32.
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:00.07 |
@solrevdev You need to replace |
Sorry I'm really not sure I understand, I don't set any targets or use any tools. Well no, that's not true, I do include TypeScript and BuildBundlerMinifier perhaps you mean these? <PackageReference Include="BuildBundlerMinifier" Version="3.2.449" />
<PackageReference Include="Microsoft.TypeScript.MSBuild" Version="4.7.2"> Aha, OK, So, I've got it to build consistently by adding something I copied from another one of your replies to another issue. It works, but I'm not that confident I fully understand what is going on. <PropertyGroup>
<PrepareForBuildDependsOn>GetTypeScriptOutputForPublishing;$(PrepareForBuildDependsOn)</PrepareForBuildDependsOn>
</PropertyGroup> So my <Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="BuildBundlerMinifier" Version="3.2.449" />
<PackageReference Include="Microsoft.TypeScript.MSBuild" Version="4.7.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<PropertyGroup>
<PrepareForBuildDependsOn>GetTypeScriptOutputForPublishing;$(PrepareForBuildDependsOn)</PrepareForBuildDependsOn>
</PropertyGroup>
</Project> Thanks for pointing me in the right direction, much appreciated. |
Is there an existing issue for this?
Describe the bug
I have a
dotnet new razor
project withMicrosoft.TypeScript.MSBuild
andBuildBundlerMinifier
added so that I can write TypeScript first, then minify the compiled JavaScript furtherSo, I want to be able to write the source TypeScript in the folder next to where I want the compiled JavaScript output file to eventually be.
So for example:
Also,
The project will build initially, but any subsequent builds or a
dotnet watch
will then fail.The build output and error is as follows:
The repo is here : https://github.com/solrevdev/dotnet-ts-colocation-issue
Expected Behavior
No response
Steps To Reproduce
The project should build unless I am missing something obvious, which is very possible!
The repo is here : https://github.com/solrevdev/dotnet-ts-colocation-issue
Exceptions (if any)
No response
.NET Version
6.0.300
Anything else?
I am using a combo of Sublime Text and VS Code Insiders
And here is some environment information:
.NET
dotnet --info .NET SDK (reflecting any global.json): Version: 6.0.300 Commit: 8473146e7d Runtime Environment: OS Name: Mac OS X OS Version: 11.6 OS Platform: Darwin RID: osx.11.0-x64 Base Path: /usr/local/share/dotnet/sdk/6.0.300/ Host (useful for support): Version: 6.0.5 Commit: 70ae3df4a6 .NET SDKs installed: 3.1.419 [/usr/local/share/dotnet/sdk] 6.0.300 [/usr/local/share/dotnet/sdk] .NET runtimes installed: Microsoft.AspNetCore.App 3.1.25 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.5 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 3.1.25 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.5 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] To install additional .NET runtimes or SDKs: https://aka.ms/dotnet-download
macOS:
The text was updated successfully, but these errors were encountered: