How to reference .Net standard in T4 file?
Asked Answered
A

3

21

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'?

Alpaca answered 20/9, 2017 at 16:37 Comment(0)
F
23

Alternatively, you can use

<#@ assembly name="NetStandard" #>
Foresail answered 8/2, 2019 at 0:9 Comment(1)
It does not work anymore for the moment. Running transformation: System.IO.FileNotFoundException: Could not load file or assembly 'netstandard, Version=2.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies.Brobdingnagian
A
4

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"

Antinucleon answered 25/1, 2018 at 7:38 Comment(0)
V
4

This became an issue for us in the last few days. In addition we needed a solution that would work on all dev machines and all build machines.

So basically we copied the C:\Program Files\dotnet\sdk\2.1.4\Microsoft\Microsoft.NET.Build.Extensions\net461\lib\netstandard.dll file (and a couple of other standard files we needed) into a TTLibs folder under the solution.

Then we made the references in the TT solution-relative like this: <#@ assembly Name="$(SolutionDir)TTLib\netstandard.dll" #>

Vehemence answered 16/8, 2018 at 10:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.