I'm generating a static class with constants from an XML file using T4 text templates. The template shall be transformed with every build so I added the following statements in the .csproj:
<Import Project="$(MSBuildExtensionsPath)\...\TextTemplating\Microsoft.TextTemplating.targets" />
<PropertyGroup>
<TransformOnBuild>true</TransformOnBuild>
</PropertyGroup>
This works fine on my local development machine (Visual Studio 2019) but the CI build fails with:
##[error]C:\...\TextTemplating\Microsoft.TextTemplating.targets(340,5): Error MSB4018: The "TransformTemplates" task failed unexpectedly.
System.TypeLoadException: Could not load type 'System.Windows.DependencyObject' from assembly 'WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
at Microsoft.VisualStudio.TextTemplating.Sdk.Host.GenericTextTemplatingHost.InternalConstruct()
at Microsoft.VisualStudio.TextTemplating.Sdk.Host.GenericTextTemplatingHost..ctor(IServiceProvider serviceProvider, ITelemetryService telemetryService)
at Microsoft.VisualStudio.TextTemplating.Build.Tasks.TransformTemplatesBase.GetConfiguredTextTemplatingHost()
at Microsoft.VisualStudio.TextTemplating.Build.Tasks.TransformTemplatesBase.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask)
The build server does not have a Visual Studio installation but the Visual Studio Build Tools 2019 with Workload ".NET build tools", ".NET desktop build tools" and "Webdevelopment build tools". The component "Text Template Transformation" is present as well as "Visual Studio SDK Build Tools Core". MSBuild finds all the .dll's needed. The Visual Studio project causing the trouble is of type Class Library and targets .NET Standard 2.0.