Documentation/gen-api.md
In WPF on .NET Core, C# reference assemblies are created via the use of GenAPI and a separate reference assembly project located in the ref directory under a particular assemblies source directory.
WPF assemblies make extensive use of the InternalsVisibleToAttribute which precludes the use of ProduceReferenceAssembly or ProduceOnlyReferenceAssembly. This is because these compiler options will include internal types and members in the reference assembly. In WPF, this creates dangling references to assemblies that do not exist in the WindowsDesktop reference pack.
Using GenAPI allows us to strip out internals, removing the dangling references from our reference assemblies.
Contains various properties related to GenAPI runs and configurations.
GenAPIEnabledProjects
GlobalApiExclusionsFile
GlobalAttrExclusionsFile
GenAPIAdditionalParameters
Contains targets and properties related to GenAPI runs
GenAPITargetDir
GenAPITargetPath
EnsureGenAPITargetDirectory
GenAPITargetDir if it does not existGenAPI is run only on-demand. In the event that a change to a runtime assembly creates new public surface area, a developer will see an ApiCompat error between the reference assembly and the runtime assembly. In order to address this, the developer must run GenAPI to generate new reference assembly code.
GenAPI can be run by setting the following MSBuild property while building.
/p:GenerateReferenceAssemblySource=true
When a build is run with that property enabled, GenAPI will read the runtime assembly and generate a new {AssemblyName}.cs file under the ref directory in the assembly's source tree.
This new file will contain the newly created surface area and will need to be checked in along with the runtime assembly change. The next build without GenerateReferenceAssemblySource enabled will no longer display an ApiCompat error as the surface area will now match the baseline.
GenAPI generates a lot of code that is either private, internal, or causes build errors. For this reason a developer usually cannot just use the output of GenAPI directly. Instead, the developer should do the following: