Pull Request for publishing assets in HelixBase project

Note (26/june/2023): After writing this blog post, I found that there is a pending PR by someone else that is yet to be merged: https://github.com/muso31/Helixbase/pull/62 but this post will be useful to understand a problem and associated solution + some HPP and CPM basics . 

There are so many people who have raved about Sitecore Slack. So, I won't delve into it. Recently, one of our buddy-developers was having a weird issue with the Sitecore Helixbase project and had stated they were unable to do proper VS publish with the HelixBase project. I then went through the issue logged in the repo.

Frankly, I didn't have much background about Helix Publish Pipeline(HPP) but no guts no glory. When I cloned the repo, created a publish profile and published to a local directory, this is what I saw: 


If you are eagle-eyed, you will notice that although there are config files in the sln structure, they are nowhere to be seen in the published folder.

As a very smart developer, I changed the "Copy to output Directory" property of one of the config files to Copy if Newer unaware that Helix Publish Pipeline treats this a different way wherein it publishes the config file under bin\App_Config folder as follows:


Since this is not the desired end-result, I started investigating: My search for any such issues in the past hit a dead-end. I also tried for ways to intercept the publish pipeline (msbuild tasks!) to either delete the App_Config under the bin folder or altogether bypass it someway. I could plugin tasks in the build process but not the publish process. I also thought of (somehow!) invoking a PS script that can do the delete job but everything seemed a hack and most importantly, nothing worked!

Then, I took a step back and revisited the github issue to realise that the issue started happening after switching over to central package management (CPM). I then analysed CPM (diagram below). After closing doors one after another I narrowed down to this suspicious setting:


Central Package Management (just for reference):


I changed PackageVersion to PackageReference, did a publish and that worked:


I also realised that with Helix Publish Pipeline (HPP), views and configs need to be set to "Content" for Build Action while Copy to Output Directory can stay as "Do not copy":


The fact that Build Action is set to Content will ensure that the asset will be copied to respective folder like, App_Config for config files.

That's it! Once I did a complete VS publish pointing to a site instance satisfying all the pre-requisites in the readme page, the ser push was successful and I could view the home page:


With regard to HPP, the readme page lists many uses but these were some that impressed me and useful for any basic Helix project development: 


Also, with central package management, the process of utilising nuget packages has evolved over the years: the dll referencing followed by involving packages.config and then packagereference to central package management till date. 

In all these scenarios, there has been this consistent struggle to centralise and de-centralise package and version management across projects in a solution.

With Central Package management(CPM):  Directory.Packages.props file stores the Package name with version + a switch (ManagePackageVersionsCentrally) to toggle centralised package management  while individual projects just have the PackageReference without the version. 



Fingers crossed with my PR.

Note (26/june/23): Logged a Microsoft bug for CPM with regard to VS 2022 Community Edition not throwing a build error when PackageVersion instead of PackageReference is specified in .csproj file - https://developercommunity.visualstudio.com/t/PackageVersion-in-csproj-does-not-throw/10400302




Comments

Popular Posts