You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hey, thanks for taking the time to rebuild this. I wanted to give it a try for a legacy project that still requires 2017. The extension installs but when I try to run a custom tool for template errors. It seems like some system information is not getting loaded. Here is a sample of the code that is failing to run:
public static void CalculateDatabaseConnectionString(ITextTemplatingEngineHost host)
{
DTE dte = (DTE)((IServiceProvider)host).GetService(typeof(SDTE));
List<Project> projects = new List<Project>();
try
{
foreach (var project in dte.Solution.Projects)
{
Project p = project as Project;
// Skip test and misc projects
if (p.Kind == "{67294A52-A4F0-11D2-AA88-00C04F688DDE}" || p.Kind == "66A26720-8FB5-11D2-AA7E-00C04F688DDE")
continue;
if (!p.Name.Contains("Curse.Cobalt"))
{
projects.Add(p);
}
}
}
catch (System.Runtime.Serialization.SerializationException)
{
// This is to skip projects that are a Database project
}
var solutionName = string.Empty;
var regex = new Regex(@"(.*?\\)*(?<solutionName>.*?)\.sln", RegexOptions.Compiled);
var match = regex.Match(dte.Solution.FullName);
if(match != null && match.Groups != null && match.Groups.Count > 0)
{
solutionName = match.Groups["solutionName"].ToString();
}
var implementationProjects = !string.IsNullOrEmpty(solutionName) ? projects.Where(p => p.Name.StartsWith(solutionName)) : projects;
////////// Fails Here .//////
var projectItem = implementationProjects
.Where(project => project.ProjectItems != null)
.SelectMany(project => project.ProjectItems.OfType<ProjectItem>())
.Where(pi => pi.Name == "Cobalt.config")
.First();
///////////////////////////////
string filename;
try
{
filename = projectItem.get_FileNames(0);
}
catch
{
try
{
filename = projectItem.Document.FullName;
}
catch
{
throw new InvalidOperationException("Unable to calculate file path for Cobalt.config");
}
}
var xml = XDocument.Load(filename);
var database = xml
.Elements("cobalt")
.Single()
.Elements("database")
.Single();
var activeKeyAtt = database.Attribute("activeKey");
string activeKey;
if (activeKeyAtt == null)
{
activeKey = "development";
}
else
{
activeKey = activeKeyAtt.Value;
}
var provider = database
.Elements("databaseProvider")
.Where(p => p.Attribute("key").Value == activeKey)
.Single();
string conn = provider.Attribute("connectionString").Value;
if (string.IsNullOrEmpty(conn))
{
throw new InvalidOperationException("Cannot calculate connection string");
}
_connectionString = $"{conn}Connection Timeout=90;";
string localConfigConnectionString = CalculateLocalConfigConnectionString(projects);
if (localConfigConnectionString != null)
{
_connectionString = $"{localConfigConnectionString}Connection Timeout=90;";
}
}
When running this block in 2017 using the original T4toolbox it runs without issues but this code produces this in 2022 using this T4Toolbox
Error Running transformation: System.InvalidOperationException: Sequence contains no elements
at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)
Do you have any thoughts if you are still around?
The text was updated successfully, but these errors were encountered:
Hey, thanks for taking the time to rebuild this. I wanted to give it a try for a legacy project that still requires 2017. The extension installs but when I try to run a custom tool for template errors. It seems like some system information is not getting loaded. Here is a sample of the code that is failing to run:
When running this block in 2017 using the original T4toolbox it runs without issues but this code produces this in 2022 using this T4Toolbox
Do you have any thoughts if you are still around?
The text was updated successfully, but these errors were encountered: