I'm trying to get my T4 template to reference my assembly in my solution in a practical way so that when I change configurations between debug and release, it will include the correct assembly from my solution.
This is what I have tried:
<#
// 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" #>
<# } #>
The template.Debug.tt file looks like this:
<#@ Assembly
name="$(SolutionDir)TestProject.Core/bin/Debug/TestProject.Core.dll"#>
And the template.Release.tt file looks like this:
<#@ Assembly
name="$(SolutionDir)TestProject.Core/bin/Release/TestProject.Core.dll"#>
I am getting this error when I try to run the main T4:
Error 1 Compiling transformation: An assembly with the same simple name 'TestProject.Core', Version=1.0.0.0, Culture=neutral, PublicKeyToken=null has already been imported. Try removing one of the references or sign them to enable side-by-side.
I'm guessing the preprocessor handles the assembly include line because it is happening along both execution paths which results in both assemblies being referenced.
Tried this too:
<#@ Assembly
name="$(SolutionDir)TestProject.Core/bin/$(Configuration)/TestProject.Core.dll"#>
Is there a way to add $(Configuration)? That seems like the most logical choice
Everyone else just seems to be hard coding Debug in their paths.
Referencing the wrong DLL and not knowing it is very annoying when debugging and it doesn't help things go smoothly when publishing your code to production.