Friday, November 22, 2019

Common errors when you automate build using Azure DevOps build


Error-1
The nuget command failed with exit code(1) and error(System.AggregateException: One or more errors occurred. ---> System.InvalidOperationException: Cannot determine the packages folder to restore NuGet packages. Please specify either -PackagesDirectory or -SolutionDirectory.

Solution
I observed this error when I was trying to create automated build using Azure DevOps Pipeline and I changed **/*.csproj  from **/*.Sln as a file to build.

To Resolve this error, in the Pipeline Task select  NuGet & use Pack Option instead of Restore Option, Restore Option work for Solution file only not for project file.

Error-2
C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(775,5): Error : The OutputPath property is not set for project 'ABC.csproj'.  Please check to make sure that you have specified a valid combination of Configuration and Platform for this project.  Configuration='Release'  Platform='Any CPU'.  You may be seeing this message because you are trying to build a project without a solution file, and have specified a non-default Configuration or Platform that doesn't exist for this project.

Solution
Again if you are switching from .Sln file to .csproj or .vbproj file to be build then make sure you are selecting the correct "Platform" property.

For Project file , Platform property value is "AnyCPU" and 
For Solution file, Platform property value is "Any CPU" (with space)

so, you need to open project file in notepad and check PropertyGroup section and OutputPath tag should look like below.

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <OutputPath>bin\Release\</OutputPath>
      .
      .
</PropertyGroup>

Error-3
Response status code does not indicate success: 409 (Conflict - The feed already contains “*.dll <Version Number>”)

Solution:
When you get this error that mean project is building correctly but not increasing the build number, so server trying to push same dll version into NuGet and it not allow duplicate version number, and throw 409 error
If you choose "Skip duplicate version" option then it will resolve the issues but that will not be correct because latest version never deployed into NuGet server. 

The best solution I found, in NuGet Task select following option 
Command : pack
Automatic package versioning : Use the build numbers 

This will create new version every time when new DLL build successfully, so No 409 error.

No comments: