Sometimes we need to build Telerik OpenAccess ORM enhanced projects on a machine that has no installation of the OpenAccess product. There are cases that even require that there is no such installation done on the machines like build servers or other machines that handle the build process.
One way to do it is to include the OpenAccess.targets file in your C# or VB project and use the targets defined there to enhance it. The project is automatically installed under the $(MSBuildExtensionsPath) directory. There are few requirements that must be met when using the OpenAccess.targets file:
- Import the .targets file AFTER the import of the original Microsoft build targets which look like:
.vbproj |
Copy Code |
<Import Project="$(MSBuildBinPath)\Microsoft.VisualBasic.targets" /> |
.csproj |
Copy Code |
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> |
- Make sure that there are OpenAccess ORM settings defined in the file, which look like:
|
Copy Code |
<ProjectExtensions> <VisualStudio> <UserProperties OpenAccess_EnhancementOutputLevel="1" OpenAccess_UpdateDatabase="False" OpenAccess_Enhancing="True" OpenAccess_ConnectionId="DBConnFirstSteps" OpenAccess_ConfigFile="App.config" /> </VisualStudio> </ProjectExtensions> |
- you can set the settings manually
or
- you can use the Telerik OpenAccess ORM VisualStudio integration (the wizards) to set the properties visually.
In the end you will have in your project file, something similar to the following:
|
Copy Code |
<!-- ... Content of the .csproj file omitted here ... -->
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <!-- THE FOLLOWING LINE IMPORTS THE TASKS AND DEPENDENCIES FROM OPENACCESS. --> <Import Project="$(MSBuildExtensionsPath)\OpenAccess.targets" /> <ProjectExtensions> <VisualStudio> <UserProperties OpenAccess_UseMSBuild="True" OpenAccess_EnhancementOutputLevel="1" OpenAccess_UpdateDatabase="True"" OpenAccess_Enhancing="True" OpenAccess_ConnectionId="DatabaseConnection1" OpenAccess_ConfigFile="App.config" /> </VisualStudio> </ProjectExtensions> </Project> |
After having all set in place we can use the task like this:
|
Copy Code |
<OpenAccessEnhancer VerboseMode="2" Assembly="$(TargetPath)" > <Output TaskParameter="Version" PropertyName="OpenAccessEnhancerVersion" /> </OpenAccessEnhancer> |
where: $(TargetPath) stores the path to the assembly that will be enhanced.
Enhancing a strong name assembly:
In order to enhance an assembly that was signed and has a strong name, the following options must be added:
|
Copy Code |
<OpenAccessEnhancer VerboseMode="2" Assembly="$(TargetPath)" SignAssembly="True" KeyFile="$(ProjectDir)$(AssemblyOriginatorKeyFile)" > <Output TaskParameter="Version" PropertyName="OpenAccessEnhancerVersion" /> </OpenAccessEnhancer> |
where SignAssembly is set to True and the KeyFile property contains the path to file containing the key.
You can find more information on all available MSBuild tasks for Telerik OpenAccess ORM here.
A slightly different and lightweight approach is to use directly Exec tasks that will execute the enhancer. We prepared a small .targets file that can be used out of the box and included in your build projects:
enhance.targets |
Copy Code |
<?xml version="1.0" encoding="utf-8"?> <Project> <PropertyGroup> <OpenAccessInstallDir>C:\Program Files\Telerik\OpenAccess ORM</OpenAccessInstallDir> </PropertyGroup> <Target Name="EnhanceAssembly" Condition="'$(_AssemblyTimestampBeforeCompile)'!='$(_AssemblyTimestampAfterCompile)'"> <Copy SourceFiles="$(TargetPath)" DestinationFiles ="$(TargetPath).notenhanced"/> <Copy SourceFiles="$(PdbFile)" DestinationFiles ="$(PdbFile).notenhanced"/> <Exec IgnoreExitCode="false" WorkingDirectory="$(TargetDir)" Command=""$(OpenAccessInstallDir)sdk\venhance.exe" -verboseMode:2 -signAssembly "-keyFile:$(ProjectDir)$(AssemblyOriginatorKeyFile)" "-assembly:$(TargetPath)"" Condition="'$(AssemblyOriginatorKeyFile)'!=''" /> <Exec IgnoreExitCode="false" WorkingDirectory="$(TargetDir)" Command=""$(OpenAccessInstallDir)sdk\venhance.exe" -verboseMode:2 "-assembly:$(TargetPath)"" Condition="'$(AssemblyOriginatorKeyFile)'==''" /> <Copy SourceFiles="$(TargetPath)" DestinationFolder ="$(IntermediateOutputPath)"/> <Copy SourceFiles="$(PdbFile)" DestinationFolder ="$(IntermediateOutputPath)"/> </Target> <Target Name="PeVerify" Condition="'$(_AssemblyTimestampBeforeCompile)'!='$(_AssemblyTimestampAfterCompile)'"> <GetFrameworkSdkPath> <Output TaskParameter="Path" PropertyName="SdkPath" /> </GetFrameworkSdkPath> <Exec WorkingDirectory="$(SdkPath)bin" Command="peverify.exe /nologo "$(TargetPath)"" /> </Target> <PropertyGroup> <PdbFile>$(OutputPath)\$(AssemblyName).pdb</PdbFile> <RunPostBuildEvent>OnOutputUpdated</RunPostBuildEvent> <PrepareForRunDependsOn> $(PrepareForRunDependsOn); EnhanceAssembly; PeVerify </PrepareForRunDependsOn> </PropertyGroup> </Project> |
Just import the fine at the bottom of your project fie – to do so unload the file from the solution,

open it for edit and include the import statement like:
|
Copy Code |
<Import Project="[PATH_TO_TARGETS_FILE]\enhance.targets" /> |
where
PATH_TO_TARGETS_FILE should be substituted with the real path to the .targets file.