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

When using the MSBuild package with Blazor library extra content files are added to nupkg #42907

Open
attilah opened this issue Feb 21, 2021 · 7 comments
Assignees
Labels
Visual Studio Integration with Visual Studio
Milestone

Comments

@attilah
Copy link

attilah commented Feb 21, 2021

Bug Report

When using the Microsoft.Typescript.MSBuild 4.2.1-rc to pack a Blazor Library project for nuget package, the compiled javascript files are added to the content and contentFiles folders of the nuget package, not just to staticWebAssets that Blazor build picks up.

GetTypeScriptOutputForPublishing MSBuild target seems to be the source of errors, if the content of that target is commented out, the nuget package does not have the above problem.

UPDATE

The real sideeffects of this coming to the surface when the build nuget package is consumed in another Blazor project and being built in VS 2019 16.x. As the JS files are showing up in the consuming project as project items and they should not. The worse thing is that if you put a tsconfig.json into the Logging package no matter if it is a <None.... item, that will also be packed and will cause compilation failure in the consuming project as there will be no source files to compile (that's how we started to notice this problem).

Repro

  1. Clone https://github.com/BlazorExtensions/Logging
  2. dotnet pack
  3. Observe the contents of the nupkg file

🔎 Search Terms

msbuild, nuget, blazor

🙁 Actual behavior

See in summary above.

🙂 Expected behavior

Nuget package should not have those extra files.

@minestarks minestarks self-assigned this Feb 22, 2021
@minestarks
Copy link
Member

Interesting issue, thanks for pointing it out. It's currently intentional that the TS NuGet package includes the output as Content items, but I'm not familiar enough with the design of Blazor Library projects to be able to tell whether the fault lies with the TS NuGet package or the Blazor project type here. Will investigate.

@attilah
Copy link
Author

attilah commented Feb 22, 2021

If we could have a condition for the GetTypeScriptOutputForPublishing target that we could set to true to disable the content addition that would be awesome. The problem was that this target is hooked up into multiple places and not all of them has an "After" target where I could revert these things, I tried to apply all my msbuild fu, but failed. The other way is to include Blazor specific logic as all the logic we have in the package is targeting ASP.NET Core Webapp publishing scenarios.

@galvesribeiro
Copy link

For the sake of giving more context on this, if you build the project using dotnet build, VSCode or Rider, the problem on the consuming projects doesn't happen since it looks like it doesn't care about the link to the transpiled JS file on wwwroot. However, if you build on VS and you have the tsconfig on it as Attila mentioned, it will completely fail the build.

This is how VS 2019 sees the project:

image

Note that there are links on wwwroot/BrowserConsoleLogger.js and tsconfig.json which shouldn't be there since they are both internal to the NuGet package. In fact, we're tried adding None with Pack=false and the same behavior still happen.

It indeed looks like the TS package adds everything from the project as Content on nuget so the consumer will have it "available". If that was the intentional behavior, I think for the sake of custom builds, like Blazor (which share a lot from Razor Components project type itself), we should have a prop which flag whether or not we want that to be added as Content.

@minestarks
Copy link
Member

minestarks commented Feb 23, 2021

@attilah so I don't know how much you're going to like this, but one workaround I found is to override the offending target by adding this to your Directory.Build.targets:

<Target Name="GetTypeScriptOutputForPublishing" />

Still should investigate the inner workings of this and find out how we can integrate better with Blazor though.

@attilah
Copy link
Author

attilah commented Feb 23, 2021

@minestarks Yeah....as a last resort that could work I intentionally did not bring it up as a possible solution :D :D :D I'd appreciate if we can fix it in a proper way. Of course as a workaround target override is fine!

@minestarks
Copy link
Member

@attilah ah yes, you already got there before me! I can't see any downsides to your suggestion of adding a condition to optionally disable the target. This is what I'll do if there's no more elegant integration we can come up with.

@jessetrinity jessetrinity self-assigned this Aug 25, 2021
@orta orta added the Visual Studio Integration with Visual Studio label Nov 10, 2021
@orta orta added this to the Backlog milestone Nov 10, 2021
@marcOcram
Copy link

marcOcram commented Mar 8, 2022

Any news on this? It is still an issue with Blazor 6, .NET 6 and/or VS 2022. I just stumbled across this and took me a while to figure this out ...

EDIT: The workaround mentioned is not working anymore. On .NET 6 you have to first run dotnet build and afterwards dotnet pack. That way it is going to be build twice but the files are not added to the NuGet package.

Do not try to add --no-build to dotnet pack - that does not work because of dotnet/aspnetcore#40317 (comment).

Parziwal pushed a commit to Parziwal/AutSoftCore that referenced this issue Jan 30, 2023
JS files generated by the blazor projects are not included in the staticwebassets folder in the nuget package, but in the content and contentFiles folders.

More details:
microsoft/TypeScript#42907
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Visual Studio Integration with Visual Studio
Projects
None yet
Development

No branches or pull requests

7 participants