C
C#16mo ago
jjthomps

❔ T4 Compiling transformation error

Hi, I'm upgrading a solution to .net 7.0. One of the projects contains T4 transformation templates. Getting the following error even though the target framework is set to net7.0 for all projects contained within the solution. Compiling transformation: The type 'List<>' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Collections, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. I have updated the tarhet sdk to net7.0 in all the projects, updated sdk version in the global.json files, deleted the vs, bin and obj directories, cleaned the solution, reopened solution, rebuilt solution, upgrade Visual Studio 2022 to the latest version but there is still an issue when I try to add a reference to system.Collections an error is displayed saying that the dll is invalid or not supported anyone got any ideas what's wrong? Thanks
7 Replies
cypherpotato
cypherpotato15mo ago
T4 runs on an isolated context with their own references. have you tried to reference it using
<#@ assembly name="$(TargetPath)" #>
<#@ assembly name="$(TargetPath)" #>
and then
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="System.Collections.Generic" #>
?
jjthomps
jjthompsOP15mo ago
Hi @cypherpotato I already had those lines of code in place. The error is triggered by this line when I execute this line of code: <# List<T4HelperV2.ObjectToUse> listOfObjectsToGenerate = new List<T4HelperV2.ObjectToUse>(); ObjectToUse is contained within a .cs class file. This class is referenced as follows: <#@ assembly name="$(TargetDir)T4HelperV2.dll" #> <#@ import namespace="T4HelperV2" #> <#@ include file="$(ProjectDir)ModelMapper.cs" #> This is the new error: Running transformation: System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. File name: 'System.Runtime, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
Accord
Accord15mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
jjthomps
jjthompsOP15mo ago
Hi @cypherpotato Managed to resolve it by leaving the project and the projects referenced on netstandard2.1. Was able to upgrade the other projects to dotnet 7.0 closed
SinFluxx
SinFluxx15mo ago
$close
MODiX
MODiX15mo ago
Use the /close command to mark a forum thread as answered
Accord
Accord15mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server