Cannot build only one project of a solution in Azure Devops - azure-devops

I am trying to create a new build pipeline using Azure Devops. I can built the whole solution, however I am not able to build for a single project in the same solution.
I am getting the following error:
The nuget command failed with exit code(1) and error(Cannot determine the packages folder to restore NuGet packages. Please specify either -PackagesDirectory or -SolutionDirectory.) Packages failed to restore
Can anybody please help me?

Build only one project of a solution in Azure Devops
To resolve this issue, you should specify a directory for nuget to save the restore nuget packages, like:
When I restore the nuget packages for one project by packages.config/project file, we should expend the option Advanced on the nuget restore task, then specify a directory, I set it as default packages, ..\packages. Then I test it, it restored successfully:
2019-02-01T06:18:22.1311238Z ##[section]Starting: NuGet restore
....
2019-02-01T06:18:28.3155511Z [command]C:\VSTS-vs2017-agent\_work\_tool\NuGet\4.3.0\x64\nuget.exe restore C:\VSTS-vs2017-agent\_work\5\s\TestSample\TestSample\TestSample.csproj -PackagesDirectory ..\packages -Verbosity Detailed -NonInteractive -ConfigFile C:\VSTS-vs2017-agent\_work\5\Nuget\tempNuGet_169.config
2019-02-01T06:18:37.0366771Z All packages listed in packages.config are already installed.
2019-02-01T06:18:37.0594978Z ##[section]Finishing: NuGet restore
2019-02-01T06:18:22.1311238Z ##[section]Starting: NuGet restore
2019-02-01T06:18:22.1319968Z ==============================================================================
2019-02-01T06:18:37.0366199Z C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\bin\msbuild.exe "C:\Windows\ServiceProfiles\NetworkService\AppData\Local\Temp\NuGetScratch\svd0ok2h.e2f.nugetinputs.targets" /t:GenerateRestoreGraphFile /nologo /nr:false /v:q /p:NuGetRestoreTargets="C:\Windows\ServiceProfiles\NetworkService\AppData\Local\Temp\NuGetScratch\bhkdd2rf.itk.nugetrestore.targets" /p:RestoreTaskAssemblyFile="C:\VSTS-vs2017-agent\_work\_tool\NuGet\4.3.0\x64\nuget.exe" /p:RestoreConfigFile="C:\VSTS-vs2017-agent\_work\5\Nuget\tempNuGet_169.config" /p:RestorePackagesPath="..\packages"
2019-02-01T06:18:37.0366350Z
2019-02-01T06:18:37.0366771Z All packages listed in packages.config are already installed.
2019-02-01T06:18:37.0594978Z ##[section]Finishing: NuGet restore
The reason for the error:
When we only build or restore the nuget package for one project of a solution in Azure Devops, nuget restore the nuget packages to the default \packages folder under the solution folder, but since we do not specify the .sln file in the build/nuget restore task, nuget does not know where is the solution folder. Then nuget will throw that error. So, we should specify a directory for nuget to save the restore nuget packages.
Hope this helps.

Related

Azure DevOps Pipeline not downloading reference

I'm relatively new to Azure DevOps, but I've already created 4 other pipelines that are working. I'm running into trouble with a build pipeline that is not pulling in NuGet references. I added the Task NuGet restore, but it's only getting some of the packages.
It works when I build in Visual Studio 2017. If I do a nuget restore from the command line, some of the packages are fetched. When I build, Visual Studio fetches the additional packages at the beginning of the build. Why is the NuGet restore task not fetching all of the packages? Why are the remaining packages fetched during the Visual Studio build, but not during the Azure DevOps build?
My project is old legacy ASP.NET that my boss wants automated. I'm talking the version of ASP.NET with .ASPX files that preceded MVC.
This is the error from the Azure DevOps build:
[error]WebApp\web.config(95,0): Error ASPCONFIG: Could not load file or assembly 'Microsoft.ReportViewer.Common, Version=12.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The system cannot find the file specified.
For this issue , first, make sure to select vs2017-win2016 agent when running the pipeline.
Secondly you can try to install the latest nuget.
Another possibility for your issue could be that some packages used by your project is not hosted in nuget.org. If part of the packages used locally are hosted in private server or local package source, the online Nuget Restore Task can't download the mssing packages. Please check your packages.config and project file to make sure all your packages are hosted in nuget.org.

Is it possible to access private nuget server from Azure DevOps?

I wanted to set up a pipeline but it fails at the NuGet Restore with the following
Errors in packages.config projects
Unable to find version '1.0.0.5' of package 'mypackage'.
https://api.nuget.org/v3/index.json: Package 'mypackage.1.0.0.5' is not found on source 'https://api.nuget.org/v3/index.json'.
##[error]The nuget command failed with exit code(1) and error(Errors in packages.config projects
This package is actually stored on a local NuGet server of my company (internal network) not available from the internet.
Is it possible for Azure DevOps to access these packages?
Yes, it is possible.
You´ll need to have a Self-Hosted Agent ==> e.g. Windows. https://learn.microsoft.com/en-us/azure/devops/pipelines/agents/v2-windows?view=azure-devops
It makes sense if nuget is stored in a local Nuget repo
Setup Nuget.config to point it to your repo.
4, In the NuGet Restore task be sure to select the Feeds to use --> 'Feeds in my NuGet.config'
==> Example for Private-Repo stuff: https://medium.com/#churi.vibhav/creating-and-using-a-local-nuget-package-repository-9f19475d6af8

Error while running dotnet restore Microsoft.VisualStudio.Azure.Fabric.Application.props not found

When we run dotnet restore
C:\Program Files\dotnet\dotnet.exe" restore C:\agent\vsts-agent-win7-x64-2.119.1\vstswrk\58\s\My.Project.sln --configfile C:\agent\vsts-agent-win7-x64-2.119.1\vstswrk\58\Nuget\tempNuGet_3682.config --verbosity Detailed
"C:\agent\vsts-agent-win7-x64-2.119.1\vstswrk\58\s\My.Project.sln"
(Restore target) (1) ->
"C:\agent\vsts-agent-win7-x64-2.119.1\vstswrk\58\s\My.Project\My.Project.sfproj" (_IsProjectRestoreSupported target) (2) ->
(ValidateMSBuildFiles target) ->
C:\agent\vsts-agent-win7-x64-2.119.1\vstswrk\58\s\My.Project\My.Project.sfproj(49,5):
error : Unable to find the
'..\packages\Microsoft.VisualStudio.Azure.Fabric.MSBuild.1.6.7\build\Microsoft.VisualStudio.Azure.Fabric.Application.props'
file. Please restore the 'Microsoft.VisualStudio.Azure.Fabric.MSBuild'
Nuget package.
But when I restore with nuget restore i am able to restore
C:\agent\vsts-agent-win7-x64-2.119.1\vstswrk\_tool\NuGet\4.4.1\x64\nuget.exe restore C:\agent\vsts-agent-win7-x64-2.119.1\vstswrk\58\s\My.Project.sln -Verbosity Detailed -NonInteractive -ConfigFile C:\agent\vsts-agent-win7-x64-2.119.1\vstswrk\58\Nuget\tempNuGet_3675.config
The service fabric project itself (that has all the config files and does the packaging of services) uses packages.config to gets the build tools. dotnet restore doesn't support packages.config, hence you must use nuget restore.
The Service Fabric team do have plans to move the sfproj to an SDK-style project, but at the time of writing, there are some issues in Visual Studio with SDK style projects where the SDK comes from a NuGet package that need to be resolved to avoid giving customers a poor VS experience. Once that becomes available and you migrate your sfproj to sdk style, then dotnet restore should work, but until then you need to use nuget restore in your CI pipelines.

TeamCity can't find Nuget

I have a build set up on Team City but can't seem to get NuGet to restore the packages. My build configuration has two steps: Restore Nuget, then Build the solution. I have set up NuGet on TeamCity, so when I create a NuGet build step, I can choose a NuGet version from the drop down:
But when I build, it cant find NuGet:
Failed to find NuGet executable NuGet.CommandLine.3.3.0.nupkg. Check the version is listed in NuGet server settings tab.
Why cant it find NuGet?
UPDATE

Nuget not restoring symbols

We have a local nuget server on our build machine and publish our nuget packages to that server. We create the packages with the -Symbols option to crteate a .symbols.nupkg package and that is what is copied to the packages directory on the server. (There was a problem putting both .nupkg files on the server as the restore failed to work.)
When we do a nuget restore we don't see any of the PDB files or sources in our dependent projects. How do we get nuget to restore the symbols?