【问题标题】:How to reference an assembly from a tt macro如何从 tt 宏引用程序集
【发布时间】:2012-08-11 19:01:28
【问题描述】:

给定以下 tt 宏:

<#@ template debug="false" hostspecific="true" language="C#" #>
<#@ output extension=".xml" #>
<#@ assembly name="$(TargetPath)" #>
<#@ import namespace="System.Reflection" #>
<#
AssemblyInfoHelper assemblyInfo = new AssemblyInfoHelper(Assembly.LoadFrom(@"H:\My Projects\TestApp\bin\Windows Phone\Debug\TestApp.dll"));
#>
<?xml version="1.0" encoding="utf-8"?>
<Deployment xmlns="http://schemas.microsoft.com/windowsphone/2009/deployment" AppPlatformVersion="7.0">
...
</Deployment>

...我想使用 $(TargetPath) 的内容而不是硬编码程序集的完整路径来加载程序集...这可能吗?

非常感谢任何帮助:-)

谢谢 j3d

【问题讨论】:

标签: c# .net visual-studio-2010 t4


【解决方案1】:

如果您已经使用 $(TargetPath) 语法使用程序集指令加载程序集,那么您可以从程序集中选择一个类型,执行 typeof(Foo) 并从那里进入反射图而不是引用再次路径。

【讨论】:

  • 这是我的第一次尝试......但我总是收到以下错误:错误 4 运行转换:System.ArgumentNullException:值不能为空。参数名称:Microsoft.VisualStudio.TextTemplatingCA318D3CFBFC9BADB1A4FE595511DFB9.GeneratedTextTransformation.TransformText() 处的 System.Reflection.Assembly.GetAssembly(Type type) 处键入 Microsoft.VisualStudio.TextTemplating.TransformationRunner.RunTransformation(TemplateProcessingSession session, String source, ITextTemplatingEngineHost host, String& result ) 1 1
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-06-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多