Define the solution configuration (debug / release) when running the T4 template to include the build in the solution

I am trying to get my T4 template to refer to my assembly in my solution so that when changing configurations between debugging and release it would include the correct assembly from my solution.

Here is what I 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 get this error when I try to start the main T4:

Error 1 Compilation of conversion: assembly with the same simple name "TestProject.Core", Version = 1.0.0.0, Culture = neutral, PublicKeyToken = null has already been imported. Try to remove one of the links or sign them to include side by side.

, , , , .

:

<#@ Assembly 
name="$(SolutionDir)TestProject.Core/bin/$(Configuration)/TestProject.Core.dll"#>

$()?

, Debug .

DLL , , .

+4
1

, DLL- T4 , Debug/Relase .

dll configs to goto, $(SolutionDir)\BuildArtifacts, T4.

,

PS. , ( , ), T4 - T4 "".

0

Source: https://habr.com/ru/post/1523622/


All Articles