M
MertensToon
Guest
Dear all,
I'm very new to EnvDTE to automatically setup project configurations.
I need to make a application with Beckhoff PLC where the program is automatically configured. For this Beckhoff has the following guide:
Beckhoff Information System - English
When I try the c# code, visual studio starts up. After the startup I get the error:
An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in System.Dynamic.dll
Additional information: The template specified cannot be found. Please check that the full path is correct.
At the following line of code :
string template = @"C:\TwinCAT\3.1\Components\Base\PrjTemplate\TwinCAT Project.tsproj"; //path to project template
dynamic project = solution.AddFromTemplate(template, @"C:\Temp\VS_TC2\SolutionFolder\BAI", "projTemp");
The template is standing on the correct location. So all of this should be ok I think.
Below the complete code:
using System;
using System.IO;
using TCatSysManagerLib;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("********Auto load config Twincat********");
Console.WriteLine("Start");
// START VISUAL STUDIO 2015
Type t = System.Type.GetTypeFromProgID("VisualStudio.DTE.14.0"); // PROGID Visual studio 2017 is 15.0
Console.WriteLine("presenting the type:" + t);
EnvDTE.DTE dte = (EnvDTE.DTE)Activator.CreateInstance(t);
dte.SuppressUI = false;
dte.MainWindow.Visible = true;
// ADD PROJECT DIRECTORY
if (Directory.Exists(@"C:\Temp\VS_TC2\SolutionFolder"))
Directory.Delete(@"C:\Temp\VS_TC2\SolutionFolder", true);
Directory.CreateDirectory(@"C:\Temp\VS_TC2\SolutionFolder");
Directory.CreateDirectory(@"C:\Temp\VS_TC2\SolutionFolder\BAI");
dynamic solution = dte.Solution;
solution.Create(@"C:\Temp\VS_TC2\SolutionFolder", "MySolution1");
solution.SaveAs(@"C:\Temp\VS_TC2\SolutionFolder\BAI\BAI.sln");
string template = @"C:\TwinCAT\3.1\Components\Base\PrjTemplate\TwinCAT Project.tsproj"; //path to project template
dynamic project = solution.AddFromTemplate(template, @"C:\Temp\VS_TC2\SolutionFolder\BAI", "projTemp");
ITcSysManager sysManager = project.Object;
sysManager.ActivateConfiguration();
sysManager.StartRestartTwinCAT();
project.Save();
solution.SaveAs(@"C:\Temp\VS_TC2\SolutionFolder\MySolution1\MySolution1.sln");
Console.ReadLine();
}
}
}
Can anybody guide me into the correct direction?
Thanks in advance,
Kind regards,
Toon
Continue reading...
I'm very new to EnvDTE to automatically setup project configurations.
I need to make a application with Beckhoff PLC where the program is automatically configured. For this Beckhoff has the following guide:
Beckhoff Information System - English
When I try the c# code, visual studio starts up. After the startup I get the error:
An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in System.Dynamic.dll
Additional information: The template specified cannot be found. Please check that the full path is correct.
At the following line of code :
string template = @"C:\TwinCAT\3.1\Components\Base\PrjTemplate\TwinCAT Project.tsproj"; //path to project template
dynamic project = solution.AddFromTemplate(template, @"C:\Temp\VS_TC2\SolutionFolder\BAI", "projTemp");
The template is standing on the correct location. So all of this should be ok I think.
Below the complete code:
using System;
using System.IO;
using TCatSysManagerLib;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("********Auto load config Twincat********");
Console.WriteLine("Start");
// START VISUAL STUDIO 2015
Type t = System.Type.GetTypeFromProgID("VisualStudio.DTE.14.0"); // PROGID Visual studio 2017 is 15.0
Console.WriteLine("presenting the type:" + t);
EnvDTE.DTE dte = (EnvDTE.DTE)Activator.CreateInstance(t);
dte.SuppressUI = false;
dte.MainWindow.Visible = true;
// ADD PROJECT DIRECTORY
if (Directory.Exists(@"C:\Temp\VS_TC2\SolutionFolder"))
Directory.Delete(@"C:\Temp\VS_TC2\SolutionFolder", true);
Directory.CreateDirectory(@"C:\Temp\VS_TC2\SolutionFolder");
Directory.CreateDirectory(@"C:\Temp\VS_TC2\SolutionFolder\BAI");
dynamic solution = dte.Solution;
solution.Create(@"C:\Temp\VS_TC2\SolutionFolder", "MySolution1");
solution.SaveAs(@"C:\Temp\VS_TC2\SolutionFolder\BAI\BAI.sln");
string template = @"C:\TwinCAT\3.1\Components\Base\PrjTemplate\TwinCAT Project.tsproj"; //path to project template
dynamic project = solution.AddFromTemplate(template, @"C:\Temp\VS_TC2\SolutionFolder\BAI", "projTemp");
ITcSysManager sysManager = project.Object;
sysManager.ActivateConfiguration();
sysManager.StartRestartTwinCAT();
project.Save();
solution.SaveAs(@"C:\Temp\VS_TC2\SolutionFolder\MySolution1\MySolution1.sln");
Console.ReadLine();
}
}
}
Can anybody guide me into the correct direction?
Thanks in advance,
Kind regards,
Toon
Continue reading...