Just started learning Mapster. From this article I learned that the generation of extension methods for existing entities is triggered using the GenerateMapper method, which is located in a custom configuration class that derives from IRegister.
In short:
dotnet mapster extension
” command to the *.csproj file, for example:<ItemGroup>
<PackageReference Include="Mapster" Version="7.4.2-pre02"/>
</ItemGroup>
<Target Name="Mapster" AfterTargets="AfterBuild">
<Exec WorkingDirectory="$(ProjectDir)" Command="dotnet tool restore" />
<Exec WorkingDirectory="$(ProjectDir)" Command="dotnet mapster extension -a "$(TargetDir)$(ProjectName).dll"" />
<Exec WorkingDirectory="$(ProjectDir)" Command="dotnet mapster mapper -a "$(TargetDir)$(ProjectName).dll"" />
</Target>
IRegister
:public class MapperConfig : IRegister {
private const MapType MapAll = MapType.Map | MapType.MapToTarget | MapType.Projection;
public void Register(TypeAdapterConfig config) {
config.NewConfig<Poco, Dto>()
.TwoWays()
.GenerateMapper(MapAll);
}
}