【发布时间】:2014-01-24 21:21:40
【问题描述】:
我正在尝试让我的 T4 模板以实用的方式在我的解决方案中引用我的程序集,这样当我在调试和发布之间更改配置时,它将包含我的解决方案中的正确程序集。
这是我尝试过的:
<#
// Figured out how to get the current Configuration
var serviceProvider = Host as IServiceProvider;
var dte = serviceProvider.GetService(typeof(DTE)) as DTE;
string ConfigName = dte.Solution.SolutionBuild.ActiveConfiguration.Name;
// I have verified that I am getting the strings "Debug", and "Release"
if (configName == "Debug") {
#>
<#@ include file="template.Debug.tt" #>
<# } else { #>
<#@ include file="template.Release.tt" #>
<# } #>
template.Debug.tt 文件如下所示:
<#@ Assembly
name="$(SolutionDir)TestProject.Core/bin/Debug/TestProject.Core.dll"#>
template.Release.tt 文件如下所示:
<#@ Assembly
name="$(SolutionDir)TestProject.Core/bin/Release/TestProject.Core.dll"#>
当我尝试运行主 T4 时出现此错误:
错误 1 编译转换:已导入具有相同简单名称“TestProject.Core”、Version=1.0.0.0、Culture=neutral、PublicKeyToken=null 的程序集。尝试删除其中一个引用或对其进行签名以并排启用。
我猜预处理器会处理程序集包含行,因为它发生在两个执行路径上,导致两个程序集都被引用。
也试过这个:
<#@ Assembly
name="$(SolutionDir)TestProject.Core/bin/$(Configuration)/TestProject.Core.dll"#>
有没有办法添加 $(Configuration)?这似乎是最合乎逻辑的选择
其他人似乎只是在他们的路径中硬编码调试。
在调试时引用错误的 DLL 并且不知道它是非常烦人的,并且在将代码发布到生产环境时这无助于事情顺利进行。
【问题讨论】:
标签: c# visual-studio-2012 dll .net-assembly t4