3.8 KiB
Internals of build process
The purpose of this document is to explain build process internals with subtle nuances.
This document is not by any means complete.
The ultimate source of truth is the code in .\build.psm1 that's getting executed on the corresponding CI system.
This document assumes that you can successfully build PowerShell from sources for your platform.
Top directory
We are calling dotnet tool build for $Top directory
src\powershell-win-corefor CoreCLR on Windows.src\powershell-unixfor CoreCLR on Linux and macOS.
Dummy dependencies
We use dummy dependencies between projects to leverage dotnet build functionality.
For example, src\powershell-win-core\powershell-win-core.csproj has dependency on Microsoft.PowerShell.PSReadLine,
but in reality, there is no build dependency.
Dummy dependencies allows us to build just $Top folder, instead of building several folders.
Dummy dependencies rules
If assembly is part of CoreCLR build,
it should be listed as a dependency for $Top folder (src\powershell-unix or src\powershell-win-core)
Preliminary steps
ResGen
Until the .NET CLI dotnet-resgen tool supports the generation of strongly typed classes,
we run our own tool C# ResGen tool.
While the Start-PSBuild command runs this automatically via the Start-ResGen function,
it does not require PowerShell.
The same command can be run manually:
cd src/ResGen
dotnet restore
dotnet run
Running the program does everything else:
- for each project, given a
resourcesfolder- creates a
genfolder - for each
*.resxfile- fills in a strongly typed C# class
- writes it out to the corresponding
*.csfile
- creates a
These files are not automatically updated on each build, as the project lacks the ability to detect changes. Thus, running it for every build would break incremental recompilation.
If you pull new commits and get an error about missing strings,
you likely need to delete the gen folders and re-run the tool.
Type Catalog
A pre-generated catalog of C# types is used in PowerShell to help type resolution.
Generating this catalog is a pre-build step that is run via Start-TypeGen,
which Start-PSBuild calls.
Again, however, PowerShell is not required.
The necessary steps can be run manually:
cd ../TypeCatalogGen
dotnet restore
dotnet run ../System.Management.Automation/CoreCLR/CorePsTypeCatalog.cs powershell.inc
The file powershell.inc is generated by running a custom MSBuild target,
which can be set-up by navigating to the src directory and running the following commands:
targetFile="Microsoft.PowerShell.SDK/obj/Microsoft.PowerShell.SDK.csproj.TypeCatalog.targets"
cat > $targetFile <<-"EOF"
<Project>
<Target Name="_GetDependencies"
DependsOnTargets="ResolveAssemblyReferencesDesignTime">
<ItemGroup>
<_RefAssemblyPath Include="%(_ReferencesFromRAR.ResolvedPath)%3B" Condition=" '%(_ReferencesFromRAR.Type)' == 'assembly' And '%(_ReferencesFromRAR.PackageName)' != 'Microsoft.Management.Infrastructure' " />
</ItemGroup>
<WriteLinesToFile File="$(_DependencyFile)" Lines="@(_RefAssemblyPath)" Overwrite="true" />
</Target>
</Project>
EOF
dotnet msbuild Microsoft.PowerShell.SDK/Microsoft.PowerShell.SDK.csproj /t:_GetDependencies "/property:DesignTimeBuild=true;_DependencyFile=$(pwd)/src/TypeCatalogGen/powershell.inc" /nologo
powershell.inc contains the resolved paths to the DLLs of each dependency of PowerShell,
and is taken as input to the TypeCatalogGen tool,
which generates a source file CorePsTypeCatalog.cs for the Microsoft.PowerShell.CoreCLR.AssemblyLoadContext project.
The error The name 'InitializeTypeCatalog' does not exist in the current context
indicates that the CorePsTypeCatalog.cs source file does not exist,
so follow the steps to generate it.