Azure Pipelines: .NET Core 3.0: Can't publish - azure-devops

I am having an issue with Azure Pipelines. I am trying to build an ASP.NET Core 3.0 project. Yes, I know it's not supported yet, but other questions say you can do it by including the following in the pipeline script. I am not sure how to do that, however.
task: DotNetCoreInstaller#0
displayName: 'Install .net core 3.0 (preview)'
inputs: version: '3.0.100-preview6-012264'
Do I paste the above in the following script? If not, where would I place it? Also, I am on Preview 9 at present—is that supported yet?
# ASP.NET Core
# Build and test ASP.NET Core projects targeting .NET Core.
# Add steps that run tests, create a NuGet package, deploy, and more:
# https://learn.microsoft.com/azure/devops/pipelines/languages/dotnet-core
trigger:
- master
pool:
vmImage: 'ubuntu-latest'
variables:
buildConfiguration: 'Release'
steps:
- script: dotnet build --configuration $(buildConfiguration)
displayName: 'dotnet build $(buildConfiguration)'

Do I paste the following in the below script or where would i place it
You can paste following scripts at begin of Steps, like:
steps:
- task: UseDotNet#2
displayName: 'Use .NET Core sdk 3.0.100-preview9-014004'
inputs:
version: '3.0.100-preview9-014004'
includePreviewVersions: true
- task: dotnet build --configuration $(buildConfiguration)
displayName: 'dotnet build $(buildConfiguration)'
...
You can get it by searching use .net core in the search box:
I am on preview 9 at present does that support it yet
The answer is yes. This task is used to install the .NET SDK, which supports the .NET core 3.0 preview versions list.
As test result:
Hope this helps.

You probably want to use the UseDotNet#2 task. You can add it to your list of steps.
Here's an example...
- steps:
- task: UseDotNet#2
displayName: 'Use .NET Core sdk'
inputs:
packageType: sdk
version: 3.x
includePreviewVersions: true
installationPath: $(Agent.ToolsDirectory)/dotnet
- script: ... etc etc
displayName: Continue as normal, now that the .net core 3.x SDK is installed.
And yes, preview9 is supported. So is rc1. This step installs the latest 3.x version and includes all previews. Once it's released, you can remove the includePreviewVersions field if you want.
For more info, the docs are here: https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/tool/dotnet-core-tool-installer?view=azure-devops

Related

AzureDevOps Pipleline force Task to install a certain version / old version of .Net Maui

After the latest .Net Maui update, my iOS app will longer build using the macos-12 image. Does anyone know how to specify an older version of .Net Maui using the CmdLine#2 Task? Here is what my current Task looks like.
- task: CmdLine#2
displayName: 'Install Maui'
inputs:
script: 'dotnet workload install maui'
The new version of .Net Maui seems to be looking for Xcode 14.1 and the iOS 16.1 SDK because it's using microsoft.net.sdk.ios version 16.1.1481.
I'm trying to figure out what version to use and this is getting ridiculous. You would think that I could specify one of these versions, but that's simply not the case. This is so frustrating and makes no sense!!!
https://github.com/dotnet/maui/releases
You would think that something like this would work.
- task: CmdLine#2
displayName: 'Install Maui'
inputs:
script: 'dotnet workload install --sdk-version 7.0.1xx maui'
https://maui.blob.core.windows.net/metadata/rollbacks/7.0.1xx.json
This seems to suggest that the version of Asp.net determines the .Net Maui version.
https://learn.microsoft.com/en-us/answers/questions/947953/how-do-i-get-net-maui-service-releases.html
Maui version will be determined by .net version.
AzureDevOps Pipleline force Task to install a certain version / old version of .Net Maui
To install a certain version of .net Maui in Azure Pipeline, you can use the Use dotnet v2 task to set the .net version of the pipeline. Then it will install a certain version of Maui.
Here is an example:
steps:
- task: UseDotNet#2
displayName: 'Use .NET Core sdk 7.0.100'
inputs:
version: 7.0.100
- script: 'dotnet workload install maui'
displayName: 'Command Line Script'
Here is how I was able to install an old version of .Net Maui.
I told the Pipeline to use Version 7.0.100 of Asp.net.
- task: UseDotNet#2
displayName: .NET Version
inputs:
packageType: 'sdk'
version: '7.0.100'
I told the Pipeline to use the 7.0.1xx Release version of .Net Maui.
https://github.com/dotnet/maui/tree/release/7.0.1xx
- task: CmdLine#2
displayName: 'Install Maui'
inputs:
script: 'dotnet workload install maui --from-rollback-file https://maui.blob.core.windows.net/metadata/rollbacks/7.0.1xx.json --source https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet7/nuget/v3/index.json --source https://api.nuget.org/v3/index.json'

The current .NET SDK does not support targeting .NET Standard 2.0 when targeting multiple platforms

I have an existing Azure DevOps pipeline that was working fine, then stopped building with an error "The current .NET SDK does not support targeting .NET Standard 2.0". My initial thought is whether I should install .NET Standard 2.0 before the VSBuild task. I have a task "Use .NET Core sdk 5.x". Should I repurpose this or create a new "Use .NET Core sdk" task? If so, should the version be "2.1.x" to install netstandard2.0? We need to target multiple platforms such as
<TargetFrameworks>net45;net461;netcoreapp2.0;netstandard2.0;</TargetFrameworks>
yml:
- task: NuGetToolInstaller#1
displayName: Use NuGet 5.8.0
inputs:
versionSpec: 5.8.0
checkLatest: true
- task: NuGetInstaller#0
name: NuGetInstaller_1
displayName: NuGet restore **\*.sln
inputs:
solution: '**\*.sln'
nugetConfigPath: .nuget/NuGet.Config
nuGetVersion: 3.5.0.1829
- task: UseDotNet#2
displayName: Use .NET Core sdk 5.x
inputs:
version: 5.x
performMultiLevelLookup: true
- task: DotNetCoreCLI#2
displayName: dotnet restore
inputs:
command: restore
projects: '**/*.csproj'
selectOrConfig: config
nugetConfigPath: .nuget/NuGet.Config
- task: VSBuild#1
name: VSBuild_2
displayName: Build solution **\*.sln
inputs:
platform: $(BuildPlatform)
configuration: $(BuildConfiguration)
clean: true
msbuildArchitecture: x64
The current .NET SDK does not support targeting .NET Standard 2.0 when targetting multiple platform
To resolve this issue, you need to check the global.json file for your project, like below:
{
"projects": [ "src", "test" ],
"sdk": {
"version": "2.1.301"
}
}
Then you should install the specific SDK version instead of the Use .NET Core sdk 5.x.
- task: UseDotNet#2
displayName: Use .NET Core sdk 2.1.301
inputs:
version: 2.1.301
performMultiLevelLookup: true

Devops build pipeline yaml - The current .NET SDK does not support targeting .NET Standard 2.0

Currently we are using (git) Bitbucket as source control, and Bamboo for build and deployment.
One of our projects is a legacy .NET Framework 4.7.2 MVC application. Some projects in that solution were once migrated to netstandard2.0. So the main MVC project is .NET Framework 4.7.2, and all the others projects in the solution are either also .NET Framework 4.7.2, or netstandard2.0.
Visual Studio (2019) has no problems building and running the entire solution. And Bamboo has no problems building and deploying the solution as well. Bamboo builds with MSBuild.
But when I use the same MSBuild configuration in Azure DevOps, then I get build errors. I guess because of the mix of .NET SDK versions in the project.
My azure-pipelines.yml looks like this:
trigger:
- master
pool:
# also tried VS2019, but got same errors during build
vmImage: 'VS2017-Win2016'
variables:
solution: 'WebSolution.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller#1
- task: NuGetCommand#2
inputs:
restoreSolution: '$(solution)'
- task: VSBuild#1
inputs:
solution: '$(solution)'
msbuildArgs: '/p:Configuration=web-develop /p:DeployOnBuild=false /p:PublishProfile=web.pubxml /p:AllowUntrustedCertificate=True'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: PublishBuildArtifacts#1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'drop'
publishLocation: 'Container'
But why on Azure DevOps is it complaining about the mix of the SDK frameworks? Why is Visual Studio and Bamboo able to build the solution without any issue?
A compatible SDK version for global.json version: [2.0.2] from [D:\a\1\s\global.json] was not found
##[error]C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.TargetFrameworkInference.targets(126,5): Error : The current .NET SDK does not support targeting .NET Standard 2.0. Either target .NET Standard 1.6 or lower, or use a version of the .NET SDK that supports .NET Standard 2.0.
Project "D:\a\1\s\WebSolution.Bc.Common\WebSolution.Bc.Common.csproj" (2) is building "D:\a\1\s\Web.WebData\Web.WebData.csproj" (4:2) on node 1 (default targets).
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.TargetFrameworkInference.targets(126,5): error : The current .NET SDK does not support targeting .NET Standard 2.0. Either target .NET Standard 1.6 or lower, or use a version of the .NET SDK that supports .NET Standard 2.0. [D:\a\1\s\Web.WebData\Web.WebData.csproj]
Is there a way to fix this in DevOps without having migrate every project in the solution to .NET Core?
I was facing a similar issue mixing .net standard 2.1 and dotnet 6 in a test pipeline. I didn't even get an error in the inital test pipeline... it just failed like... "Hey I could execute everything, but I doubt you want me to succeed".
Anyway... it turned out to be the nuget package manager, which was complaining that some of the nugets in the solution are not compatible with every project in the solution
Heres what i did to fix it:
trigger:
- master
pool:
vmImage: windows-latest
steps:
#specify the nuget tool
- task: NuGetToolInstaller#0
inputs:
versionSpec: '5.x'
displayName: 'Use latest NuGet 5'
#restore the nuget packages manually
- task: NuGetCommand#2
inputs:
command: 'restore'
restoreSolution: '**/*.sln'
noCache: true
displayName: 'Restore NuGet Packages'
#specify the dotnet sdk manually
- task: UseDotNet#2
inputs:
packageType: 'sdk'
version: '6.x'
displayName: 'Use latest dotnet 6'
#start your actual pipeline
- task: DotNetCoreCLI#2
inputs:
command: 'build'
projects: '**/*.csproj'
displayName: 'Build Solution'
- task: DotNetCoreCLI#2
inputs:
command: 'test'
testRunTitle: 'Testing'
projects: '**/*.csproj'
displayName: 'Executing Unittests'
I know its been a long time but i still hope this helps someone out there.

Azure Devops CI for Azure Function failing to build. Strange compilation error

Following this code:
https://learn.microsoft.com/en-us/azure/azure-functions/functions-how-to-azure-devops?tabs=csharp%2Cwindows
the Build pipeline fail on the "script" task with this error
enter image description here
If I replace this:
- task: DotNetCoreCLI#2
inputs:
command: publish
arguments: '--configuration Release --output publish_output'
projects: '*.csproj'
publishWebProjects: false
modifyOutputPath: false
zipAfterPublish: false
with this:
task: VSBuild#1
inputs:
solution: '***.sln'
msbuildArgs: '/p:OutDir=$(System.DefaultWorkingDirectory)/publish_output'
the build work but I need to publish
The project is built with Visual studio 2019 template for azure function. I did add an extra project to separate the logic, but it's all core 3.1. any suggestions?
According to your screen shot :( the build is using .NET Core 2.2.401, which has already reached end of life and is not .NET Core 3.1 as you expect.
You need to add a UseDotNet task to install the required .NET core release. Recommendation is that you have a global.json file for the version you expect.
- task: UseDotNet#2
displayName: 'Use .NET Core SDK (global.json)'
inputs:
packageType: 'sdk'
useGlobalJson: true
For useGlobalJson: false you can specifiy the version which should be used explicitly.

Build Pipeline keep crashing at Publish level of Azure Functions

I am trying to build and deploy an Azure Function using Devops Pipeline (CI)
These are my steps
But everything till step Publish executing without any error. But at the Publish level I am getting this error (As in the image above)
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.
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://learn.microsoft.com/en-us/dotnet/core/tools/ and https://learn.microsoft.com/en-us/dotnet/core/compatibility/ . To learn about more such changes and troubleshoot, refer here: https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/build/dotnet-core-cli?view=azure-devops#troubleshooting
##[error]Project file(s) matching the specified pattern were not found.
Finishing: Publish
I thought its because of .Net version thats why I have added Use .NET 5.x step just before publish. But it still triggering the same error.
Here is the Yaml of these 3 steps
steps:
- task: DotNetCoreCLI#2 displayName: 'dotnet build' inputs:
projects: 'Toolset/ScheduledJobs/*.csproj'
steps:
- task: UseDotNet#2 displayName: 'Use .NET Core sdk 5.x' inputs:
version: 5.x
steps:
- task: DotNetCoreCLI#2 displayName: Publish inputs:
command: publish
publishWebProjects: false
projects: '--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingdirectory)/ScheduledJobs'
zipAfterPublish: false
modifyOutputPath: false
Please let me know what I did wrong there?
I developed the Azure Function (3.0) in VS 2019
When you publish you need provide path to the project like here:
- task: DotNetCoreCLI#2
inputs:
command: 'publish'
publishWebProjects: true
projects: 'BlazorSample.csproj'
arguments: '--configuration $(buildConfiguration) --output $(build.artifactstagingdirectory)"'
zipAfterPublish: false
workingDirectory: $(Build.SourcesDirectory)/stackoverflow/51-blazor-sample/BlazorSample
Please notice working directory at the end.
Also change your order bu putting
- task: UseDotNet#2 displayName: 'Use .NET Core sdk 5.x' inputs:
version: 5.x
before this:
- task: DotNetCoreCLI#2 displayName: 'dotnet build' inputs:
projects: 'Toolset/ScheduledJobs/*.csproj'