|
| 1 | +<Project> |
| 2 | + <!-- Build-time code generation target: runs Wolverine code generation before compilation --> |
| 3 | + <!-- This target runs when EnableWolverineCodeGeneration is true (defaults to true for Release builds) --> |
| 4 | + <!-- It generates Wolverine code before compilation so it can be included in the build --> |
| 5 | + <Target Name="GenerateWolverineCode" |
| 6 | + BeforeTargets="BeforeBuild" |
| 7 | + Condition="'$(EnableWolverineCodeGeneration)' == 'true' And '$(GeneratingWolverineCode)' != 'true' And '$(MSBuildProjectName)' == 'Morphir.Tooling'"> |
| 8 | + <PropertyGroup> |
| 9 | + <ToolingProjectPath>$(MSBuildProjectDirectory)/$(MSBuildProjectName).csproj</ToolingProjectPath> |
| 10 | + <ProjectRootDir>$(MSBuildProjectDirectory)/../..</ProjectRootDir> |
| 11 | + <MorphirProjectPath>$(ProjectRootDir)/src/Morphir/Morphir.csproj</MorphirProjectPath> |
| 12 | + </PropertyGroup> |
| 13 | + |
| 14 | + <Message Text="Generating Wolverine code (EnableWolverineCodeGeneration=true)..." Importance="high" /> |
| 15 | + |
| 16 | + <!-- Build Morphir project first (needed for codegen command) --> |
| 17 | + <!-- Pass GeneratingWolverineCode=true to prevent recursive codegen target execution --> |
| 18 | + <!-- Disable shared compilation to avoid VBCSCompiler file locking issues on Windows --> |
| 19 | + <MSBuild Projects="$(MorphirProjectPath)" |
| 20 | + Targets="Build" |
| 21 | + Properties="Configuration=$(Configuration);GeneratingWolverineCode=true;EnableWolverineCodeGeneration=false;UseSharedCompilation=false" /> |
| 22 | + |
| 23 | + <!-- Run codegen write command from the project root using the Morphir CLI --> |
| 24 | + <!-- The Morphir project has the codegen command that uses Morphir.Tooling --> |
| 25 | + <!-- Use dotnet exec with the built DLL to avoid file locking issues and ensure process completes --> |
| 26 | + <PropertyGroup> |
| 27 | + <MorphirDllPath>$(ProjectRootDir)/src/Morphir/bin/$(Configuration)/net10.0/morphir.dll</MorphirDllPath> |
| 28 | + </PropertyGroup> |
| 29 | + <!-- Use dotnet exec which ensures the process fully completes and releases file handles --> |
| 30 | + <Exec Command="dotnet exec "$(MorphirDllPath)" codegen write" |
| 31 | + WorkingDirectory="$(ProjectRootDir)" |
| 32 | + ContinueOnError="false" |
| 33 | + Timeout="300000" |
| 34 | + Condition="Exists('$(MorphirDllPath)')" /> |
| 35 | + <!-- Fallback to dotnet run if DLL doesn't exist (shouldn't happen after build above) --> |
| 36 | + <Exec Command="dotnet run --project $(MorphirProjectPath) --configuration $(Configuration) --no-build -- codegen write" |
| 37 | + WorkingDirectory="$(ProjectRootDir)" |
| 38 | + ContinueOnError="false" |
| 39 | + Timeout="300000" |
| 40 | + Condition="!Exists('$(MorphirDllPath)')" /> |
| 41 | + |
| 42 | + <!-- Wait a moment to ensure all file handles are released (especially on Windows where VBCSCompiler may hold locks) --> |
| 43 | + <Exec Command="timeout /t 2 /nobreak" |
| 44 | + Condition="'$(OS)' == 'Windows_NT'" |
| 45 | + ContinueOnError="true" /> |
| 46 | + <Exec Command="sleep 2" |
| 47 | + Condition="'$(OS)' != 'Windows_NT'" |
| 48 | + ContinueOnError="true" /> |
| 49 | + |
| 50 | + <Message Text="Wolverine code generation completed." Importance="high" /> |
| 51 | + </Target> |
| 52 | +</Project> |
| 53 | + |
0 commit comments