Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

T4.BuildTools Inconsistent .net version #186

Open
innominateAtWork opened this issue Jun 13, 2024 · 1 comment
Open

T4.BuildTools Inconsistent .net version #186

innominateAtWork opened this issue Jun 13, 2024 · 1 comment

Comments

@innominateAtWork
Copy link

The T4.BuildTools package seems to compile t4 files against a different version of .net depending on if the build is run from visual studio vs dotnet build.

My Project file looks like:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net6.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <TransformOnBuild>True</TransformOnBuild>
    <TransformOutOfDateOnly>False</TransformOutOfDateOnly>
  </PropertyGroup>
  
  <ItemGroup>
    <PackageReference Include="T4.BuildTools" Version="3.0.0-preview-0052-g5d0f76c785" />      
  </ItemGroup>
  
  <ItemGroup>
    <T4Transform Include="Program.tt"/>
  </ItemGroup>
 
</Project>

Program.tt looks like:

<#@ output extension=".cs" #>

<#        
   //var a = 8;
   //var str = $"Hello Mono T4. A={a}";
   var str = System.Environment.Version.ToString();
#>
    
Console.WriteLine("<#=str#>");

When built and run from visual studio it outputs "4.0.30319.42000"
When built and run via dotnet run it outputs "8.0.5"

newer C# features like interpolation also dont work when run within visual studio.

@mhutch
Copy link
Member

mhutch commented Jun 18, 2024

The T4 MSBuild tasks run on the same version of .NET that MSBuild runs on. MSBuild in Visual Studio runs on .NET 4.8 , which reports its version as "4.0.x" (iirc for compatibility reasons).

It would be pretty easy to support newer C# versions when running on. NET 4.8 by adding some logic to locate and use the newer version of csc that's bundled with Visual Studio or dotnet. Currently when running on .NET 4.8 the T4 engine uses the version of csc from the .NET Framework directory, which is very old.

Running the templates on .NET 8 when running the build tasks on .NET 4.8 is doable but would necessitate some kind of out-of-process hosting model for template execution. This would definitely be useful and has been on the backlog for a while.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants