Data Access has been discontinued. Please refer to this page for more information.

Telerik® Data Access .targets files

This article is relevant to entity models that utilize the deprecated Visual Studio integration of Telerik Data Access. The current documentation of the Data Access framework is available here.

This article will help you familiarize yourself with the purpose of the Telerik Data Access .targets files - why are they needed and which are the default settings they define.

Why is a .targets file necessary?

There are two Telerik Data Access .targets files - OpenAccess.targets which is deployed with the product`s installation and OpenAccessNuGet.targets which is deployed by the Telerik.DataAccess.Fluent NuGet. Both of these files serve the same purpose - they are loaded and used by the project containing the Telerik Data Access model to call the Telerik Data Access Enhancer as a post-build step. The Enhancer will add the persistent capability, change tracking and lazy loading functionality to the model. Due to this approach you will write less code, the domain model will be cleaner and the persistent classes more simple thus reducing the time you will need for development and testing.

Project settings

The Telerik Data Access .targets files define the default values of the settings controlling the behavior of the Enhancer. These default values are used when there are no explicitly defined values for the respective settings in the .csproj or .vbproj files of the project which is to be enhanced.

OpenAccess.targets settings:

<PropertyGroup>
    <UseXmlMapping Condition="'$(UseXmlMapping)'==''">
        true
    </UseXmlMapping>
    <UseAttributeMapping Condition="'$(UseAttributeMapping)'==''">
        true
    </UseAttributeMapping>
    <UseFluentMapping Condition="'$(UseFluentMapping)'==''">
        true
    </UseFluentMapping>
    <OpenAccessPath Condition="'$(OpenAccessPath)'==''">
        c:\Program Files\Telerik\Telerik Data Access
    </OpenAccessPath>
    <EnhancerAssembly Condition="'$(EnhancerAssembly)'==''">
        $(OpenAccessPath)\sdk\enhancer.exe
    </EnhancerAssembly>
    <EnhancerVerboseMode Condition="'$(EnhancerVerboseMode)'==''">3</EnhancerVerboseMode>
    <Use64BitEnhancer Condition="'$(Use64BitEnhancer)'=='' And '$(PlatformTarget)'=='x64'">
        true
    </Use64BitEnhancer>
    <ValidateMapping Condition="'$(ValidateMapping)'==''">false</ValidateMapping>
</PropertyGroup>
  • UseXmlMapping - this setting specifies whether Domain Models using Xml Mapping should be enhanced by the Enhancer. The default value is true.
  • UseAttributesMapping - this setting specifies whether models using Attributes Mapping should be enhanced by the Enhancer. The default value is true.
  • UseFluentMapping - this setting specifies whether models using Fluent Mapping should be enhanced by the Enhancer. The default value is true.
  • OpenAccessPath - this setting contains the path to the installation directory of Telerik Data Access.
  • EnhancerAssembly - this setting contains the path to the Enhancer executable, relative to the Telerik Data Access installation directory. The default value is $(OpenAccessPath)\sdk\enhancer.exe .
  • EnhancerVerboseMode - this setting specifies what information the Enhancer will display in the Error List window in Visual Studio. The default value is 3. There are three possible values:
    • 2 - errors
    • 3 - errors and warnings
    • 4 - errors, warnings and information
  • Use64BitEnhancer - depending on the platform target for the project, this setting automatically determines whether to call the Enhancer in a 32 or 64 bit process. For projects with target platform AnyCPU or x86 the Enhancer will be called in a 32 bit process. For projects with target platform x64 the Enhancer will be called in a 64 bit process.
  • ValidateMapping - this setting specifies whether the mapping of the model should be validated when the containing project is being build. The default value is false. We recommend you not to change the default value of this setting.

OpenAccessNuGet.targets settings:

<PropertyGroup>
    <UseXmlMapping Condition="'$(UseXmlMapping)'==''">false</UseXmlMapping>
    <UseAttributeMapping Condition="'$(UseAttributeMapping)'==''">false</UseAttributeMapping>
    <UseFluentMapping Condition="'$(UseFluentMapping)'==''">true</UseFluentMapping>
    <EnhancerAssembly Condition="'$(EnhancerAssembly)'==''">enhancer.exe</EnhancerAssembly>
    <EnhancerVerboseMode Condition="'$(EnhancerVerboseMode)'==''">3</EnhancerVerboseMode>
    <Use64BitEnhancer Condition="'$(Use64BitEnhancer)'=='' And '$(PlatformTarget)'=='x64'">
        true
    </Use64BitEnhancer>
    <ValidateMapping Condition="'$(ValidateMapping)'==''">false</ValidateMapping>
</PropertyGroup>

Since the Telerik Data Access NuGet packages do not provide the functionality to create Domain Models using Visual Designer, the default settings optimize the build process for enhancing Code First models.

  • UseXmlMapping - this setting specifies whether Domain Models using Xml Mapping should be enhanced by the Enhancer. The default value is false.
  • UseAttributesMapping - this setting specifies whether models using Attributes Mapping should be enhanced by the Enhancer. The default value is false.
  • UseFluentMapping - this setting specifies whether models using Fluent Mapping should be enhanced by the Enhancer. The default value is true.
  • EnhancerAssembly - this setting contains the relative path to the Enhancer executable. The default value enhancer.exe is just a place holder. The actual path to the Enhancer executable is added to the .csproj or .vbproj file by the NuGet package install script.
  • EnhancerVerboseMode - this setting specifies what information the Enhancer will display in the Error List window in Visual Studio. The default value is 3. There are three possible values:
    • 2 - errors
    • 3 - errors and warnings
    • 4 - errors, warnings and information
  • Use64BitEnhancer - depending on the platform target for the project, this setting automatically determines whether to call the Enhancer in a 32 or 64 bit process. For projects with target platform AnyCPU or x86 the Enhancer will be called in a 32 bit process. For projects with target platform x64 the Enhancer will be called in a 64 bit process.
  • ValidateMapping - this setting specifies whether the mapping of the model should be validated when the containing project is being build. The default value is false. We recommend you not to change the default value of this setting.

The boolean values for the settings must always be specified with lower case.

Why is the OpenAccessNuget.targets file included in the project?

The OpenAccess.CodeFirst NuGet package adds the OpenAccessNuget.targets file to the project in which is installed. This file needs to be loaded by the project right after the C# or VB .targets file, on all development and testing machines. For this reason instead of storing the .targets file in the Packages folder in the solution, we recommended adding it within the project itself. This way it will be handled by the source control in which the project is included and will still be loaded successfully by the project even if you depend on the NuGet Package Restore functionality.