From my Umbraco NuGet package how can I copy the App_Plugins folder to the consumer webproject?

I have a project that has a client folder with TS code that adds sections to the Backoffice. If I run npm run build there, an App_Plugins folder will be generated. Locally, if I copy this over to the consumer web project, my package works.

However, what’s the solution when I want to do the same thing from NuGet?

The goal is that if I add my package as a NuGet package to a web project, I want the App_Plugins folder to be generated (npm run build) and put into the web project’s root folder: So my package would appear on the Backoffice.

I already packed my package locally into NuGet and tried adding it to the we project, but the App_Plugins folder didn’t appear, and my package is not registered on the Backoffice.

What is the standard solution here?

The standard solution is to make you NuGet package a razor class library and have the App_Plugins folder in the wwwroot folder. This way, there is no need to copy over the files to the consumer web project locally when testing and it will work when you install the package as a NuGet.

<Project Sdk=“Microsoft.NET.Sdk.Razor”>
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework> 	
...
<ImplicitUsings>enable</ImplicitUsings>
<StaticWebAssetBasePath>/</StaticWebAssetBasePath>
<ContentTargetFolders>.</ContentTargetFolders>
</PropertyGroup>
</Project>
1 Like

It worked, thank you!

Do I need to include the built files (App_Plugins folder), or is there a way around that? Somehow, calling npm run build after my package is referenced by the web project, maybe?

Some explanation about static web assets here..

<Project Sdk="Microsoft.NET.Sdk.Razor">
and add a <StaticWebAssetBasePath> value to the property group element.
<StaticWebAssetBasePath>/</StaticWebAssetBasePath>

This tells Asp.Net that anything in the wwwroot folder will be presented in the website at the root level. meaning if we put our files in app_plugins/package then they will be accessible at https://site/app_plugins/package

I’m not sure what you mean by that? You have a project that is your NuGet package. In that project are your non-compiled files, so your typescript/vite files. On that project you run npm build (or better, use a watch, so it will run when a file gets updated), and that should compile the files and place the compiled files into the wwwroot/App_Plugins/Your_Package folder. These are the files that should be present in your NuGet package. There is no need to have the original source files in your package.

1 Like

That was present in my example, but it was not very well visible because it somehow didn’t get placed on it’s own line in the code. I fixed that :slight_smile:

Yeah, I see it now, thank you!

I meant only to include the source files, then build them in the web project. But as you said, it just bloats the inclusion, since then it would have the source files and the built files too. And also, I don’t think it’s possible in a simple way.

So yeah, I’m only including the built files. Thanks!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.