How to Enhance Projects Using MSBuild on a Machine Without Telerik OpenAccess ORM Installed

Posted by: the telerik blogs, on 08 Jul 2009 | View original | Bookmarked: 0 time(s)

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. On the other hand when Telerik OpenAccess ORM is installed, the project enhancement is automatically done from our Visual Studio integration add-in. The MSBuild integration can be used as an alternative to the Microsoft Visual Studio integration and is useful while using the command-line build environment. It is targeted for serving build servers and build processes that are done using MSBuild and/or TFSBuild. In this blog I will introduce two possible ways of automating the enhancement process with MSBuild.


Using the tasks that come with OpenAccess.targets file

One way to do it is to include the OpenAccess.targets file (that comes with Telerik OpenAccess ORM installation) 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:

a) Import the .targets file in your project file, AFTER the import of the original Microsoft build targets which look like:


<Import Project="$(MSBuildBinPath)\Microsoft.VisualBasic.targets" />

<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />


b) Make sure that there are OpenAccess ORM settings  defined in the file, which look like:

     <UserProperties OpenAccess_EnhancementOutputLevel="1"   OpenAccess_UpdateDatabase="False" OpenAccess_Enhancing="True" 
          OpenAccess_ConnectionId="DBConnFirstSteps" OpenAccess_ConfigFile="App.config" />

- you can set the settings manually (they are pretty descriptive and explained here.)
- you can use the Telerik OpenAccess ORM VisualStudio integration (the wizards) to set the properties visually.


In the end you should have in your project file, something similar to the following:

<!--   ... Content of the .csproj file omitted here ... -->

<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath)\OpenAccess.targets" />
               OpenAccess_ConfigFile="App.config" />

After having all set in place we can use the task like this:

           Assembly="$(TargetPath)"  >
           <Output TaskParameter="Version" PropertyName="OpenAccessEnhancerVersion" />  

where:  $(TargetPath) stores the path to the assembly that will be enhanced.

In order to enhance an assembly that was signed and has a strong name, the following options must be added:

           KeyFile="$(ProjectDir)$(AssemblyOriginatorKeyFile)"  >  
           <Output TaskParameter="Version" PropertyName="OpenAccessEnhancerVersion" />  

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.


Using custom tasks file

A slightly different and lightweight approach is to use directly Exec tasks that will execute the enhancer. We prepared a small .targets file (the enhance.targets)that can be used out of the box and included in your build projects:


<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="">
   <OpenAccessInstallDir>C:\Program Files\Telerik\OpenAccess ORM</OpenAccessInstallDir>
 <Target Name="EnhanceAssembly" Condition="'$(_AssemblyTimestampBeforeCompile)'!='$(_AssemblyTimestampAfterCompile)'">
   <Copy SourceFiles="$(TargetPath)" DestinationFiles ="$(TargetPath).notenhanced"/>
   <Copy SourceFiles="$(PdbFile)" DestinationFiles ="$(PdbFile).notenhanced"/>
   <Exec IgnoreExitCode="false"
         Command=""$(OpenAccessInstallDir)sdk\venhance.exe" -verboseMode:2 -signAssembly "-keyFile:$(ProjectDir)$(AssemblyOriginatorKeyFile)" "-assembly:$(TargetPath)""
         Condition="'$(AssemblyOriginatorKeyFile)'!=''" />
   <Exec IgnoreExitCode="false"
         Command=""$(OpenAccessInstallDir)sdk\venhance.exe" -verboseMode:2 "-assembly:$(TargetPath)""
         Condition="'$(AssemblyOriginatorKeyFile)'==''" />
   <Copy SourceFiles="$(TargetPath)" DestinationFolder ="$(IntermediateOutputPath)"/>
   <Copy SourceFiles="$(PdbFile)" DestinationFolder ="$(IntermediateOutputPath)"/>
 <Target Name="PeVerify" Condition="'$(_AssemblyTimestampBeforeCompile)'!='$(_AssemblyTimestampAfterCompile)'">
     <Output TaskParameter="Path" PropertyName="SdkPath" />
   <Exec WorkingDirectory="$(SdkPath)bin" Command="peverify.exe /nologo "$(TargetPath)"" />

Just import the line 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:

<Import Project="[PATH_TO_TARGETS_FILE]\enhance.targets" />

where PATH_TO_TARGETS_FILE should be substituted with the real path to the .targets file.

Category: ASP.NET | Other Posts: View all posts by this blogger | Report as irrelevant | View bloggers stats | Views: 3359 | Hits: 28

Similar Posts

  • Using WCF with SQL Azure and Telerik OpenAccess more
  • Connecting to SQL Azure with Telerik OpenAccess more
  • How to display data from different tables using one data source more
  • Telerik OpenAccess WCF Wizard October CTP more
  • Binding Hierarchical RadGrid for ASP.NET Ajax with Telerik OpenAccess ORM more
  • Using the Telerik OpenAccess WCF Wizard with Multiple Versions of OpenAccess more
  • Visual Studio 2008 Intellisense and Telerik.Charting more

News Categories

.NET | Agile | Ajax | Architecture | ASP.NET | BizTalk | C# | Certification | Data | DataGrid | DataSet | Debugger | DotNetNuke | Events | GridView | IIS | Indigo | JavaScript | Mobile | Mono | Patterns and Practices | Performance | Podcast | Refactor | Regex | Security | Sharepoint | Silverlight | Smart Client Applications | Software | SQL | VB.NET | Visual Studio | W3 | WCF | WinFx | WPF | WSE | XAML | XLinq | XML | XSD