Utility to migrate from RazorGenerator.Mvc to RazorGenerator.MsBuild Package to implement Sitecore Precompiled Views
Recently implemented precompiled views for one of my applications having many csproj files.
Initially added RazorGenerator.mvc nuget package but then realized that this package adds .generated.cs file for each cshtml and its an overhead to check-in all those auto-generated files to github.
Then, stumbled upon RazorGenerator.MsBuild nuget package that takes care of compiling the autogenerated cs file into the dll.
Since my application had a lot of projects, I not only had to undo the addition of RazorGenerator.Mvc package and dll references but also add the new package. So, wrote this utility that makes the changes automatically. The utility covers the following steps (methods in the utility):
1. BlankRazorGeneratedLines(): Remove the .generated.cs references in the project file
2. ReplaceGeneratedLinesStartingwithNone(): Set just Build action to none for cshtml files in the project file
2.a
3. BlankRazorGeneratorMvcStartLines(): Remove RazorGeneratorMvcStart.cs references in the project file
4. BlankRazorMvcReferenceandAddRazorBuildRef():
4.a remove razor mvc pkg ref:
4. b And, add razor msbuild ref:
5. AddRazorMsBuildtoPackagesConfig(): Added razorGenerator.MSBuild to packages.config
6. DeleteAutoGeneratedFiles();// physically delete autogenerated files from filesystem
7. DeleteRazorMvcStartFiles(); //delete razor generator mvc start files from filesystem
With this utility, I could make changes/delete about 360+ files in one shot in a matter of few seconds. So, if you by mistake added RazorGenerator.Mvc package instead of RazorGenerator.MSbuild package and don't have a way to revert amidst other changes, this utility must transition in a matter of few seconds!
Ensure to close the sln while you run the tool to not get file lock error!
The 0.1 release adds RazorGenerator directive to Custom Tool property while setting Build Action to None for all cshtml files in a sln but the side-effect of this approach is the redundant .generated.cs files
If you use the 0.2 release exe, this is how you invoke the utility with the necessary args -
RazorGeneratorUtility.exe <path to sln folder> <sln Name> <grand parent path that will allow the tool to delete .generated.cs files from filesystem>
Comments
Post a Comment