NuGet Restore task fails (not compatible with netcoreapp2.2), but it works in Visual Studio - azure-devops

I am trying to build a repository in Azure Pipelines. It builds OK in Visual Studio, but when using Azure Pipelines (with an agent running on a build machine), it fails with the following error:
The nuget command failed with exit code(1) and error
Project MyProject is not compatible with netcoreapp2.2 (.NETCoreApp,Version=v2.2).
Project MyProject supports: netstandard2.0 (.NETStandard,Version=v2.0)
How can I fix this?
And here is the yaml build script:
pool:
name: MyBuildServer
demands:
- msbuild
- visualstudio
steps:
- task: NuGetCommand#2
displayName: 'NuGet restore'
- task: VSBuild#1
displayName: 'Build solution **\*.sln'
- task: VSTest#2
displayName: 'Run tests'
inputs:
testSelector: 'testAssemblies'
testAssemblyVer2: |
**\*test*.dll
!**\*TestAdapter.dll
!**\obj\**
searchFolder: '$(System.DefaultWorkingDirectory)'

NuGet Restore task fails (not compatible with netcoreapp2.2), but it works in Visual Studio
It seems that the version of nuget used on the Azure pipeline is not the latest version, which may cause the incompatibility issues.
To resolve this issue, you can try to add a NuGet Tool Installer task point it to a Version of NuGet.exe to install, which you simply specify the version number of the desired NuGet.exe you want to execute in the build.
Once this have been properly configured, the builds all succeeded using the latest incarnation of .net core.
Besides, if above not resolve your question, you can try to use the dotnet restore task instead of nuget restore task.
Hope this helps.

Related

Download nuget package from remote feed without NuGetCommand#2/Nuget.exe available?

We have an ADO Build pipeline, which need download a nuget package from a remote feed.
Using a Windows agent, we can do something like
- task: NuGetCommand#2
displayName: Downloading nuget package
inputs:
command: custom
arguments: install "{{ parameters.packageName}}" d -source "${{ parameters.nugetFeed }}"
However, now we have switched to MarinerOS, which does not have mono installed, so nuget.exe is not working.
After searching around, DotNetCoreCLI#2 task is working in Linux OS, however in order to download a package, it needs a project file to be able to add the project reference and then restore the package.
- task: DotNetCoreCLI#2 // won't work as it cannot find any project files
displayName: Downloading nuget package
inputs:
command: 'custom'
arguments: package SomePackageName
vstsFeed: $(NugetFeed)
feedsToUse: 'select'
custom: 'add'
Since we do not have any project files nor solution files in our pipeline, how can we download a nuget package without Nuget.exe in ADO pipeline?

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 NuGet task just started failing (missing dotnet core)

I have recently discovered that my Azure DevOps pipeline has started failing. Originally I assumed I had broken it with my recent changes however if I run the same commit on the same branch (NOTE that I have renamed master to main) then it fails when it had previously succeeded:
Here is my YAML for the pipeline:
trigger:
- master
pool:
vmImage: 'vs2017-win2016'
steps:
- task: NuGetCommand#2
displayName: "NuGet Restore"
inputs:
command: 'restore'
restoreSolution: '**/*.sln'
feedsToUse: 'select'
- task: MSBuild#1
displayName: "NET 4.0 Build"
inputs:
solution: '**\Expressive.csproj'
configuration: 'Release'
- task: DotNetCoreCLI#2
inputs:
command: 'test'
projects: '**/*.csproj'
testRunTitle: 'Run all tests'
I have discovered this detail in the build log:
Errors in D:\a\1\s\Source\CSharp\Expressive\Expressive.Tests\Expressive.Tests.csproj
Unable to resolve 'Microsoft.NETCore.App (>= 3.0.0)' for '.NETCoreApp,Version=v3.0'.
OK https://api.nuget.org/v3-flatcontainer/microsoft.netcore.dotnethostresolver/2.0.0/microsoft.netcore.dotnethostresolver.2.0.0.nupkg 39ms
OK https://api.nuget.org/v3-flatcontainer/microsoft.netcore.dotnethostresolver/2.2.0/microsoft.netcore.dotnethostresolver.2.2.0.nupkg 37ms
OK https://api.nuget.org/v3-flatcontainer/microsoft.netcore.dotnethostresolver/2.1.0/microsoft.netcore.dotnethostresolver.2.1.0.nupkg 38ms
OK https://api.nuget.org/v3-flatcontainer/system.runtime.serialization.json/4.0.2/system.runtime.serialization.json.4.0.2.nupkg 953ms
OK https://api.nuget.org/v3-flatcontainer/system.xml.xpath.xmldocument/4.0.1/system.xml.xpath.xmldocument.4.0.1.nupkg 955ms
So to summarise the only difference I can see is the fact that I have renamed master to main. I would be rather surprised if this is the cause of the problem though. Has anyone seen this or are able to provide assistance?
Update:
As workaround , switch to dotnet restore task to solve this issue .
Troubleshooting:
You can try to check the nuget version used by the nuget restore task in the pipeline running on the master branch. Then compare it with the nuget version used in pipeline running on the main branch to see if they are consistent.
If they are inconsistent, you can add a NuGet tool installer task to the main branch pipeline to use the same nuget version as the master branch pipeline.

nuget package restore failed in build pipeline after updating the visual studio 2017 to 2019 in build agent server

2020-04-23T07:13:09.4014026Z ##[error]Error: C:\BuildAgent_work_tool\NuGet\4.0.0\x64\nuget.exe failed with return code: 1 2020-04-23T07:13:09.4014026Z ##[error]Packages failed to restore 2020-04-23T07:13:09.4170281Z ##[section]Finishing: NuGet restore
It looks that you use an old 'NuGet version. Pleae se change it to a newer or use installer task to install 4.0.0
- task: NuGetToolInstaller#1
displayName: 'Use NuGet 4.0.0'
inputs:
versionSpec: 4.0.0
But I would recommend to get rid of hardcoding nuget version in your pipeline. There is already NuGet tool but newer.

VSTS build is not generating .msi file using .vdproj

I have VSTS Build which will generate the .msi file using .vdproj but I am not getting the .msi file out of the build.
I am getting the Warning MSB4078: The project file "abcdSetup\abcdSetup.vdproj" is not supported by MSBuild and cannot be built.
I am using Visual studio build task and MS build task to generate the .msi.
I have tried some ways and I installed third part task called create .msi file from VS installer Project.
I have attached the Snapshot of all the tasks using to generate this .msifile.
Please have a look and help me on this and also do let us know is there any task available in VSTS to create .msi file.
It wasn't possible until agent image Windows2019 was published. The new image is equipped with an extension for vdproj that is called Microsoft Visual Studio Installer Projects.
Steps:
Add a Command line task
Add there following line: "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\devenv.com" MyProjectDir\MySolution.sln /Rebuild Release
Remark: please note to use devenv.com (not devenv.exe). The "com" version outputs build log and errors to the console (standard output).
In 2022 today, looks like the Azure DevOps includes the Microsoft Visual Studio Installer Projects extension.
I was able to get a build using below pipeline configuration:
trigger:
- master
pool:
vmImage: 'windows-latest'
variables:
BuildConfiguration: 'Release'
BuildPlatform: 'Any CPU'
InstallerProject: 'YourInstallerProject/YourInstallerProject.vdproj'
Solution: 'YourSolution.sln'
VisualStudioPath: 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise'
steps:
- task: NuGetToolInstaller#1
displayName: 'Install Nuget CLI'
- task: NuGetCommand#2
displayName: 'Restore packages'
inputs:
restoreSolution: '$(Solution)'
- task: CmdLine#2
displayName: 'Prepare for MSI build'
inputs:
script: 'DisableOutOfProcBuild.exe'
workingDirectory: '$(VisualStudioPath)\Common7\IDE\CommonExtensions\Microsoft\VSI\DisableOutOfProcBuild'
- task: VSBuild#1
displayName: 'Build primary project'
inputs:
solution: '$(Solution)'
platform: '$(BuildPlatform)'
configuration: '$(BuildConfiguration)'
- task: CmdLine#2
displayName: 'Build installer project'
inputs:
script: '"$(VisualStudioPath)\Common7\IDE\devenv.com" "$(Solution)" /Project "$(InstallerProject)" /Build "$(BuildConfiguration)|$(BuildPlatform)"'
- task: CopyFiles#2
displayName: 'Copy MSI files'
inputs:
sourceFolder: '$(Build.SourcesDirectory)'
contents: '**/$(BuildConfiguration)/**/?(*.msi)'
targetFolder: '$(Build.ArtifactStagingDirectory)'
- task: PublishBuildArtifacts#1
displayName: 'Publish artifacts'
inputs:
pathToPublish: '$(Build.ArtifactStagingDirectory)'
artifactName: drop
Make sure to update the values of Solution and InstallerProject variables. If you would like to build with a Visual Studio version other than 2022, you must also edit VisualStudioPath variable.
I am getting the Warning MSB4078: The project file "abcdSetup\abcdSetup.vdproj" is not supported by MSBuild and cannot be built
That because MSBuild/Visual Studio does not have support for setup projects. To integrate with Azure DevOps, you will have to use devenv.
Note: starting VS 2013, .vdproj support is provided by an add-in.
That the reason why you got the error Warning MSB4078: The project file "abcdSetup\abcdSetup.vdproj" is not supported by MSBuild and cannot be built
Is there any way that we can generate .msi without setting up the
Private agent in VSTS ? Please let me know is there any task available.
I am afraid there is no such way you can generate .msi without setting up the Private agent in Azure DevOps, otherwise, we will always get the error:
Some errors occurred during migration. For more information, see the migration report: C:\VSTS-vs2017-agent\_work\9\s\Setup1\UpgradeLog.htm
I test it on the Private agent and local PC without installing the Visual Studio Installer Projects extension and got the same result. Then I installed that extension on the local PC and it works fine. So, we have to install the Visual Studio Installer Projects extension, if we want to build the setup projects.
Hope this helps.