This project is read-only.

Smart device project

Aug 14, 2009 at 2:13 PM

I am unable to use T4 Toolbox inside a Smart Device project.

When I want to run my generator, I obtain this error :

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

Apparently, the T4 engine is using the compact framework with CodeDom's very small subset.

 

I've tried to add the following <#@ assembly name="System.dll" #> but nothing changed

or

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

But it bugs me on the double declaration of System.Net.NetworkCredential that I'm using in my template (since I've both System.dll for complete and compact runtime inside the AppDomain).

 

Have you faced this problem before ?

Aug 14, 2009 at 5:42 PM
nekresh --

Have you tried to use the same template-set on a class library project?

It seems to me that if you tried that then you would be able to more closely determine the culprit-- Is it in the template-set? Is it in the Smart-device-project? Is it in the integration point? Etc.

Furthermore, along the same lines, one solution for you might be to abstract the template-set parts so that they exist outside of the Smart-device-project, in a standard custom class library project for example. Maybe that will help?

Not having worked with Smart Device Projects at all, I am only guessing here, in the hopes that it might help.

Good luck.

Thank you.

-- Mark Kamoski
Aug 14, 2009 at 8:37 PM

Mark,

I tried this on a class library project.

The problem appears in the Generator.tt file, because the framework used for the compilation is the compact subset.

I was wondering if the custom host used by T4Toolbox can tweak the T4 execution engine to force using the full framework, instead of the restricted compact subset.

It's difficult for me to add another library :

- the framework will be the same, because compact framework library can only reference compact framework library (the opposite isn't true)

- I must build a single library file, because I use this library as an extension to a commercial project and do not have control over it

 

Thank for your quick answer. I will try to investingate further in T4Toolbox code ASAP.

Aug 14, 2009 at 9:07 PM
nekresh --

Given this...

It's difficult for me to add another library :
- the framework will be the same, because compact framework library can only reference compact framework library (the opposite isn't true)
- I must build a single library file, because I use this library as an extension to a commercial project and do not have control over it

...I would be inclined to suggest generating the code outside the target-project and just moving the output into the target-project-- you would still get all the benefit of the codegen (quick updates, incrementally moving towards code perfection, etc) and you could just script the file to be moved at post-build. Maybe. Perhaps it is not possible given your architectural constraints-- but, it could work for some scenarios.

With code generation, have fun. Template-code and generation-workflow can be a bit quick-and-dirty because it does not need to be perfect-- it just has to do its job.

On the output side, however, what is vastly more important is the output code itself-- so focus on THAT and do not focus on the workflow of where the templates live, etc.

Those rules of thumb may or may not apply to your particular case-- but, I would argue they DO apply to code generation in general.

Why? Because I would not trust the Framework parts involved at run-time (IL, JIT compiler, etc) to select the right version/subset to use. I recall we had many headaches when were trying to make a .NET Framework 2.0 web service expose a .NET Framework 1.0 DLL, which should be easy, right-- web services abstract the details of the code-called from the caller-- one of the main reasons for being in web services-- anyway, that was NOT an easy case and, in the end, we had to rewrite the Framework 1.0 piece to be Framework 2.0. So, while that example is not too close to what you are doing, it is similar in-kind and, as such, I would steer away if it were me.

(These are just musings from an subscriber to GEFN and YAGNI-- so, please take it as such.)

HTH.

Thank you.

-- Mark Kamoski
Aug 14, 2009 at 11:35 PM

Nekresh,

T4 Toolbox relies on the standard Visual Studio host, which does two things causing this problem. First, it declares "System.dll" to be a standard assembly reference (without specifying its version and location. And second, it uses assembly references of the current project that hosts the T4 file to resolve it. Although it is possible to get around the initial errors using approach described here: http://staxmanade.blogspot.com/2008/12/t4-text-templating-in-silverlight.html, I think that this behavior causes both version of the System.dll to be loaded in the templating AppDomain and, as you have discovered, results in errors when your code trying to use a type defined in both versions.

I can't think of any way to suppress this behavior without having to implement a custom host. Needless to say, this option requires a non-trivial amount of effort. Because this problem may also be addressed in Visual Studio 2010, I am reluctant to take on this project.

As a workaround, I would agree with Mark's suggestion and use a separate, regular .NET class library project to "host" your code generator. You should be able direct its output to your Smart Device project like so: http://www.olegsych.com/2009/03/t4-toolbox-generating-files-in-different-folders-and-projects/. Please let us know if this workaround doesn't work for you.

Oleg

Aug 18, 2009 at 10:33 AM

Oleg & Mark,

 

I've tried the generation in another project and it worked very well.

I've forgotten the OutputInfo part of T4Toolbox, so I thought I must copy/paste the generated file each time they are changed (or add link from visual studio).

The generation in other folders and project is a great fonctionnality.

Thanks to you, I am now able to generate the file from another project and integrate them directly in my Smart Device project.

 

Nekresh

Aug 18, 2009 at 2:09 PM
nekresh wrote:

It's difficult for me to add another library ... I must build a single library file, because I use this library as an extension to a commercial project and do not have control over it

Nekresh --

FYI, regarding how to build a single file library (how to combine multiple assemblies into one assembly), one can use the following to do it...

"

ASP.NET Merge Tool (Aspnet_merge.exe)

http://msdn.microsoft.com/en-us/library/bb397866.aspx 

The ASP.NET Merge tool (Aspnet_merge.exe) enables you to combine and manage assemblies that are

created by the ASP.NET Compilation tool (Aspnet_compiler.exe). The ASP.NET Merge tool works on

assemblies that have been created by using ASP.NET version 2.0 or later.

You can use the ASP.NET Compilation tool to precompile an application for deployment.

The tool creates one assembly for each content folder in the target Web site, or

it creates one assembly for each content file.

The ASP.NET Merge tool gives you additional flexibility for deployment and release management.

It enables you to do the following:

  • Create one assembly for the whole Web site.

  • Create an assembly for each Web site folder, and add a prefix to the assembly name.

  • Create a single assembly for just the Web site user interface (UI) elements, such as pages and controls.

"

HTH.

Thank you.

-- Mark Kamoski