question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
minestarkscommented, 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.

0reactions
marcOcramcommented, 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 https://github.com/dotnet/aspnetcore/issues/40317#issuecomment-1048254393.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do you add additional files to a NuGet package in Visual ...
First, please be aware that you need to put your files either into a content or contentFiles folder depending on how you NuGet...
Read more >
Create a NuGet package using MSBuild - Microsoft Learn
A detailed guide to the process of designing and creating a NuGet package using MSBuild, including key decision points like files and ...
Read more >
Publishing a self-contained Blazor component (Razor + CSS + ...
.NET 5.0 RC1 only: Edit the csproj to exclude the isolated CSS files from the NuGet package (this is fixed in RC2). csproj...
Read more >
Copy NuGet Content Files to Output Directory on Build
Viewing v5.0.4 of the .nupkg file in the NuGet Package Explorer, ... name of my library's project name, and I added the a...
Read more >
Packing PHP Libraries into NuGets - PeachPie
To contain all the jpg, js and css content files, add the following ... has a PHP NuGet package reference, you are free...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found