Search code examples
c#azure-webjobs

Why is my web job running in DEBUG mode on the server


I created a web job that runs on an Azure web app server. I am also using Devops to deploy the web job to the server. The deploy itself works, and the webjob (continuous) shows up on the server. However, when I check the logs, I see that it is logging some information that is within @if DEBUG tags. This is my first time using Devops with a web job. Is there something I could be doing wrong in the build/release process? Below is my yaml code for the build pipeline:

# ASP.NET

# Build and test ASP.NET projects.
# Add steps that publish symbols, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/apps/aspnet/build-aspnet-4

pool:
  vmImage: 'windows-latest'

variables:
  solution: '**/RingClone.Starter.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'

steps:
- task: NuGetToolInstaller@1

- task: NuGetCommand@2
  inputs:
    restoreSolution: '$(solution)'


- task: DotNetCoreCLI@2
  inputs:
    command: 'build'
    projects: 'Starter.RingCentral.IndexPriority.Voice/Starter.RingCentral.IndexPriority.Voice.csproj'
    arguments: '--configuration Release'

- task: DotNetCoreCLI@2
  inputs:
    command: 'publish'
    publishWebProjects: false
    projects: 'Starter.RingCentral.IndexPriority.Voice/Starter.RingCentral.IndexPriority.Voice.csproj'
    arguments: '--output $(Build.BinariesDirectory)/publish_output/App_Data/jobs/continuous/Starter.RingCentral.IndexPriority.Voice'
    zipAfterPublish: false
    modifyOutputPath: false


- task: ArchiveFiles@2
  inputs:
    rootFolderOrFile: '$(Build.BinariesDirectory)/publish_output'
    includeRootFolder: false
    archiveType: 'zip'
    archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
    replaceExistingArchive: true

- task: PublishBuildArtifacts@1
  inputs:
    PathtoPublish: '$(Build.ArtifactStagingDirectory)'
    ArtifactName: 'drop'
    publishLocation: 'Container'

Is there anything in here that could be causing the web job to be running in DEBUG mode?

Also, as requested, here is the contents of the main csproj file:

<Project Sdk="Microsoft.NET.Sdk;Microsoft.NET.Sdk.Publish">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.1</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="CsvHelper" Version="27.2.0" />
    <PackageReference Include="Dapper" Version="2.0.123" />
    <PackageReference Include="Microsoft.ApplicationInsights" Version="2.12.1" />
    <PackageReference Include="Microsoft.Azure.Cosmos" Version="3.9.1" />
    <PackageReference Include="Microsoft.Azure.WebJobs" Version="3.0.14" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions" Version="3.0.6" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="3.0.10" />
    <PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.1.0" />
    <PackageReference Include="Microsoft.Web.Deployment" Version="4.0.5" />
    <PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
    <PackageReference Include="System.Data.SqlClient" Version="4.8.3" />
    <PackageReference Include="System.Runtime.Caching" Version="4.7.0" />
    <PackageReference Include="System.ServiceModel.Duplex" Version="4.4.*" />
    <PackageReference Include="System.ServiceModel.Http" Version="4.4.*" />
    <PackageReference Include="System.ServiceModel.NetTcp" Version="4.4.*" />
    <PackageReference Include="System.ServiceModel.Security" Version="4.4.*" />
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\ConvosoActions\ConvosoActions.csproj" />
    <ProjectReference Include="..\FtpActions\FtpActions.csproj" />
    <ProjectReference Include="..\GlobalEntities\GlobalEntities.csproj" />
    <ProjectReference Include="..\InContactActions\InContactActions.csproj" />
    <ProjectReference Include="..\RingCentralOfficeHandActions\RingCentralOfficeHandActions.csproj" />
    <ProjectReference Include="..\RingCentral\RingCentralActions.csproj" />
    <ProjectReference Include="..\RingCloneCore\RingCloneCore.csproj" />
  </ItemGroup>
  <ItemGroup>
    <Reference Include="System.Runtime.Caching">
      <HintPath>C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Runtime.Caching.dll</HintPath>
    </Reference>
  </ItemGroup>
  <ItemGroup>
    <None Update="appsettings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="Settings.job">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
  </ItemGroup>
  <ItemGroup>
    <WCFMetadata Include="Connected Services" />
  </ItemGroup>
</Project>

Solution

  • (Converting my comments to an answer)

    The problem here is that your command: 'publish' action will cause a new build (rather than re-using the Release output of command: 'build'), but because the 'publish' action doesn't specify --configuration Release it will cause the MSBuild $(Configuration) property to default to DEBUG1.

    So change the arguments string of 'publish' to include --configuration Release and you should be good-to-go.


    I might recommend adding a new <Target> to your .csproj that will cause MSBuild to abort whenever $(Configuration) is not explicitly set, like so:

    // Ensure this <Target> is near the top of your `.csproj` so other <Import>'s defaults won't hide this issue.
    // https://learn.microsoft.com/en-us/visualstudio/msbuild/error-task?view=vs-2022
    
    <Target Name="ValidateCommandLine">
        <Error Condition="'$(Configuration)' == ''" Text="Build aborted because the 'Configuration' MSBuild property is not set." />
    </Target>
    

    1: For "pre-SDK" .csproj files, you'll find this MSBuild property in your first <PropertyGroup> element:

    <PropertyGroup>
        [...]
        <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
        <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
        [...]
    </PropertyGroup>
    

    ...while in "SDK-style" .csproj files this same <Configuration> property default still exists, but is located in dotnet\sdk\$version\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.DefaultOutputPaths.targets instead.