Currently, i am starting a new project which is based on eCommerce solution build in legacy .net platform which i need to move to Sitecore. I wanted to have a look at all the solutions & structures available in community like Habitat, Sitecore Commerce 9.0.2 (A storefront example with the help of SXA), Habitat Home Demo.
I have already configured Habitat solution many times in local or on server without visual studio installed. I also installed Sitecore Commerce 9.0.2 with the help of installation guide provided by Sitecore and an excellent blog by @viet_hoang_sc: https://buoctrenmay.com/2018/03/09/step-by-step-guide-for-sitecore-commerce-9-installation-on-your-machine/ . Now, it was turn for Habitat Home Demo.
Habitat Home Demo
India witnessed first ever SUGCON in this region in May 2018. Where on second day, Implementing XC9 Habitat home Demo was on schedule. I got to see that demo and decided to install that at some time. Now, comes the real confusion. While searching on search engine, it always shows the Habitat (Helix) instead of Habitat Home Demo. There were couple of post from @viet_hoang_sc on this topic. Why couple of? because HabitatHome Demo is divided into two parts mainly:
Habitat Home Content
- This is similar to what normal Habitat is. Only content oriented demo site.
- Main difference is, this is built on top of SXA while earlier version of Habitat was without SXA.
- So, if you just wanted to have a site which is rich in content and built using SXA, this is the solution.
- You can install it by following blog https://buoctrenmay.com/2018/05/30/sitecore-demo-habitat-home-step-by-step-setup-guide/
- Repository: https://github.com/Sitecore/Sitecore.HabitatHome.Content. Use develop branch which will have latest 9.0.2 related stuff. While other branches may still point to 9.0.1.
Habitat Home Commerce
- This is similar to the storefront which comes as part of Sitecore Commerce 9 installation built on top of SXA demonstrating all commerce capabilities.
- To install this, you must install the Habitat Home Content mentioned above.
- This is a great mix of rich Content & Commerce experience as compared to default storefront which comes as part of Sitecore Commerce 9. If you wanted to have a feel of some modern eCommerce sites which are also rich in content, this is your solution.
- You can install it by following blog https://github.com/Sitecore/Sitecore.HabitatHome.Commercehttps://buoctrenmay.com/2018/05/30/sitecore-demo-habitat-home-step-by-step-setup-guide/
- Repository: https://github.com/Sitecore/Sitecore.HabitatHome.Commerce. Use develop branch which will have latest 9.0.2 related stuff. While other branches may still point to 9.0.1.
Build Error & PackageReference
By following the guide and the blog mentioned above, i was able to set up all prerequisites. I was just far to run the gulp command either from command line or from Visual Studio Task Explorer. I executed default gulp task, it failed after nuget restore while building the solution. Error is:
I went to Visual studio and performed rebuild solution and to the surprise, it succeeded without any errors.
Then i expanded the Accounts project under Foundation layer to have a look there.
With surprise, i couldn’t find the packages.config. And not the packages folder even in repository. This may be new to you as well if you have not paid much attention to the Asp.Net Core & new csproj style in VS 2017.
For Asp.Net core 1.0 projects, project.json was responsible to store all these dependency related information. With introduction of VS2017, project.json is retired and information related to dependency and nuget packages included in csproj itself. This new pattern is called PackageReference https://docs.microsoft.com/en-us/nuget/consume-packages/package-references-in-project-files.
I have installed latest nuget from https://www.nuget.org/downloads and there wasn’t any issue restoring packages even with this new PackageReference format. So, it looked like issue was with new PackageReference format and Project references. With some research i come to know that there were some issues with old legacy CSProj + PackageReference until MSBuild 15.1.
Few links if you wanted to know more about the build issue overall:
- https://github.com/dotnet/standard/issues/481 main issue tracker
To know more about project.json file: https://docs.microsoft.com/en-us/nuget/archive/project-json
To know more about PackageReference pattern: https://docs.microsoft.com/en-us/nuget/consume-packages/package-references-in-project-files
A guidance of converting package.json format to Packageeference using csproj properties: https://docs.microsoft.com/en-us/dotnet/core/tools/project-json-to-csproj. https://natemcmaster.com/blog/2017/03/09/vs2015-to-vs2017-upgrade.
There is a nice VS extension available to convert legacy packages.config style csproj into PackagReference pattern: https://marketplace.visualstudio.com/items?itemName=CloudNimble.NuGetPackageReferenceUpgrader
I was using VS 2017 with initial version of build tools. Installing latest stable version (15.7 or 15.8) of Visual Studio or just Build Tools for Visual Studio 2017 will solve the issue. And after this when you run the gulp command from command prompt, it will restore nuget packages, resolve dependencies correctly and build the projects successfully.