I am trying to use Text Transform templates (a feature of Visual Studio) with GitHub Actions. I am specifically using the Windows runner, which has Visual Studio 2022 Enterprise installed, so the dependency should be there.
In my .csproj
file I have set up the configuration as follows:
<PropertyGroup>
<CustomPathToTransforms>$(MSBuildExtensionsPath)</CustomPathToTransforms>
</PropertyGroup>
<Import Project="$(CustomPathToTransforms)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TextTemplating\Microsoft.TextTemplating.targets" />
Then, I also make sure that the transform occurs during build:
<PropertyGroup>
<TransformOnBuild>true</TransformOnBuild>
<TransformOutOfDateOnly>false</TransformOutOfDateOnly>
</PropertyGroup>
Locally, this works fine with Visual Studio 2022 Community edition. The reason that I added another property (CustomPathToTransforms
) is that so in GitHub Actions I can redirect it to the Visual Studio installation folder instead of the .NET tooling folder, that would otherwise be picked up with MSBuildExtensionsPath
.
In GitHub Actions, I am running the build like this:
dotnet build --configuration Release -p:CustomPathToTransforms="C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Msbuild\"
In theory, this should work, and I can tell from the build output that the targets are found correctly, however the step fails rather spectacularly:
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Msbuild\Microsoft\VisualStudio\v17.0\TextTemplating\Microsoft.TextTemplating.targets(347,5): error MSB4018: The "TransformTemplates" task failed unexpectedly. [D:\a\grunt\grunt\Grunt\Grunt\Grunt.csproj]
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Msbuild\Microsoft\VisualStudio\v17.0\TextTemplating\Microsoft.TextTemplating.targets(347,5): error MSB4018: System.TypeLoadException: Could not load type 'System.Windows.DependencyObject' from assembly 'WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. [D:\a\grunt\grunt\Grunt\Grunt\Grunt.csproj]
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Msbuild\Microsoft\VisualStudio\v17.0\TextTemplating\Microsoft.TextTemplating.targets(347,5): error MSB4018: at Microsoft.VisualStudio.TextTemplating.Sdk.Host.GenericTextTemplatingHost.InternalConstruct() [D:\a\grunt\grunt\Grunt\Grunt\Grunt.csproj]
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Msbuild\Microsoft\VisualStudio\v17.0\TextTemplating\Microsoft.TextTemplating.targets(347,5): error MSB4018: at Microsoft.VisualStudio.TextTemplating.Sdk.Host.GenericTextTemplatingHost..ctor(IServiceProvider serviceProvider, ITelemetryService telemetryService) [D:\a\grunt\grunt\Grunt\Grunt\Grunt.csproj]
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Msbuild\Microsoft\VisualStudio\v17.0\TextTemplating\Microsoft.TextTemplating.targets(347,5): error MSB4018: at Microsoft.VisualStudio.TextTemplating.Build.Tasks.TransformTemplatesBase.GetConfiguredTextTemplatingHost() [D:\a\grunt\grunt\Grunt\Grunt\Grunt.csproj]
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Msbuild\Microsoft\VisualStudio\v17.0\TextTemplating\Microsoft.TextTemplating.targets(347,5): error MSB4018: at Microsoft.VisualStudio.TextTemplating.Build.Tasks.TransformTemplatesBase.Execute() [D:\a\grunt\grunt\Grunt\Grunt\Grunt.csproj]
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Msbuild\Microsoft\VisualStudio\v17.0\TextTemplating\Microsoft.TextTemplating.targets(347,5): error MSB4018: at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [D:\a\grunt\grunt\Grunt\Grunt\Grunt.csproj]
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Msbuild\Microsoft\VisualStudio\v17.0\TextTemplating\Microsoft.TextTemplating.targets(347,5): error MSB4018: at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [D:\a\grunt\grunt\Grunt\Grunt\Grunt.csproj]
Build FAILED.
This is a .NET 6.0 project that I want to make cross-platform (compiled through VS, though).
I am curious - what can I do to resolve the issue? Is there a way to make the process identify dependencies which I assume are already in the GAC?