为什么我的 Web 作业在服务器上以 DEBUG 模式运行

问题描述 投票:0回答:1

我创建了一个在 Azure Web 应用服务器上运行的 Web 作业。我还使用 DevOps 将 Web 作业部署到服务器。部署本身可以正常工作,并且 webjob(连续)会显示在服务器上。但是,当我检查日志时,我发现它正在记录

@if DEBUG
标签内的一些信息。这是我第一次在 Web 作业中使用 DevOps。在构建/发布过程中我可能做错了什么吗?以下是我的构建管道的 yaml 代码:

# 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'

这里有什么东西可能导致 Web 作业在 DEBUG 模式下运行吗?

另外,根据要求,这里是主 csproj 文件的内容:

<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>
c# azure-webjobs
1个回答
0
投票

(将我的评论转换为答案)

这里的问题是您的

command: 'publish'
操作将导致新的构建(而不是重新使用
Release
command: 'build'
输出),但因为
'publish'
操作未指定
--configuration Release
它会导致MSBuild
$(Configuration)
属性默认为
DEBUG
1

因此,将

arguments
'publish'
字符串更改为包含
--configuration Release
,这样就可以了。


我可能建议在您的

<Target>
中添加一个新的
.csproj
,这将导致MSBuild在未明确设置$(Configuration)
时中止
,如下所示:

// 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:对于“pre-SDK”

.csproj
文件,您将在第一个
<PropertyGroup>
元素中找到此 MSBuild 属性:

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

...在“SDK 样式”中

.csproj
文件中,相同的
<Configuration>
属性默认值仍然存在,但位于
dotnet\sdk\$version\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.DefaultOutputPaths.targets
中。

© www.soinside.com 2019 - 2024. All rights reserved.