views:

101

answers:

1

I am looking at sharing my class library code between .NET 3.5 and Silverlight 3.

Since I am mainly developing for .NET, I am looking at auto-generating the Silverlight project file(s) from the corresponding .NET project file(s).

Thus, I have a T4 file, which complains in Silverlight with the following error message:

Error 1 Compiling transformation: The type or namespace name 'CompilerError' does not exist in the namespace 'System.CodeDom.Compiler' (are you missing an assembly reference?)

Error 2 Compiling transformation: The type 'System.CodeDom.Compiler.CompilerErrorCollection' is defined in an assembly that is not referenced. You must add a reference to assembly 'System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

Error 3 Compiling transformation: 'System.CodeDom.Compiler.CompilerErrorCollection' does not contain a definition for 'Add' and no extension method 'Add' accepting a first argument of type 'System.CodeDom.Compiler.CompilerErrorCollection' could be found (are you missing a using directive or an assembly reference?)

My emphasis shows that I'm missing a reference to a System.dll.

If I add the following line:

<#@ assembly name="System" #>

Then the .NET project complains with:

Error 1 Compiling transformation: An assembly with the same identity 'System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' has already been imported. Try removing one of the duplicate references.

It looks like I'll just have to change the code that builds the Silverlight project so that it only adds the generated .cs file, and leaves the .tt file out.

Or is there something I can do that will make both compilers happy?

This is the start of my .TT file:

<#@ template language="C#v3.5" #>
<#@ assembly name="System.Core" #>
<#@ assembly name="System" #>
<#@ output extension=".Designer.cs" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Collections.Generic" #>
+1  A: 

If what you need is to make sure your T4 works from the Silverlight project, you can easily do this by adding the following line to ask T4 host to load the correct System.dll

<#@ assembly name="C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.dll" #>

See this detailed post here

http://msmvps.com/blogs/theproblemsolver/archive/2009/03/24/getting-t4-templates-to-work-with-silverlight.aspx

Hope this helps

amazedsaint
Thanks, that seems to work better than just "System".
Lasse V. Karlsen