14
votes

I'm making some changes in an asp.Net MVC5 webapp, in which I used typelite to create .ts definitions from C# classes (really handy). For some reason now I've got this error when executing the T4:

Compiling transformation: The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes'.

and this warning:

Compiling transformation: Assuming assembly reference 'mscorlib, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' used by 'EnvDTE' matches identity 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' of 'mscorlib', you may need to supply runtime policy Mair.Tracking.Web

I guess it's something related to the EnvDTE version used by TypeLite and the reference to mscorlib EnvDTE uses. Should I add a bindingRedirect in the web.config?

I'm using VS2015 with Update2 CTP.

5
I don't use typelite but I also get the mscorlib warning since I updated VS2015 to CTP 2.Akinzekeel
I found your question and was reading thinking "perfect - exact same situation as me" right down to the version of VS2015, etc. Then sadness when I don't see an answer. I guess it's Update 2 CTP at fault. I'm going to install Update 2 RC in a few hours' time so will report back with an answer if that helpsIan Yates
Updated to Update 2 RC, same errorqwertoyo
Same problem in Update 2 RTM. And, for the record, my .tt file doesn't access any external third party libraries, nor is it targeted at PCL, it's just a standard T4 template that doesn't do anything spectacular, just uses EnvDTE (which is the assembly my .tt file is complaining about).Fred

5 Answers

11
votes

I can confirm that Portable class libraries in combination with T4 templates cause this problem in Visual Studio 2015 Update 2. I wasn't able to find better solution then retargeting TypeLITE to full .NET framework.

From the version 1.8.0 TypeLITE nuget package contains a copy of the library that targets full .NET framework. If your project targets full .NET framework, the correct TypeLITE assembly is picked up during installation and everything works fine in Visual Studio 2015 Update 2. Unfortunately if your project targets PCL, you are out of luck with Visual Studio 2015 Update 2. I am looking for better solution.

7
votes

Thanks to Ian Yates for opening the Connect item.

Microsoft re-released KB3151378 on May 4, 2016. I can confirm that this update addresses the issue when T4 templates are used with EDMX files. Unfortunately I do not use TypeLite, so I am unable to confirm that it addresses the OP's issue, though I would suspect it does.

From the KB page:

Issue 6:

In T4 templates, errors occur when you reference an assembly that's built for a version of the .NET Framework that differs from the desktop (full) framework. For instance, errors occur when you reference portable libraries.

2
votes

It looks like this should be fixed by KB3151378.

Notes for version 14.0.25130.0:

Issue 6

In T4 templates, errors occur when you reference an assembly that's built for a version of the .NET Framework that differs from the desktop (full) framework. For instance, errors occur when you reference portable libraries.

1
votes

Specifically for TypeLite, I opened my copy of it (fairly out of date but I've tweaked it to suit my needs) and stopped it being a portable library. That was done following the steps at https://stackoverflow.com/a/23135170/1053381. Now that it's not a portable library I'm able to execute my T4 template again.

I have many other T4 templates in my solution using ImmutableObjectGraph (search GitHub) and they ran fine despite it also using a portable library. I didn't dig too far into the specifics but I've learnt that mscorlib 2.0.5.0 is associated with portable libraries, etc and really we don't need TypeLite itself to be portable.

Hope this helps others.

There's also an open Connect issue at https://blogs.msdn.microsoft.com/visualstudio/2016/03/03/visual-studio-2015-update-2-rc/ since this is still a regression in VS2015 Update 2.

0
votes

I had the full version of the TypeLite 1.5.1 installed (Regular WebApplication .Net Full version 4.5.1) and simple updating to 1.8.1 helped to resolve the issue. So I should say that VS 2015 Update2 RC and Update2 RTM doesn't work neither with the FULL version of the TypeLite nor with the PORTABLE (yes, version 1.5.1 already has the portable version)