Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to build .NET 5 app in Azure DevOps Pipelines #5120

Closed
isaacrlevin opened this issue Aug 26, 2020 · 23 comments
Closed

Unable to build .NET 5 app in Azure DevOps Pipelines #5120

isaacrlevin opened this issue Aug 26, 2020 · 23 comments
Assignees

Comments

@isaacrlevin
Copy link

General

When I try to build a .net5 project in Azure Pipelines, I get this error

Error : Version 5.0.100-preview.8.20417.9 of the .NET Core SDK requires at least version 16.8.0 of MSBuild. The current available version of MSBuild is 16.7.0.37604. Change the .NET Core SDK specified in global.json to an older version that requires the MSBuild version currently available.

0>D:\a\1\s\src\PresenceLight\PresenceLight.csproj : error : Version 5.0.100-preview.8.20417.9 of the .NET Core SDK requires at least version 16.8.0 of MSBuild. The current available version of MSBuild is 16.7.0.37604. Change the .NET Core SDK specified in global.json to an older version that requires the MSBuild version currently available.

I have been building the app this way for multiple previews of .NET 5 now, so not sure what changed with Preview 8

@sfoslund
Copy link
Member

@rbhanda this can be closed as it is by design. Starting with preview 8 the SDK depends on a new MSBuild feature which is only available in 16.8 and above.

@rbhanda
Copy link
Contributor

rbhanda commented Aug 26, 2020

Closing as by design

@rbhanda rbhanda closed this as completed Aug 26, 2020
@isaacrlevin
Copy link
Author

@sfoslund is there a workaround for Azure DevOps/GitHub Action builds?

cc @rbhanda

@sfoslund
Copy link
Member

Yes, you need to have a recent enough version of MSBuild on the machine, so you can update your images to carry the latest preview of VS16.8.

@isaacrlevin
Copy link
Author

Is there a way to get these on hosted builds?

@sfoslund
Copy link
Member

I don't know, @mmitche?

@dsplaisted
Copy link
Member

You may be able to build your app with dotnet instead of msbuild. In that case it wouldn't use the version of VS/MSBuild on the hosted build machine, it would just use the version in the .NET Core SDK you are using.

@mmitche
Copy link
Member

mmitche commented Aug 31, 2020

I don't think there is currently any way to get the preview version of VS on the hosted pools. I'll bring it up in Tactics on Tuesday.

@robertmclaws
Copy link

Azure DevOps used to have a pool for the latest VS build, they need to bring that back. Also, they aren't even keeping the version on the existing instances current. The team needs to stay on top of this... I have projects that require both .NET Framework and .NET Core, and maintaining two different versions of my solution just to handle lack of effort on Microsoft's end costs my company money.

@samsmithnz
Copy link

I had a side conversation with Isaac, you can do this with two tasks. Putting the solution here for others who come here:

  1. UseDotNet@2 to download the new SDK.
    - task: UseDotNet@2
      displayName: 'Install .Net 5 SDK'
      inputs:
        packageType: 'sdk'
        version: '5.0.100-rc.1.20452.10'
  1. Use dotnet CLI, with self-contained and the runtime arguments.
 --self-contained true --runtime win-x64

You can also use the DotNetCoreCLI@2 task in Azure Piplines, for example:

    - task: DotNetCoreCLI@2
      displayName: 'Publish dotnet 5 projects'
      inputs:
        command: publish
        publishWebProjects: false
        projects: |
         SamLearnsAzure/SamLearnsAzure2.Web/SamLearnsAzure2.Web.csproj
        arguments: '--configuration release --output $(build.artifactstagingdirectory) -p:Version=$(buildNumber) --self-contained true --runtime win-x64'
        zipAfterPublish: true

@robertmclaws
Copy link

Appreciate this, and it works great when you are building from the CLI. The problem is I don't think you folks are testing this in multi-Framework configurations. I have a solution that has BOTH .NET Framework and .NET Core projects, and the code above will not help in that situation because Visual Studio is doing the compiling. Using CLI tasks will not stop the MSBuild process from failing, which will fail the whole process.

@jessyhoule
Copy link

I'm in the same boat as @robertmclaws. We have a mixed framework solution, in preparation for the .NET 5 release.

@robertmclaws
Copy link

Is there any solution for this yet, or are there no other solutions for mixed-solution projects until after the .NET 5 release.

@soumyamahunt
Copy link

Since .NET 5 is released now, is there any ETA on when this will be fixed??

@robertmclaws
Copy link

robertmclaws commented Nov 12, 2020

I have a solution for this before the Azure DevOps team deploys a new version within the next 2 weeks. Here's how it works:

image

Task 1: Install the .NET 5.0 SDK.
Task 2: Install the VS2019 Build tools through Chocolatey (the Choco runtime does not need to be installed, it's already on the agent.

  • Add Chocolatey to your Azure DevOps pipeline: https://marketplace.visualstudio.com/items?itemName=jungeriusit.jungit-choco
  • Once it's installed in your tenant, add an Install task to your pipeline.
    • The package is visualstudio2019buildtools.
    • Under "Advanced Options | Other Options", add the following value: --package-parameters "--allWorkloads --includeRecommended --includeOptional --passive --locale en-US"
      Task 3: Run a dotnet restore task with **/*.csproj as the project paths. Make sure you have your internal CI feeds authenticated, if necessary.
      Task 4: Disable your MSBuild task for now (you can delete the Chocolately task and re-enable this after the AzDO team deploys a new image in 1-2 weeks)
      Task 5: Add a Powershell task with the following Inline Script: & "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin\msbuild.exe" --% "$(Build.SourcesDirectory){PATH TO YOUR SOLUTION}" /nologo /nr:false /p:platform="$(BuildPlatform)" /p:configuration="$(BuildConfiguration)" /p:VisualStudioVersion="16.0"

THIS IS SUPER FREAKIN IMPORTANT:

You need to add the following build variables to re-map what would already be working under MSBuild:

  • MSBuildSDKsPath with the value C:\hostedtoolcache\windows\dotnet\sdk\5.0.100\Sdks\
  • SQLDBExtensionsRefPath with the value $(VSToolsPath)\SSDT
  • SqlServerRedistPath with the value C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\Extensions\Microsoft\SQLDB\DAC\150
  • VSToolsPath with the value C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Microsoft\VisualStudio\v16.0

Build normally.

Keep an eye on this page for VM image updates. When the Visual Studio version hits 16.8.0, you can remove these extra steps.

@virzak
Copy link

virzak commented Nov 13, 2020

@robertmclaws thanks so much.
Could you post the yaml output please for relevant tasks?

@robertmclaws
Copy link

This is what I used for SimpleMessageBus:

pool:
  name: Hosted Windows 2019 with VS2019
variables:
  BuildPlatform: 'any cpu'
  BuildConfiguration: 'debug'

steps:
- task: UseDotNet@2
  displayName: 'Use .NET Core sdk 5.x'
  inputs:
    version: 5.x

- task: jungeriusit.jungit-choco.jungit-chocoinstaller.ChocoInstallPackage@1
  displayName: 'Install visualstudio2019buildtools '
  inputs:
    packageId: 'visualstudio2019buildtools '
    extraOptions: '--package-parameters "--allWorkloads --includeRecommended --includeOptional --passive --locale en-US"'

- task: DotNetCoreCLI@2
  displayName: 'dotnet restore'
  inputs:
    command: restore
    projects: '**/*.csproj'
    vstsFeed: 'fff3d87c-fad3-4fdd-90f9-f8d6a5893a23'
    verbosityRestore: Minimal

- powershell: '& "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin\msbuild.exe" --% "$(Build.SourcesDirectory)\src\SimpleMessageBus.sln" /nologo /nr:false /p:platform="$(BuildPlatform)" /p:configuration="$(BuildConfiguration)" /p:VisualStudioVersion="16.0"'
  displayName: 'PowerShell Script'

- task: VSBuild@1
  displayName: 'Build solution **\SimpleMessageBus.sln'
  inputs:
    solution: '**\SimpleMessageBus.sln'
    platform: '$(BuildPlatform)'
    configuration: '$(BuildConfiguration)'
    maximumCpuCount: true
  enabled: false

- task: PublishBuildArtifacts@1
  displayName: 'Publish Artifact: drop'

@jaybo
Copy link

jaybo commented Nov 14, 2020

I tried all of the steps posted by @robertmclaws but got an error in the Build task:

Build started 11/14/2020 7:11:23 AM.
Project "D:\a\1\s\dzweb.csproj" on node 1 (default targets).
D:\a\1\s\dzweb.csproj : error MSB4236: The SDK 'Microsoft.NET.Sdk.Web' specified could not be found.
Done Building Project "D:\a\1\s\dzweb.csproj" (default targets) -- FAILED.

Nothing else seemed to fail. The one item I'm confused about is whether to use:

 --self-contained true --runtime win-x64

I tried appending these to the build task and got:

"C:\windows\System32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ". 'D:\a\_temp\1bbb7636-55f6-41d8-b134-09c10a4b3d67.ps1'"
MSBUILD : error MSB1001: Unknown switch.
Switch: --self-contained

@robertmclaws
Copy link

@jaybo Yeah that isn't the problem. There are more build variables you need to remap where to look for the .targets files. Working on getting my 30-project build working... once I have it then I'll update my post above with more details.

Thanks!

@robertmclaws
Copy link

I updated this comment with additional build variables that I discovered you need to add in order to make this work. NOTE: I did not add those variables to the YAML, you will need to do that yourself (I don't use YAML).

HTH!

@skypaint96
Copy link

skypaint96 commented Nov 15, 2020

I am managing to build and create an artifact for my asp.net (.net 5) project using this yaml.
I am a yaml noob still so it is mostly copy paste from built in templates and I took the Use .NET Core sdk 5.x task from robertmclaws
But it is working so far without the extra visual studio stuff.

trigger:
- master

pool:
  vmImage: 'windows-latest'

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'
steps:
- task: UseDotNet@2
  displayName: 'Use .NET Core sdk 5.x'
  inputs:
    version: 5.x
- task: DotNetCoreCLI@2
  inputs:
    command: 'restore'
    projects: '**/*.csproj'
    feedsToUse: 'config'
    nugetConfigPath: 'nuget.config'
- task: DotNetCoreCLI@2
  inputs:
    command: 'build'
    projects: '**/*.csproj'
    arguments: '--configuration $(BuildConfiguration)'
- task: DotNetCoreCLI@2
  inputs:
    command: 'test'
    projects: '**/*.Tests.csproj'
    arguments: '--configuration $(BuildConfiguration)'
- task: DotNetCoreCLI@2
  displayName: Publish
  inputs:
    command: publish
    publishWebProjects: True
    arguments: '--configuration $(BuildConfiguration) --output "$(build.artifactstagingdirectory)"'
    zipAfterPublish: True

Edit: my release CD that pushes the artifact to an azure app service isnt finding any artifact... but in the CI build I am not getting any errors

@robertmclaws
Copy link

@public-void-code Yes, that is the standard way to build .NET 5 apps, and it works because your project appears to be a pure .NET 5 app. As I mentioned, if you are doing any kind of mixed Framework configuration in the .sln, that will not work, and you will have to use my solution until they push another VM image within the next week.

@skypaint96
Copy link

@robertmclaws Ahh I see. Thanks anyway for the use net5 task that I was missing anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests