How to Properly add Accelerator DLL references to your Project using A4DNReference.msbuild

  • 623 Views
  • Last Post 08 March 2016
DerekMaciak posted this 08 March 2016

When you need to add Accelerator DLL references to your project, you want to make sure that the version and hint path are pulled from your A4DNReference.msbuild file.  This A4DNReference.msbuild file contains the Accelerator version and hintpath for your System.  When you upgrade your system using the Upgrade Utility, this is the main file that we are changing.  

Here is what the A4DNReference.msbuild file looks like.

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <A4DNVersion>6.2.0.0</A4DNVersion>
    <A4DNCoreHintPath>C:\Program Files\Accelerator for .NET\v6_2\Core\DotNet\</A4DNCoreHintPath>
    <A4DNSilverlightHintPath>C:\Program Files\Accelerator for .NET\v6_2\Core\Silverlight\</A4DNSilverlightHintPath>
    <A4DNMaintenanceHintPath>C:\Program Files\Accelerator for .NET\v6_2\Maintenance\</A4DNMaintenanceHintPath>
    <A4DNCodeFactoryHintPath>C:\Program Files\Accelerator for .NET\v6_2\CodeFactory\Wizards\</A4DNCodeFactoryHintPath>
    <A4DNJobMonitorHintPath>C:\Program Files\Accelerator for .NET\v6_2\JobMonitor\</A4DNJobMonitorHintPath>
  </PropertyGroup>
</Project>

You will notice that the file has the A4DNVersion as well as hint paths such as A4DNCoreHintPath to find the location of a specific Accelerator folder.

By using this file and linking to these variables in your project instead of hard coding this information, you can easily upgrade the Accelerator and all you projects will point to the correct folder and dll version.

To use this A4DNReference.msbuild file, we first need to add an import statement to your project file.  The Accelerator generates all your project files with this import statement already included.  If you created your own project in Visual Studio, then you need to manually add this import.

To add the import statement, open your project file (.csproj) in a text editor. Add this Import element to the project file after the Project element. Make sure that the relative path to the A4DNReference.msbuild file is correct.

<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="../../../A4DNReference.msbuild" />

Once you import the A4DNReference.msbuild file, you can now access the XML elements by using variables like this: $(A4DNVersion), $(A4DNCoreHintPath), $(A4DNMaintenanceHintPath) and so forth...

If you reference an Accelerator DLL via Visual Studio, it will add a reference to your project that looks like this. Notice the hard coded version number and hint path.

<Reference Include="A4DN.Core.BOS.Base, Version=6.2.0.0, Culture=neutral, PublicKeyToken=a051f91c03e970af, processorArchitecture=MSIL">
      <SpecificVersion>False</SpecificVersion>
      <HintPath>..\..\..\..\Program Files\Accelerator for .NET\v6_2\Core\DotNet\A4DN.Core.BOS.Base.dll</HintPath>
</Reference>

DerekMaciak posted this 08 March 2016

You want to correct this by opening the project in a text editor and replace any hardcoded Accelerator hint paths and versions with this syntax.

IMPORTANT - Accelerator DLLs in the Core\DotNET Folder or Core\DotNETDEBUG folders are versioned and Accelerator DLLs in the other folders are not. There is a slightly different syntax for versioned DLLs vs. non-versioned DLLs. Notice that the Culture, PublicTokenKey and processorAchitecture will be the same for all accelerator dlls.

For referencing a DLL in the Core\DotNet Folder (Versioned Syntax):

<Reference Include="A4DN.Core.BOS.Base, Version=$(A4DNVersion), Culture=neutral, PublicKeyToken=a051f91c03e970af, processorArchitecture=MSIL">
   <SpecificVersion>True</SpecificVersion>
   <HintPath>$(A4DNCoreHintPath)A4DN.Core.BOS.Base.dll</HintPath>
</Reference>

For referencing a DLL in the Maintenance Folder (Non-Versioned Syntax):

<Reference Include="A4DN.Extensions.WPF.PropertyCodes, Version=1.0.0.0, Culture=Neutral, PublicKeyToken=null">
   <SpecificVersion>False</SpecificVersion>
   <HintPath>$(A4DNMaintenanceHintPath)A4DN.Extensions.WPF.PropertyCodes.dll</HintPath>
</Reference>

Close