You are on page 1of 4

How to Create a Visual Studio Project for ESPRIT TNG

from an Existing E20xx Project

First check your existing Visual Studio project for E20xx and make sure of the following:
1. Make sure you are not using “Any CPU” configurations; E20xx projects should only use “x86”.
2. Make sure you are not using COM references for ESPRIT; only .NET Interop.Esprit*.dll references should
be used for ESPRIT projects.
3. Absolute HintPaths are strongly recommended for ESPRIT references. Visual Studio uses relative
HintPaths by default though, so you must open the .csproj or .vbproj project file in a text editor to check
and change these. You can also set ReferencePaths in the project properties Visual Studio, which by
default typically creates a .csproj.user or .vbproj.user file, although the information in the .user file can
also be manually inserted into the project file instead.

Then to create an ESPRIT TNG project from an E20xx project:


1. Copy the .csproj or .vbproj project file and the .sln solution file to create corresponding .TNG.csproj or
.TNG.vbproj and .TNG.sln files.
2. Edit the .TNG.??proj and .TNG.sln files in a text editor and make the following changes:
a. Mass replace x86 with x64 (again you should not be using “Any CPU”; E20xx projects should only
use “x86”; TNG projects should use “x64”).
b. Mass replace “C:\Program Files (x86)\D.P.Technology\ESPRIT\Prog” with “C:\Program
Files\D.P.Technology\ESPRIT TNG\Prog” (this assumes .NET Interop.Esprit references with
absolute HintPaths as described above).
c. Mass replace “C:\Program Files (x86)\Common Files\D.P.Technology\AnnexLibraries” with
“C:\Program Files\D.P.Technology\ESPRIT TNG\Prog” as well (again this assumes absolute
HintPaths).
d. Update the Project Name and file name in the .sln file to point to the .TNG.csproj or .TNG.vbproj
project file.
e. Mass replace the <ProjectGuid> in all files to a new Guid; you can use
System.Guid.NewGuid().ToString().ToUpper() to generate new Guids.
f. For an add-in project delete the line for the <PostBuildEvent> that runs regasm near the bottom
of the .TNG.??proj file (this does not apply to stand-alone .exe projects).
g. Also for an add-in project remove the complete <COMReference
Include="AddInDesignerObjects"> node from the .TNG.??proj file (or just remove the
AddInDesignerObjects Reference from Visual Studio as part of the next step).
3. Open the TNG solution in Visual Studio and make the following project changes:
a. For creating a TNG Extension from an E20xx add-in you must add References to:
• “C:\Program Files\D.P.Technology\ESPRIT TNG\Prog\ESPRIT.NetApi.dll”: use the
Browse… button to browse to the ESPRIT TNG\Prog installation folder and select the
ESPRIT.NetApi.dll; you can then typically set the “Copy Local” property to False for it.
• “System.ComponentModel.Composition”: this should be found under Assemblies >
Framework on the Add Reference dialog.
The two references listed above are required for TNG extensions.
b. For all project types (add-in or stand-alone .exe) as much as 80% of the code can be shared
between the E20xx and TNG projects. There will be some code that cannot be shared but
sharing as much of it as possible is strongly recommend for maintainability. For the code that
cannot be shared you will have to use conditional compiler directives to tell the compiler
whether that part of the code is for TNG or not. To set this up:
• In C# go to Properties > Build and for “All Configurations” add a TNG conditional
compilation symbol as shown in the first image below.
• In VB go to My Project > Compile tab and switch to “All Configurations”, then click the
“Advanced Compile Options…” button and add a Custom constant for TNG as shown in
the second image below.
4. You then need to use the TNG symbol/constant added in step 3b to differentiate the code that cannot
be shared between TNG and E20xx. If you have any compilation errors in your TNG project you just need
to compare the API and apply the #if compiler directives accordingly. For example one change in the
TNG API compared to E20xx that will cause complications is that Esprit.Operation in E20xx has been split
into Esprit.PartOperation and Esprit.MachineOperation in TNG, and likewise TNG has
Document.PartOperations and Document.MachineOperations collections instead of just
Document.Operations. In practice you can usually (but not always) just use Esprit.PartOperation in TNG
wherever you were using Esprit.Operation in E20xx as their members are mostly the same (including
their Technology, although the Technology itself may contain additional and/or modified parameters in
ESPRIT TNG), e.g. in C#:

#if (TNG)
foreach (Esprit.PartOperation op in Document.PartOperations)
#else
foreach (Esprit.Operation op in Document.Operations)
#endif

In VB.NET:

#If TNG Then


For Each op As Esprit.PartOperation In Document.PartOperations
#Else
For Each op As ESPRIT.Operation In Document.Operations
#End If

5. When creating a TNG Extension from an E20xx add-in one more place that you will need to use the TNG
symbol/constant and conditional compiler directives is with the Imports statements and attributes in
the “connecting” class (typically called Connect in Connect.cs or Connect.vb code file). The attributes
that must be applied to TNG extensions are completely different from the attributes applied to E20xx
add-ins and they come from different imported DLLs and namespaces. In C#:

#if (TNG) // must add corresponding References for these two using statements
using ESPRIT.NetApi.Extensions;
using System.ComponentModel.Composition;
#else
using System.Runtime.InteropServices;
#endif

#if (TNG)
[Export(typeof(IExtension)), ExportMetadata("SupportBuild", 20)]
public class Connect : DPTechnology.AnnexLibraries.EspritAddIn
#else
[ClassInterface(ClassInterfaceType.None), ComVisible(true),
Guid("5b0109b1-f251-4968-8b4f-6896d0704dd1"),
ProgId("E20xxSampleAddIn.Connect")]
public class Connect : DPTechnology.AnnexLibraries.EspritAddIn
#endif
In VB.NET:

#If TNG Then ' must add corresponding References for these two Imports statements
Imports ESPRIT.NetApi.Extensions
Imports System.ComponentModel.Composition
#Else
Imports System.Runtime.InteropServices
#End If

#If TNG Then


<Export(GetType(IExtension)), ExportMetadata("SupportBuild", 20)>
Public NotInheritable Class Connect
#Else
<ClassInterface(ClassInterfaceType.None), ComVisible(True),
Guid("5b0109b1-f251-4968-8b4f-6896d0704dd1"),
ProgId("E20xxSampleAddIn.Connect")>
Public NotInheritable Class Connect
#End If

You might also like