Azure / azure-functions-dotnet-worker

Azure Functions out-of-process .NET language worker
MIT License
416 stars 181 forks source link

Azure Devops Build Keeps Failing Due to Compile Items Being Included in Project File #1576

Open notmynameatthemoment opened 1 year ago

notmynameatthemoment commented 1 year ago

I'm running into this issue when I try to run dotnet publish in Azure Devops. It fails with the following error:

C:\Windows\system32\chcp.com 65001
Active code page: 65001
Info: .NET Core SDK/runtime 2.2 and 3.0 are now End of Life(EOL) and have been removed from all hosted agents. If you're using these SDK/runtimes on hosted agents, kindly upgrade to newer versions which are not EOL, or else use UseDotNet task to install the required version.
C:\hostedtoolcache\windows\dotnet\dotnet.exe publish D:\a\1\s\src\COMPASSDataIngestion\COMPASSDataIngestion.csproj -o D:\a\1\a\COMPASSDataIngestion -c Release
MSBuild version 17.3.2+561848881 for .NET
  Determining projects to restore...
  Restored D:\a\1\s\src\COMPASSDataIngestion\COMPASSDataIngestion.csproj (in 1.65 min).
D:\a\1\s\src\COMPASSDataIngestion\Functions\SB1Parser.cs(236,36): warning CS1998: This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread. [D:\a\1\s\src\COMPASSDataIngestion\COMPASSDataIngestion.csproj]
C:\hostedtoolcache\windows\dotnet\sdk\6.0.408\Microsoft.Common.CurrentVersion.targets(5097,5): error MSB3030: Could not copy the file "D:\a\1\s\src\COMPASSDataIngestion\local.settings.json" because it was not found. [D:\a\1\s\src\COMPASSDataIngestion\COMPASSDataIngestion.csproj]
##[error]Error: The process 'C:\hostedtoolcache\windows\dotnet\dotnet.exe' failed with exit code 1
C:\hostedtoolcache\windows\dotnet\dotnet.exe publish D:\a\1\s\src\S00PackageRun\S00PackageRun.csproj -o D:\a\1\a\S00PackageRun -c Release
MSBuild version 17.3.2+561848881 for .NET
  Determining projects to restore...
  Restored D:\a\1\s\src\S00PackageRun\S00PackageRun.csproj (in 2.93 sec).
C:\hostedtoolcache\windows\dotnet\sdk\6.0.408\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.DefaultItems.Shared.targets(190,5): error NETSDK1022: Duplicate 'Compile' items were included. The .NET SDK includes 'Compile' items from your project directory by default. You can either remove these items from your project file, or set the 'EnableDefaultCompileItems' property to 'false' if you want to explicitly include them in your project file. For more information, see https://aka.ms/sdkimplicititems. The duplicate items were: 'Controllers\SeatPackageController.cs'; 'Core\Application\MSOffice\IExcelWriter.cs'; 'Core\Application\Storage\BlobDto.cs'; 'Core\Application\Storage\BlobResponseDto.cs'; 'Core\Application\Storage\IStorageService.cs'; 'Infrastructure\Data\SqlService.cs'; 'Infrastructure\Data\Startup.cs'; 'Infrastructure\MicrosoftOffice\MicrosoftExcelService.cs'; 'Infrastructure\MicrosoftOffice\MicrosoftWordService.cs'; 'Infrastructure\MicrosoftOffice\Startup.cs'; 'Infrastructure\Middleware\ErrorResult.cs'; 'Infrastructure\Middleware\ExceptionMiddleware.cs'; 'Infrastructure\Middleware\Startup.cs'; 'Infrastructure\Services\DirectoryService.cs'; 'Infrastructure\Services\EMCDTemplateService.cs'; 'Infrastructure\Services\PackageSummaryTemplateService.cs'; 'Infrastructure\Services\SB1PackageReportTemplateService.cs'; 'Infrastructure\Services\Startup.cs'; 'Infrastructure\Services\TemplateServiceBase.cs'; 'Infrastructure\Startup.cs'; 'Infrastructure\Storage\BlobService.cs'; 'Infrastructure\Storage\Startup.cs'; 'Models\Compass\ExcelMappingFieldAttribute.cs'; 'Models\Compass\SB1PackageReportData.cs'; 'Models\Compass\TSOTransmittalData.cs'; 'Models\Configurations\AppSettingsConfiguration.cs'; 'Models\Configurations\AzureConfiguration.cs'; 'Models\Configurations\ConnectionStringsConfiguration.cs'; 'Models\Configurations\Startup.cs'; 'Models\PackageCriteria.cs'; 'Models\PackageStatistics.cs'; 'Models\WordTemplateField.cs'; 'Program.cs' [D:\a\1\s\src\S00PackageRun\S00PackageRun.csproj]
##[error]Error: The process 'C:\hostedtoolcache\windows\dotnet\dotnet.exe' failed with exit code 1
##[warning].NET 5 has some compatibility issues with older Nuget versions(<=5.7), so if you are using an older Nuget version(and not dotnet cli) to restore, then the dotnet cli commands (e.g. dotnet build) which rely on such restored packages might fail. To mitigate such error, you can either: (1) - Use dotnet cli to restore, (2) - Use Nuget version 5.8 to restore, (3) - Use global.json using an older sdk version(<=3) to build
Info: Azure Pipelines hosted agents have been updated and now contain .Net 5.x SDK/Runtime along with the older .Net Core version which are currently lts. Unless you have locked down a SDK version for your project(s), 5.x SDK might be picked up which might have breaking behavior as compared to previous versions. You can learn more about the breaking changes here: https://docs.microsoft.com/en-us/dotnet/core/tools/ and https://docs.microsoft.com/en-us/dotnet/core/compatibility/ . To learn about more such changes and troubleshoot, refer here: https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/build/dotnet-core-cli?view=azure-devops#troubleshooting
##[error]Dotnet command failed with non-zero exit code on the following projects : [
  'D:\\a\\1\\s\\src\\COMPASSDataIngestion\\COMPASSDataIngestion.csproj',
  'D:\\a\\1\\s\\src\\S00PackageRun\\S00PackageRun.csproj'
]
Finishing: Dotnet publish

I've pasted below my project file.

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <AzureFunctionsVersion>v4</AzureFunctionsVersion>
    <_FunctionsSkipCleanOutput>true</_FunctionsSkipCleanOutput>
    <OutputType>Exe</OutputType>
  </PropertyGroup>
  <ItemGroup>
    <Compile Include="Functions\AB3Parser.cs" />
    <Compile Include="Functions\AB3Scrubber.cs" />
    <Compile Include="Functions\DropProcessor.cs" />
    <Compile Include="Functions\AB1Parser.cs" />
    <Compile Include="Functions\AB1Scrubber.cs" />
    <Compile Include="Functions\SB1Parser.cs" />
    <Compile Include="Functions\SB1Scrubber.cs" />
    <Compile Include="Infrastructure\ExtensionMethods\DataTypeExtensions.cs" />
    <Compile Include="Infrastructure\ExtensionMethods\HttpRequestExtensions.cs" />
    <Compile Include="Infrastructure\ExtensionMethods\ServiceCollectionExtensions.cs" />
    <Compile Include="Infrastructure\Services\AppInsightsService.cs" />
    <Compile Include="Infrastructure\Services\AzureBlobService.cs" />
    <Compile Include="Infrastructure\Services\EmailService.cs" />
    <Compile Include="Infrastructure\Services\SqlService.cs" />
    <Compile Include="Models\DataIngestionField.cs" />
    <Compile Include="Models\ValidRequirement.cs" />
    <Compile Include="Program.cs" />
  </ItemGroup>
  <ItemGroup>
    <None Include="host.json" />
    <None Include="local.settings.json" />
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="Azure.Monitor.Query" Version="1.1.0" />
    <PackageReference Include="Azure.Storage.Blobs" Version="12.16.0" />
    <PackageReference Include="Dapper" Version="2.0.123" />
    <PackageReference Include="Microsoft.ApplicationInsights" Version="2.21.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.13.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.0.13" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.OpenApi" Version="1.5.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Storage.Blobs" Version="5.0.1" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.9.0" />
    <PackageReference Include="Microsoft.Data.SqlClient" Version="5.1.1" />
    <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
    <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
</Project>

For some reason the separate classes and functions are being included as Compile items and causing this issue. I can't delete the separate compile items because it seems to dereference them in the project file and are no longer linked. I didn't use to run into this issue before and need some guidance on this.

I am also pasting my pipeline code below, but it has worked on other project files without the compile items: parameters:

  SolutionPath: ""
  TestPath: ""

stages:
- stage: Build_Test_Publish
  dependsOn: []
  pool:
    vmImage: $(poolImage)
  jobs:
  - job: Build_Test_Publish
    displayName: Restore, Test, Publish
    steps:
    - task: UseDotNet@2
      displayName: 'Use .NET global.json version'
      inputs:
        packageType: sdk
        useGlobalJson: true
    - task: NuGetAuthenticate@1

    - task: PowerShell@2
      displayName: Dotnet test
      inputs:
        targetType: 'inline'
        script: 'dotnet test -v=normal -o $(Agent.TempDirectory)\WebAppContent\\ -l trx -r ${{parameters.TestPath}}/TestResults ${{parameters.TestPath}}'
      condition: ne('${{parameters.TestPath}}', '')

    - task: PublishTestResults@2
      displayName: 'Publish test results'
      inputs:
        testResultsFormat: 'VSTest'
        testResultsFiles: ${{parameters.TestPath}}/**/*.trx
        searchFolder: ${{parameters.TestPath}}/TestResults
        failTaskOnFailedTests: true
      condition: ne('${{parameters.TestPath}}', '')

    - task: DotNetCoreCLI@2
      displayName: 'Dotnet publish'
      inputs:
        command: publish
        publishWebProjects: false
        projects: '**/*.csproj'
        arguments: '-o $(build.artifactStagingDirectory) -c Release'
        zipAfterPublish: true
        modifyOutputPath: true

    - task: PublishSymbols@2
      displayName: 'Publish symbols path'
      inputs:
        SearchPattern: '**\bin\**\*.pdb'
        PublishSymbols: false
      continueOnError: true

    - publish: $(build.artifactstagingdirectory)
      displayName: 'Publish Artifact: function'
      artifact: function
      condition: succeededOrFailed()
notmynameatthemoment commented 1 year ago

Any update?