Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reference .Net standard in T4 file?

Tags:

I have a .Net standard 2.0 library. In this library I have a T4 file. The file contains these rows.

<#
            foreach (MessageType enumValue in Enum.GetValues(typeof(MessageType)))
            {
                var name = Enum.GetName(typeof(MessageType), enumValue);
#>

I get the following error in Visual Studio.

Compiling transformation: The type 'Enum' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.

How can I add a reference to 'netstandard'?

like image 921
Erik Z Avatar asked Sep 20 '17 16:09

Erik Z


2 Answers

Alternatively, you can use

<#@ assembly name="NetStandard" #>
like image 60
Huy Hoang Avatar answered Sep 25 '22 08:09

Huy Hoang


I had similar issue. I've solved this with adding reference inside t4 to file on disk

<#@ assembly Name="C:\Program Files\dotnet\sdk\2.1.4\Microsoft\Microsoft.NET.Build.Extensions\net461\lib\netstandard.dll" #>

if You don't have that file try to find netstandard.dll inside directory "C:\Program Files\dotnet\sdk"

like image 24
Jacek Avatar answered Sep 23 '22 08:09

Jacek