Converting T4 from .Net Framework 4.8 to .Net 6.0

Josef Fieseler 0 Reputation points
2023-09-21T13:20:31.47+00:00

I get the error "System.Data.Common 6" not found.

<#@ template debug="false" hostspecific="false" language="C#" #>
<#@ assembly name="System.Core" #>
<#@ assembly name="$(TargetDir)\Microsoft.Data.SqlClient.dll" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="Microsoft.Data.SqlClient" #>
<#@ output extension=".txt" #>
<#
    SqlConnection conn = new SqlConnection("Server=Mars;initial catalog=IKA-PROD;TrustServerCertificate=True;Timeout=10;Trusted_Connection=True");
#>

This works in the same solution

using Microsoft.Data.SqlClient;
internal class Program
{
    private static void Main(string[] args)
    {
        SqlConnection conn = new SqlConnection("Server=Mars;initial catalog=IKA-PROD;TrustServerCertificate=True;Timeout=10;Trusted_Connection=True");
        conn.Open();
        SqlCommand cmd = conn.CreateCommand();
        conn.Close();
    }
}
Developer technologies Visual Studio Other
{count} votes

2 answers

Sort by: Most helpful
  1. Tianyu Sun-MSFT 34,436 Reputation points Microsoft External Staff
    2023-09-22T04:23:01.4066667+00:00

    Hello @Josef Fieseler ,

    Welcome to Microsoft Q&A forum.

    I checked the corresponding NuGet package System.Data.Common, and it seems that the latest released(11/15/2016) version is 4.3.0 not 6.0.0. I am thinking if any class that you are using is not supported for .NET 6.0.

    Please try to install the latest version of .NET 6, update Visual Studio and Windows OS, check if this error disappears.

    Sincerely,

    Tianyu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  2. Josef Fieseler 0 Reputation points
    2023-10-17T07:35:48.0533333+00:00

    This is what I feared: (https://developercommunity.visualstudio.com/t/error-in-t4-you-must-add-a-reference-to-assembly-n/1300905)

    Unfortunately, while T4 templates can be used with .NET Core projects, you cannot use .NET Core libraries in your T4 template because the T4 engine uses .NET Framework for transformation and loading and running .NET Core libraries. NET Core code is not possible.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.