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

Error System.Data.Client #113

Open
Shurpop opened this issue Jul 29, 2021 · 0 comments
Open

Error System.Data.Client #113

Shurpop opened this issue Jul 29, 2021 · 0 comments

Comments

@Shurpop
Copy link

Shurpop commented Jul 29, 2021

Hello I am trying to use a connection to my database to execute the template, but i having the following error:
The type or namespace name 'SqlClient' does not exist in the namespace 'System.Data' (missing assembly reference?)
Error MSB3073 The command "dotnet t4 DbObjectsMapper.tt" exited with code 1


DbObjectsMapper.tt
<#@ template debug="false" hostspecific="false" language="C#" #>
<#@ include file="SqlHelper.ttinclude" #>
<#@ assembly name="System.Core" #>
<#@ assembly name="System.Data" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="System.Data.SqlClient" #>
<#@ output extension=".cs" #>

using System;
namespace Woffu.DiaryCatalog.Common.Context
{

}


SqlHelper.ttinclude
<#@ assembly name="System.Core.dll" #>
<#@ assembly name="System.Xml" #>
<#@ assembly name="System.Configuration" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="System.Data.SqlClient" #>
<#@ import namespace="System.Data" #>
<#@ import namespace="System.Data.Common" #>
<#@ import namespace="System.Diagnostics" #>
<#@ import namespace="System.Globalization" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Text.RegularExpressions" #>
<#@ import namespace="System.Configuration" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="System" #>
<#@ import namespace="Microsoft.VisualStudio.TextTemplating" #>



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

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netstandard2.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <DotNetCliToolReference Include="dotnet-t4-project-tool" Version="2.0.5" />
    <TextTemplate Include="**\*.tt" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Dapper" Version="2.0.90" />
    <PackageReference Include="Microsoft.Extensions.Configuration" Version="2.1.1" />
    <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.1.1" />
    <PackageReference Include="Microsoft.Extensions.Options" Version="2.1.1" />
    <PackageReference Include="System.ComponentModel.Annotations" Version="4.5.0" />
    <PackageReference Include="SqlKata" Version="2.3.7" />
    <PackageReference Include="System.Data.SqlClient" Version="4.8.2" />
  </ItemGroup>

  <Target Name="TextTemplateTransform" BeforeTargets="AfterBuild" >
    <ItemGroup>
      <Compile Remove="**\*.cs" />
    </ItemGroup>
    <Exec WorkingDirectory="$(ProjectDir)" Command="dotnet t4 %(TextTemplate.Identity)" />
    <ItemGroup>
      <Compile Include="**\*.cs" />
    </ItemGroup>
  </Target>

  <ItemGroup>
    <Compile Update="DbObjectsMapper.cs">
      <DesignTime>True</DesignTime>
      <AutoGen>True</AutoGen>
      <DependentUpon>DbObjectsMapper.tt</DependentUpon>
    </Compile>
    <Compile Update="DbObjectsMapper.cs">
      <DependentUpon>DbObjectsMapper.tt</DependentUpon>
    </Compile>
  </ItemGroup>

</Project>

If I use the tool of visual studio (Run Custom tool) it works and connects to my database without problems.

Any idea or suggestion? Thanks!

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

1 participant