This document helps to understand the SolutionGeneration task, starting from the ProjectGeneration to the WFNetConversionTool call and settings to execute the Generation service.
First thing to understand is what ProjectGeneration does. ProjectGeneration contains the services and templates that generate the output files for a project, using some configurations. In this file, we will be focusing on the SolutionGeneration for Blazor.
We need to start talking about the Interfaces of the Abstractions. This interfaces define the properties and methods needed to execute the generation of the project.
We can find the interfaces in the Mobilize.ProjectGeneration.Abstraction project under the SolutionGenerator repository.
Go to IProjectGenerator, we can find some properties. You can see this properties as parameters that the Generate task needs.
Pay special attention to this method definition, because this will be called inside the Task to call the generator you need.
Now that we see this Interface, we need to understand… Why is this needed? Well, let’s jump on it.
Under the same project, we have a class called ProjectGeneratorBase.
This class implements the IProjectGenerator interface. If you navigate a bit in this class, you will find the GenerateProject implementation.
Now, we need to use the template used by the respective GenerateProject. In this case, we should go into the SolutionTemplate.tt.
Avoid touching the SolutionTemplate.cs
You can modify the template as we did here.
And save the file. When you save, a popup is showing. Press Yes. This is to synchronize the tt with the cs(the cs is generated dynamically by handlebars).
To test the changes we can pack the projects locally, or, upload the changes to a branch and wait for the build to generate an alpha version.
To pack locally just run the next command under the build folder. Change the path for every csproj
Once you pack the changes, you need to install the package in the WFNetConversionTool. If you pack it locally, add the build folder to the package sources in the Nuget Package Manager of Visual Studio.
Or install the alpha version if you commit the changes to a branch.
Now, is necessary to add the BlazorSolutionGenerationTask and the BlazorSolutionGenerator
Here we have our BlazorSolutionGenerator, that will set the params and config to call the GenerateProject from the ProjectGeneration.
Here in the Run method, we need to pass the config to the SolutionGenerationParams
And now, we can call the BlazorSolutionGenerator from the Task.