Home > Enterprise >  How to add tasks to azure dev ops starter?
How to add tasks to azure dev ops starter?

Time:10-28

I am new to azure dev ops and yml files. I recently created an Azure dev ops starter resource for a .NET Core site I built. I connected it to a github repo and pushed some files.

I am getting the error:

Build FAILED.

/home/runner/.dotnet/sdk/3.1.302/Microsoft.Common.CurrentVersion.targets(1177,5): error MSB3644: The reference assemblies for .NETFramework,Version=v5.0 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application

I researched the issue and came up with this solution https://stackoverflow.com/questions/65079876/error-msb3644-the-reference-assemblies-for-framework-netframework-version-v5#:~:text=assemblies for framework ".-,NETFramework,Version=v5.,SDK or Targeting Pack installed.

However I have no idea how to actually implement this. Do I create a separate yml file and it just fixes it when I push it to git?

I tried adding the following block to the devops-starter-workflow.yml file that was autogenerated by azure in the repo when it was auto created :

- task: UseDotNet@2
  displayName: 'Use .NET Core sdk 5.0.100'
  inputs:
    packageType: 'sdk'
    version: '5.0.100'
    includePreviewVersions: true

- task: DotNetCoreCLI@2
  displayName: 'dotnet restore'
  inputs:
    command: restore
    projects: '**/*.csproj'

but I got the error "every step must define a uses or run key"

How do I actually add this to my build? I dont see a pipeline anywhere in my azure portal.

CodePudding user response:

Are you specifying the MS Agent vs2017-win2016

Here is an example of one I have made should help you to figure it out your error looks to me like you are using the wrong agent as it cant find Visual Studio Code to be able to build the .Net App.

trigger:
  branches:
    include:
    - master

pr: none

pool:
   vmImage: vs2017-win2016

variables: 
  System.Debug: false
  azureSubscription: 'AzureSub'
  RG: 'myrg'
  Location: UK South 
  appconnectionname: 'azuresub/serviceprinciplename'

jobs:

  - job: job1
    displayName: Create And Publish Artifact
   
    steps:

    - task: UseDotNet@2 ## Not Needed For MS Self Hosted Agent. 
      displayName: Use .Net Core 5.0.301 SDK
      inputs:
        packageType: 'sdk'
        version: '5.0.301'

    - task: DotNetCoreCLI@2
      displayName: dotnet restore
      inputs:
        command: restore
        projects: 'Website.csproj' 
 
    - task: DotNetCoreCLI@2
      displayName: dotnet build
      inputs:
        projects: 'Website.csproj'
        arguments: '--configuration Release'
  
    - task: DotNetCoreCLI@2
      displayName: dotnet restore unit tests 
      inputs:
        command: restore
        projects: 'UnitTests/UnitTests.csproj'

    - task: DotNetCoreCLI@2
      displayName: dotnet Test
      inputs:
        command: test
        projects: 'UnitTests/UnitTests.csproj'
        arguments: '--configuration Release'
      
    - task: DotNetCoreCLI@2
      displayName: dotnet publish
      inputs:
        command: publish
        projects: 'Website.csproj'
        arguments: '--configuration Release --output $(Build.ArtifactStagingDirectory)'
        zipAfterPublish: true
        modifyOutputPath: false
      
    - task: PublishPipelineArtifact@1
      displayName: Publish Pipeline Artifact
      inputs:
        targetPath: '$(Build.ArtifactStagingDirectory)'
        artifact: 'Website'
        publishLocation: 'pipeline'

  - job: job2
    displayName: Create Web App 
    dependsOn: job1   
    steps:

    # Download Artifact File
    - download: none
    - task: DownloadPipelineArtifact@2
      displayName: 'Download Build Artifacts'
      inputs:
        patterns: '**/*.zip'
        path: '$(Build.ArtifactStagingDirectory)'

    # deploy to Azure Web App 
    - task: AzureWebApp@1
      displayName: 'Azure Web App Deploy: nsclassroom'
      inputs:
        package: $(Build.ArtifactStagingDirectory)/**/*.zip 
        azureSubscription: $(azureSubscription)
        ConnectedServiceName: $(appconnectionname)
        appName: 'nsclassroom'
        ResourceGroupName: $(RG)

 
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

Please put this in a YAML formatter in Azure DevOps to just check spaces or install YML Extension in VS Code.

CodePudding user response:

In the portal I created a seperate Web App and set the service to .Net version 5 instead of Core v3 and was able to build it properly. A new yml file was created and I had to just update the build and publish processes to the path with my csproj. I think all along I needed the webapp - not devops starter

  • Related