MSDN >
フォーラム ホーム
>
Visual Studio Extensibility
>
Does any one have source code for a working program that implements ITextTemplatingEngineHost
Does any one have source code for a working program that implements ITextTemplatingEngineHost
- I am trying to build a custom tool that does the same thing as the TextTemplatingFileGenerator custom tool that drives the T4 code generation process but is smart about how to find the XML files that I am using to drive my code generation process. Right now, I am using hard-coded references to the files. That works for the initial application but does not promote re-usability. I specifically want to eliminate any hard-coded references to the files.
There seem to be several ways that I could achieve this goal. First, I could put the logic to find the XML files into worker templates that I could include in each of the code generation templates; the templates are really just an appreviated programming language that are transformed into executable packages that generate the final code (very Zen like). Second, I could split each template into a thicker worker template that did the work based upon parameters passed to it and was ignorant of the file locations and a thinner controlling template that invoked the worker template, passing the locations of the source XML files as parameters. Third, I could embed the file location logic into a class that inherits from TextTransformation class; I could define properties and methods in that class that the worker templates could invoke to get the model data. Fourth, I could build a custom tool to replace the TextTemplatingFileGenerator custom tool that had all of the logic.
I went down the custom tool route because it seemed like this approach would be cleaner and would allow me to expand the logic into the MsBuild process or into a GUI-based tool. I really like the way that the custom tool works in the stage of building the templates. I have written the code (drawing from the example code in the MSDN article about ITextTemplatingEngineHost) but it throws the exception listed below. I do not trust the source of the code completely because the code was clearly out of date with respect to the .NET 3.5 version of the interface. The exception does not make any sense to me, but I think that I am safe in assuming that this is programmer error. The only question is where is the error. What I would like is the source code to a working implementration of a class that implements the ITextTemplatingEngineHost interface.
ErrorGeneratingOutput
C:\_Projects\Blog\CodeGeneration\CustomTemplateToolDriver\Test.tt(-1,-1) : error
: An Exception was thrown while running the transformation code. The process ca
nnot continue. The following Exception was thrown:
System.Runtime.Serialization.SerializationException: Type 'Microsoft.VisualStudi
o.TextTemplating.Engine' in Assembly 'Microsoft.VisualStudio.TextTemplating, Ver
sion=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' is not marked as
serializable.
Server stack trace:
at System.Runtime.Serialization.FormatterServices.InternalGetSerializableMemb
ers(RuntimeType type)
at System.Runtime.Serialization.FormatterServices.GetSerializableMembers(Type
type, StreamingContext context)
at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitMemberI
nfo()
at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSeriali
ze(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, S
erObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter
objectWriter)
at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.Serialize(O
bject obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerOb
jectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter obje
ctWriter)
at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Write(WriteObj
ectInfo objectInfo, NameInfo memberNameInfo, NameInfo typeNameInfo)
at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Obje
ct graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck)
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(S
tream serializationStream, Object graph, Header[] headers, Boolean fCheck)
at System.Runtime.Remoting.Channels.CrossAppDomainSerializer.SerializeMessage
Parts(ArrayList argsToSerialize)
at System.Runtime.Remoting.Messaging.SmuggledMethodCallMessage..ctor(IMethodC
allMessage mcm)
at System.Runtime.Remoting.Messaging.SmuggledMethodCallMessage.SmuggleIfPossi
ble(IMessage msg)
at System.Runtime.Remoting.Channels.CrossAppDomainSink.SyncProcessMessage(IMe
ssage reqMsg)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage req
Msg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgDa
ta, Int32 type)
at Microsoft.VisualStudio.TextTemplating.TransformationRunner.RunTransformati
on(String fullClassName, String baseClassName, String[] importedNamespaces, Stri
ng[] references, String source, String inputFile, Boolean debug, SupportedLangua
ges language, IDictionary`2 languageOptions, IFormatProvider format, ITextTempla
tingEngineHost host, Boolean cacheAssemblies, String& result)
at Microsoft.VisualStudio.TextTemplating.Engine.CompileAndRunCode(String gene
ratorCode, ITextTemplatingEngineHost host, TemplateProcessingSession session)
回答
- The ultimate answer to my issue may be found in the topic: http://social.msdn.microsoft.com/Forums/en-US/vsx/thread/543a9fc6-0aa4-4cb9-86a1-cde6ade85867.
- 回答としてマークJon Stonecash 2008年11月3日 10:48
すべての返信
- The ultimate answer to my issue may be found in the topic: http://social.msdn.microsoft.com/Forums/en-US/vsx/thread/543a9fc6-0aa4-4cb9-86a1-cde6ade85867.
- 回答としてマークJon Stonecash 2008年11月3日 10:48

