enkelmedia / TheDashboard

Magic dashboard for Umbraco
MIT License
39 stars 42 forks source link

Plugin gets deleted when solution builds #83

Closed seanrockster closed 1 year ago

seanrockster commented 1 year ago

Hi

I'm not sure why this keeps happening, or if an issue with the plugin, but its only this plugin. When I build the solution/project in VS, this plugin gets deleted.

Any ideas why this is happening? Thanks.

seanrockster commented 1 year ago

What is more bizarre is if I set Copy to Output Directory to anything other than Do not copy, the plugin folder gets removed. However if I leave on Do not copy, it doesn't get deleted but doesn't get published either.

tristanjthompson commented 1 year ago

Did you ever solve this? I've just come across this and I can see it's getting deleted as part of its Our.Umbraco.TheDashboard.targets file where it specifically deletes the folder during a clean...however the clean gets run during a rebuild so it's deleting it and then doesn't quite seem to be restoring the folder in time for the rest of the build.

enkelmedia commented 1 year ago

Hi!

What version of Umbraco are you running on? This "hack" is basically the way that the "Umbraco Package Starter-Kit" is recommended way to handle static files since we no longer can include "Project files" in the NuGet package. The idea is that the .target-file would remove the folder and re-create it. It works on a lot of sites where I use the package my self.

Are you seeing this problem during development or during build/publish?

// m

tristanjthompson commented 1 year ago

This was happening specifically on our build server when doing a Rebuild (as opposed to a Build) - I never knew this before, but the Rebuild triggers the "clean" action in the .targets file..so that was where I was at. Umbraco 11.1.0, though I think that's unrelated.

I've solved it now! We basically had a lot of custom data types/block list editor/angular modules in our App_Plugins folder which we needed to be included when packaging things up/publishing. To do that, we'd added a wildcard include in our .csproj file like this:

<Content Include="App_Plugins\**\*.*">
    <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>

When the build process starts, I think it looks at all the files in the folder and builds up its list of what's in there. Then, because the Our.Umbraco.TheDashboard folder got deleted mid way through, it got confused and complained about it not being there.

My solution was to exclude the Our.Umbraco.TheDashboard folder by right-clicking in the project and excluding it which generated the following in the csproj file:

<Content Include="App_Plugins\**\*.*">
    <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>

<Content Remove="App_Plugins\Our.Umbraco.*\**" />

This then lets your .targets file do its thing which ensures it's part of the published package.

Thanks for the info around it being the recommended way of making sure the files were included - that made me look at other packages and I could see the same in their targets file - that made me realise it was something in the way our project was set up so I focussed on that!

What's really weird, is the only other folder in there that wasn't a custom one we'd made was from the Our.Umbraco.GMaps package. I can see in their repo that they have the same .targets file, but for some reason it doesn't behave the same way and I don't see it getting deleted during a rebuild (even though I can see a log line about it running the "clean" action from the .targets file) so we hadn't had that problem with that package!

Anyways, excluding the folder solved it for me without having to manually include/configure all of our other App_Plugins folders/files (which is useful as we'll inevitiablly miss something if we have to do it individually each time we add some custom stuff in there!)

enkelmedia commented 1 year ago

Hi!

Thanks a lot for sharing the details! I have had similar issues during CI-builds as well and since most builds are different it's hard to find a "one size fits all"-solution or recommendation.

I don't know if all other packages use the clean-target but the idea is that we want to remove any old files if a new version of the package makes changes to the filesystem. If we would remove html-file clean would make sure that we have the right files in the folder and not any old stuff.

In one of our projects, we use this code to "hook into" the publishing pipeline at a later stage (when the files are back) after the "ComputeFilesToPublish"-target. This solution also runs some npm stuff as a part of the build.

<Target Name="PublishFrontend" AfterTargets="ComputeFilesToPublish">

  <Message Text="On ComputeFilesToPublish - Adding wwwroot/Assets and App_Plugins" Importance="high" />

  <ItemGroup>
    <DistFiles Include="wwwroot\Assets\**;App_Plugins\**\*.*" />
    <ResolvedFileToPublish Include="@(DistFiles->'%(FullPath)')" Exclude="@(ResolvedFileToPublish)">
      <RelativePath>%(DistFiles.Identity)</RelativePath>
      <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
      <ExcludeFromSingleFile>true</ExcludeFromSingleFile>
    </ResolvedFileToPublish>
  </ItemGroup>
</Target>

With the improved support for Razor Class Libraries in Umbraco 11 I think that many packages will transition into shipping the client files as a RCL which would eliminate this issue. I haven't really had the time to convert the package yet but I think that this would be the "right" solution for the future.

Thanks for sharing your solution as well!

Cheers!

seanrockster commented 1 year ago

Thanks i'll try the above.

enkelmedia commented 1 year ago

Hi!

Just wanted to let everyone know that for Umbraco 11 there is now a release where the package has been moved into a Razor Class Library. This will remove the need to the special stuff in the csproj-file.

I will go ahead and close this issue but feel free to re-open or create new if needed.

Package-link: https://www.nuget.org/packages/Our.Umbraco.TheDashboard/11.1.0