<#@ import namespace="System" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="System.Reflection" #>

<# 
    string platformFromDte = null;

    try {
        string repoRoot = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(Host.TemplateFile), @"..\"));
        string dllPath = Path.Combine(repoRoot, @"libs\Microsoft.VisualStudio.Interop.dll");
        if (File.Exists(dllPath)) {
            Assembly.LoadFrom(dllPath);
            var sp = Host as IServiceProvider;
            var dte = sp?.GetService(typeof(EnvDTE.DTE)) as EnvDTE.DTE;
            var projectItem = dte?.Solution?.FindProjectItem(Host.TemplateFile);
            var project = projectItem?.ContainingProject;
            var cfg = project?.ConfigurationManager?.ActiveConfiguration;
            platformFromDte = cfg?.PlatformName;
        } 
    } catch {
        // Log the exception if necessary
    }

    platformValue = platformFromDte 
                 ?? Environment.GetEnvironmentVariable("Platform") 
                 ?? Environment.GetEnvironmentVariable("PLATFORM") 
                 ?? "Any CPU";
#>