Search code examples
azure-devopsazure-pipelinesazure-web-app-serviceasp.net-core-3.1azure-webjobs

How to deploy .NET Core 3.1 project to webjob?


How do we set up build/release pipelines in Azure Devops to automatically deploy a .NET Core 3.1 project as a webjob?

I manually created a web app in the portal:

enter image description here

I'm attempting to deploy the following project using Azure Devops:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.1</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <ProjectReference Include="..\BusinessManager\BusinessManager.csproj" />
    <ProjectReference Include="..\Models\Models.csproj" />
    <ProjectReference Include="..\Service\Service.csproj" />
  </ItemGroup>
</Project>

Here are my build tasks

enter image description here

dotnet build task details:

enter image description here

dotnet publish task details:

enter image description here

I'm getting the following error from the build

C:\Program Files\dotnet\sdk\9.0.101\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.ConflictResolution.targets(112,5): error NETSDK1152: Found multiple publish output files with the same relative path: D:\a\1\s\Controller.Tests\appsettings.json, D:\a\1\s\API\appsettings.json. [D:\a\1\s\Controller.Tests\Controller.Tests.csproj]

##[error]Error: The process 'C:\Program Files\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 : [ '' ]  
Finishing: dotnet publish

When disabling the dotnet publish and enabling the artifact drop, the build succeeds:

enter image description here

The release is triggered after the build artifacts are published:

enter image description here

However, I do not see the web job published in the portal

enter image description here

Questions

  1. What would indicate that the webjob is correctly published to the portal?
  2. What is the proper way to build a .NET Core 3.1 project using devops?
  3. Apologies if this question is vague and abstract, if you provide some constructive commentary, I'm happy to update this question and make it more focused and answerable.

Solution

  • I was able to build using yaml without having to upgrade anything and it released fine and works in portal.

    According to your comment, you are able to build using YAML, but it didn't work when you used the classic pipeline.

    Usually, as long as the same configuration is used in both YAML and the classic pipeline, the running results should be the same. In this case, you can export your classic pipeline to YAML and compare the differences between the exported YAML and your original YAML.

    Steps:

    1. Select your classic pipeline definition.

    2. Click the ellipses icon (three dots) and select "Export to YAML." Make sure you're in the pipeline definition view, not a specific run, to see the "Export to YAML" option. Screenshot of context menu, to export your pipeline to YAML.

    3. Open the downloaded YAML file in your code editor.

    4. Compare the downloaded YAML file with your original YAML file to identify any differences.

    5. Make the appropriate changes to your classic pipeline based on the comparison.

    6. Run the modified classic pipeline and check the result.