Skip to main content

Use Azure Service Fabric with the .NET Framework or .NET Core agent

If you are using a container image, follow the instructions to install in containers. Otherwise, to add the Contrast .NET Framework or .NET Core agent to an Azure Service Fabric service:


For Standalone Executable services, the ServiceManifest.xml file is located in the top-level Azure Service Fabric project (for example, the sfproj file).

  1. Install the appropriate NuGet package to the main project for the service.

    • .NET Framework: Install Contrast.NET.Azure.AppService. All files in the contrastsecurity folder must have Copy to Output Directory set to Copy if newer.

    • .NET Core: Install Contrast.SensorsNetCore. All files in the contrast folder have Copy to Output Directory set to Copy if newer.

  2. Set ServiceManifest/CodePackage/EntryPoint/ExeHost/WorkingDirectory in ServiceManifest.xml to CodePackage.

    <CodePackage Name="Code" Version="1.0.0">
  3. Set environment variables in ServiceManifest.xml to configure the profiler.

    • .NET Framework:

                  <EnvironmentVariable Name="COR_ENABLE_PROFILING" Value="1"/>
                  <EnvironmentVariable Name="COR_PROFILER" Value="{EFEB8EE0-6D39-4347-A5FE-4D0C88BC5BC1}"/>
                  <EnvironmentVariable Name="COR_PROFILER_PATH_32" Value=".\contrastsecurity\runtimes\win-x86\native\ContrastProfiler.dll" />
                  <EnvironmentVariable Name="COR_PROFILER_PATH_64" Value=".\contrastsecurity\runtimes\win-x64\native\ContrastProfiler.dll" />
                  <EnvironmentVariable Name="CONTRAST_CONFIG_PATH" Value="contrast_security.yaml"/>
    • .NET Core:

                  <EnvironmentVariable Name="CORECLR_ENABLE_PROFILING" Value="1"/>
                  <EnvironmentVariable Name="CORECLR_PROFILER" Value="{8B2CE134-0948-48CA-A4B2-80DDAD9F5791}"/>
                  <EnvironmentVariable Name="CORECLR_PROFILER_PATH_32" Value="contrast\runtimes\win-x86\native\ContrastProfiler.dll"/>
                  <EnvironmentVariable Name="CORECLR_PROFILER_PATH_64" Value="contrast\runtimes\win-x64\native\ContrastProfiler.dll"/>
                  <EnvironmentVariable Name="CONTRAST_CONFIG_PATH" Value="contrast_security.yaml"/>
  4. Configure the agent with either:

    • A YAML file: Add it to the main project for the service. Make sure Copy to Output Directory for the file is set to Copy if newer. Add an environment variable to ServiceManifest.xml specifying the location of the file, like this:

                      <EnvironmentVariable Name="CONTRAST_CONFIG_PATH" Value="contrast_security.yaml"/>
    • Environment variables: Add them to ServiceManifest.xml, like this:

                  <EnvironmentVariable Name="CONTRAST__API__URL" Value=""/>
                  <EnvironmentVariable Name="CONTRAST__API__API_KEY" Value="aBcD0123"/>
                  <EnvironmentVariable Name="CONTRAST__API__SERVICE_KEY" Value="ABCD0123"/>
                  <EnvironmentVariable Name="CONTRAST__API__USER_NAME" Value="agent_123@Team"/>
  5. Deploy the Azure Service Fabric application as usual.