I'm working with a handful of Xamarin Forms projects and projects that produce multi-targeted Xamarin packages. I have spent a day wrestling with getting one of the projects to work properly in Azure DevOps and I give up.
When I work with one particular unit test project locally, it sets up this directory structure:
+ ProjectName
+ bin
+ obj
+ ...
+ packages
+ <nuget packages here>
This structure manifests itself in parts of the project file like this:
<Import Project="..\..\packages\NUnit3TestAdapter.3.15.1\build\net35\NUnit3TestAdapter.props" Condition="Exists('..\..\packages\NUnit3TestAdapter.3.15.1\build\net35\NUnit3TestAdapter.props')" />
<Import Project="..\..\packages\NUnit.3.12.0\build\NUnit.props" Condition="Exists('..\..\packages\NUnit.3.12.0\build\NUnit.props')" />
There's another part of the project file that depends on this:
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\..\packages\NUnit.3.12.0\build\NUnit.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NUnit.3.12.0\build\NUnit.props'))" />
<Error Condition="!Exists('..\..\packages\NUnit3TestAdapter.3.15.1\build\net35\NUnit3TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NUnit3TestAdapter.3.15.1\build\net35\NUnit3TestAdapter.props'))" />
</Target>
When I build this locally, everything is fine. The project builds. The tests pass. When I build this in Azure DevOps, it fails:
(EnsureNuGetPackageBuildImports target) ->
D:\a\1\s\[Redacted].Unit.Tests\[Redacted].Unit.Tests.csproj(97,5): error : This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is ..\..\packages\NUnit.3.12.0\build\NUnit.props.
So clearly Azure DevOps has a different idea of where the packages folder is created. If I edit the ..\.. to ..\, everything works. This is consistent with a lot of projects. In several of my other projects, all of the .csproj files use ..\ and they have this directory structure:
+ ProjectName
+ bin
+ obj
+ packages
+ ...
I can't find anything in either .csproj that seems to indicate either one is instructing nuget to do anything differently. But it's behaving VERY differently for each one. My only guess is I have some super-hidden local config for the "broken" one that changes the default behavior, and that file's not in source control so DevOps uses the "real" default?
What could be causing this to happen?
Some people asked for the .yml to see how we're restoring packages: I believe this is it:
- task: NuGetToolInstaller@1
displayName: "Install nuget"
inputs:
versionSpec: '4.4.1'
- task: NuGetCommand@2
displayName: 'restore $(solution)'
inputs:
restoreSolution: '$(solution)'
vstsFeed: "$(packageFeedName)"
I'm not the devops guy for the team, but I know a little about the yml. $(solution) is just a path to our solution file, and the package feed name is what it says it is. They seem pretty straightforward to me.