SmartAssembly 7

Using SmartAssembly with Azure Pipelines

In this document you will learn how to integrate SmartAssembly into your existing Azure Pipelines build process on Microsoft-hosted agents.

Currently you can only use SmartAssembly on pipelines using build agents running on Windows.

You must use SmartAssembly 7.1 or newer.

Include SmartAssembly in the pipeline

In order to process your assemblies with SmartAssembly, you have to add appropriate tasks to your pipeline definition.

Depending on your pipeline's configuration (with or without YAML) follow one of the instructions below.

Option 1: Configure using the azure-pipelines.yml file

Securely storing SmartAssembly license key

  1. Sign-in to Azure DevOps: https://dev.azure.com/.
  2. From the main screen choose a project you’re working on.
  3. From the left-side menu choose Pipelines, then choose an existing pipeline and click Edit in the top-right corner.
  4. Click Variables in the top-right corner.
  5. To add a new variable click a "+" button next to a search field or a "New variable" button if there are no variables yet.
  6. In the Name field type SA_KEY. This name will later be used to activate and deactivate SmartAssembly.
  7. In the Value field provide your SmartAssembly license key.
  8. Check Keep this value secret to prevent the license key to be shown in Azure GUI and build logs (it will be replaced with ***).
  9. Click OK.

Installing SmartAssembly

Add the following tasks before building your project (usually before VSBuild@1 task).

The first task will download a package RedGate.SmartAssembly.Installer from NuGet. The second task will install SmartAssembly on a test agent using a provided license key.

- task: NuGetCommand@2
  displayName: 'SmartAssembly download'
  inputs:
    command: 'custom'
    arguments: 'install RedGate.SmartAssembly.Installer /OutputDirectory $(System.DefaultWorkingDirectory)'

- task: PowerShell@2
  displayName: 'SmartAssembly installation'
  inputs:
    targetType: 'inline'
    script: |
      $saExtractPath = "$(System.DefaultWorkingDirectory)\RedGate.SmartAssembly.Installer*\tools\"
      $saInstallLocation = "$(System.DefaultWorkingDirectory)\tools\SA\"
      
      "##[debug] Installing SmartAssembly..."
      $msiPath = (Get-ChildItem "$saExtractPath\SmartAssembly_*_x64.msi").FullName
      
      "Installing SmartAssembly from $msiPath into $saInstallLocation"
      $p = Start-Process -FilePath msiexec -Args "/qn /i `"$msiPath`" INSTALLDIR=`"$saInstallLocation`" RG_LICENSE=`"$(SA_KEY)`" RG_WARNING=`"Ignore`" REBOOT=`"ReallySuppress`" RG_I=`"Red Gate Software Ltd.`"" -Wait -Verbose -PassThru
      if ($p.ExitCode -ne 0) {
        throw "SmartAssembly installation failed. Installer exited with code: $($p.ExitCode)"
      }

Deactivating SmartAssembly

Add the following task after building your project (or at the end of the file).

The task will deactivate SmartAssembly to allow the license key to be used again.

- task: PowerShell@2
  displayName: 'SmartAssembly deactivation'
  condition: always()
  inputs:
    targetType: 'inline'
    script: |
      $saInstallLocation = "$(System.DefaultWorkingDirectory)\Tools\SA\"
      $saComPath = "$saInstallLocation\SmartAssembly.com"

      "##[debug] Deactivating SmartAssembly..."
      $p = Start-Process -FilePath $saComPath -Args "/deactivateSerial" -PassThru -NoNewWindow -Wait
      if ($p.ExitCode -ne 0) {
        throw "Unable to deactivate SmartAssembly."
      }

Executing SmartAssembly (optional)

If you want to run SmartAssembly manually, add the following task after building your project (usually after VSBuild@1 task):

- task: PowerShell@2
  displayName: 'SmartAssembly execution'
  inputs:
    targetType: 'inline'
    script: |
      $saInstallLocation = "$(System.DefaultWorkingDirectory)\Tools\SA\"
      $saComPath = "$saInstallLocation\SmartAssembly.com"

      "##[debug] Executing SmartAssembly..."
      & $saComPath /build "$(Build.SourcesDirectory)\AppsToObfuscate\Net472ConsoleApp\Net472ConsoleApp.saproj" # replace with path to your .saproj file

You can execute SmartAssembly.com as many times as needed, providing the path to .saproj file for each project.

It's recommended to configure projects to run SmartAssembly during the build process (see Using SmartAssembly with MSBuild). Doing so allows you to skip SmartAssembly execution task entirely, as it will happen automatically when building your application with MSBuild.

Option 2: Configure using the classic editor (without YAML)

Securely storing SmartAssembly license key

  1. Sign-in to Azure DevOps: https://dev.azure.com/.
  2. From the main screen choose a project you’re working on.
  3. From the left-side menu choose Pipelines, then choose an existing pipeline and click Edit in the top-right corner.
  4. Go to Variables tab and make sure Pipeline variables tab is selected on the left-side menu.
  5. Click Add button below the variables table.
  6. In the Name column type SA_KEY. This name will later be used to activate and deactivate SmartAssembly.
  7. In the Value column provide your SmartAssembly license key.
  8. Click on the padlock icon on the right side of the Value column to change variable type to secret, preventing the license key to be shown in Azure GUI and build logs (it will be replaced with ***).
  9. Click Save button located on a toolbar above the variables table.

Installing SmartAssembly

Task 1: SmartAssembly download

  1. On the pipeline edit screen make go to Tasks tab.
  2. From the list on the left-side of the screen select an agent job responsible for building your project.
  3. Click on the tinymce.emotions_dlg.add icon next to the agent job's name.
  4. Search for NuGet task, then click Add button. The task will now be added to the tasks list as NuGet restore.
  5. Drag the NuGet restore task and drop it at the beginning of the list.
  6. With the task selected, change its Name to SmartAssembly download.
  7. Change the Command field to custom.
  8. In the Command and arguments field paste the following command:

    install RedGate.SmartAssembly.Installer /OutputDirectory $(System.DefaultWorkingDirectory)
  9. Click Save button located on a toolbar above the tasks list.

Task 2: SmartAssembly installation

  1. On the pipeline edit screen make go to Tasks tab.
  2. From the list on the left-side of the screen select an agent job responsible for building your project.
  3. Click on the tinymce.emotions_dlg.add icon next to the agent job's name.
  4. Search for PowerShell task, then click Add button. The task will now be added to the tasks list as PowerShell Script.
  5. Drag the PowerShell Script task and drop it right after SmartAssembly download task.
  6. With the task selected, change its Name to SmartAssembly installation.
  7. Change the Type to Inline.
  8. In the Script field, paste the following PowerShell script:

    $saExtractPath = "$(System.DefaultWorkingDirectory)\RedGate.SmartAssembly.Installer*\tools\"
    $saInstallLocation = "$(System.DefaultWorkingDirectory)\Tools\SA\"
    
    "##[debug] Installing SmartAssembly..."
    $msiPath = (Get-ChildItem "$saExtractPath\SmartAssembly_*_x64.msi").FullName
    
    "Installing SmartAssembly from $msiPath into $saInstallLocation"
    $p = Start-Process -FilePath msiexec -Args "/qn /i `"$msiPath`" INSTALLDIR=`"$saInstallLocation`" RG_LICENSE=`"$(SA_KEY)`" RG_WARNING=`"Ignore`" REBOOT=`"ReallySuppress`" RG_I=`"Red Gate Software Ltd.`"" -Wait -Verbose -PassThru
    if ($p.ExitCode -ne 0) {
      throw "SmartAssembly installation failed. Installer exited with code: $($p.ExitCode)"
    }


  9. Click Save button located on a toolbar above the tasks list.

Deactivating SmartAssembly

  1. On the pipeline edit screen make go to Tasks tab.
  2. From the list on the left-side of the screen select an agent job responsible for building your project.
  3. Click on the tinymce.emotions_dlg.add icon next to the agent job's name.
  4. Search for PowerShell task, then click Add button. The task will now be added to the tasks list as PowerShell Script.
  5. Drag the PowerShell Script task and drop it at the end of the tasks list.
  6. With the task selected, change its Name to SmartAssembly deactivation.
  7. Change the Type to Inline.
  8. In the Script field, paste the following PowerShell script:

    $saInstallLocation = "$(System.DefaultWorkingDirectory)\Tools\SA\"
    $saComPath = "$saInstallLocation\SmartAssembly.com"
    
    "##[debug] Deactivating SmartAssembly..."
    $p = Start-Process -FilePath $saComPath -Args "/deactivateSerial" -PassThru -NoNewWindow -Wait
    if ($p.ExitCode -ne 0) {
      throw "Unable to deactivate SmartAssembly."
    }


  9. Under Control Options section set Run this task to Even if a previous task has failed, even if the build was cancelled. This will ensure SmartAssembly will always be deactivated, even if the build fails or is cancelled.
  10. Click Save button located on a toolbar above the tasks list.

Executing SmartAssembly (optional)

If you want to run SmartAssembly manually, add the following task after building your project (usually after the Visual Studio build task).

  1. On the pipeline edit screen make go to Tasks tab.
  2. From the list on the left-side of the screen select an agent job responsible for building your project.
  3. Click on the tinymce.emotions_dlg.add icon next to the agent job's name.
  4. Search for PowerShell task, then click Add button. The task will now be added to the tasks list as PowerShell Script.
  5. Drag the PowerShell Script task and drop it right after the Visual Studio build task on the tasks list.
  6. With the task selected, change its Name to SmartAssembly execution.
  7. Change the Type to Inline.
  8. In the Script field, paste the following PowerShell script:

    $saInstallLocation = "$(System.DefaultWorkingDirectory)\Tools\SA\"
    $saComPath = "$saInstallLocation\SmartAssembly.com"
    
    "##[debug] Executing SmartAssembly..."
    & $saComPath /build "$(Build.SourcesDirectory)\AppsToObfuscate\Net472ConsoleApp\Net472ConsoleApp.saproj" # replace with path to your .saproj file


  9. Click Save button located on a toolbar above the tasks list.

You can execute SmartAssembly.com as many times as needed, providing the path to .saproj file for each project.

It's recommended to configure projects to run SmartAssembly during the build process (see Using SmartAssembly with MSBuild). Doing so allows you to skip SmartAssembly execution task entirely, as it will happen automatically when building your application with MSBuild.

Configure error and feature reporting (optional)

SmartAssembly must be connected to a database and have access to a map files folder in order to use error reporting and feature reporting.

To learn how to configure SmartAssembly to use an external SQL database (e.g. Azure SQL) see Configure database connection on Azure Pipelines.

To learn how to configure SmartAssembly to store map files on Azure File Share see Configure error and feature reporting on Azure Pipelines.


Didn't find what you were looking for?