3
votes

When building a project in VSTS we first download the nuget packages in a NUget restore step.

the path to nuget.config points to a file in the solution folder .nuget. in this file there is a path to the repository.

when running the build the restore step works fine and all the packages gets restored into this directory.

2017-07-12T14:11:15.7270814Z Adding package '***' to folder 'd:\a\3\s\microservices\MyPackages12'

but during the build the packages can't be found because of a wrong location.

2017-07-12T14:11:27.7978408Z           Considered "..\..\MyPackages\

this only seems to fail for packages from a package feed from vsts.

where or how can i change the locations for the packages in the buildstep?

thanks..

Edit

Nuget.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <config>
    <add key="repositoryPath" value="..\MyPackages" />
  </config>
  <packageSources>
    <add key="nuget.org" value="https://www.nuget.org/api/v2/"  />
    <add key="MyWebAPI" value="https://MyWebAPI.pkgs.visualstudio.com/_packaging/MyWebAPI/nuget/v3/index.json" protocolVersion="3" />
  </packageSources>
</configuration>

Edit 2 I've got it working but not as i like it.

first current solution. version 2 of the nuget installer

buildscreen

current nuget.config.

<?xml version="1.0" encoding="utf-8"?>
 <configuration>
  <config>
<add key="repositoryPath" value="..\s\WebSiteCiCd\Packages" />
  </config>
  <packageSources>
    <!-- remove any machine-wide sources with <clear/> -->
    <clear />
    <!-- add a Team Services feed -->
    <add key="MyGreatFeed" value="https://CICD.pkgs.visualstudio.com/_packaging/CICDWebAPI/nuget/v3/index.json" />
    <!-- also get packages from the NuGet Gallery -->
    <add key="nuget.org" value="https://www.nuget.org/api/v2/" />
  </packageSources>
  <activePackageSource>
    <add key="All" value="(Aggregate source)" />
  </activePackageSource>
 </configuration>

what i don't like is the

<add key="repositoryPath" value="..\s\WebSiteCiCd\Packages" />

I would like to have a centralized nuget.config without specific project names.

the problem i think is because of the build task dooesn't look at the nuget.config settings but takes the settings in de proj file..

which is in the failing builds.. in this case i used

<add key="repositoryPath" value="..\MyPackages" />

this results in a restore step

2017-07-14T06:35:40.5913207Z Restoring NuGet package Microsoft.AspNet.WebPages.3.2.3.
2017-07-14T06:35:40.5923209Z   GET https://www.nuget.org/api/v2/Packages(Id='Microsoft.AspNet.WebPages',Version='3.2.3')
2017-07-14T06:35:40.6643208Z   OK https://www.nuget.org/api/v2/Packages(Id='Microsoft.AspNet.WebApi.WebHost',Version='5.2.3') 113ms
2017-07-14T06:35:40.6683214Z   GET https://www.nuget.org/api/v2/package/Microsoft.AspNet.WebApi.WebHost/5.2.3
2017-07-14T06:35:40.6798131Z Completed installation of Microsoft.AspNet.Razor 3.2.3
2017-07-14T06:35:40.6818132Z Adding package 'Microsoft.AspNet.Razor.3.2.3' to folder 'd:\a\1\MyPackages'
2017-07-14T06:35:40.6828123Z Completed installation of Microsoft.AspNet.Mvc 5.2.3

but in the build step it uses a different location

 2017-07-14T06:35:49.5938928Z d:\a\1\s\WebSiteCiCd\WebSiteCiCd\WebSiteCiCd.csproj(297,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\Microsoft.Net.Compilers.1.3.2\build\Microsoft.Net.Compilers.props.

it uses the ..\packages\ reference path

hopes this helps..

3
What's the detail code of nuget.config? What's the path of these references?starian chen-MSFT
Can you share detail build log here or on the OneDrive? Try to refer to this article to Migrating to automatic restorestarian chen-MSFT
I've updated the question with edit 2 @starain-MSFTFrans

3 Answers

1
votes

The task uses a temp Nuget configuration file (e.g. -ConfigFile xxx_work\17\Nuget\tempNuGet_1951.config), then the repositoryPath is based on this temp file.

So for ..\s\WebSiteCiCd\Packages path, the packages will be restored to xxx_work\17\s\WebSiteCiCd\ Packages folder. (..\MyPackages=> xxx_work\17\MyPackages).

The better way is that you can remove the setting of repositoryPath (delete config section), just use the default setting for both local and build server, then the structures are the same.

0
votes

Update your references in your project files. It looks like someone referenced a package out of a non-standard location that exists on their machine.

The easiest way to troubleshoot issues like this to delete all of your local packages (or just re-sync fresh from source control) and then let the restore run locally. That will ferret out issues with references pretty quickly.

0
votes

solution thanks to @starain-MSFT:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="nuget.org" value="https://www.nuget.org/api/v2/" />
    <add key="My packages" value="https://mypackages.pkgs.visualstudio.com/_packaging/MyWebAPI/nuget/v3/index.json" />
  </packageSources>
</configuration>

in the csproj file set the hintpath for the packages: e.g

  <Reference Include="Antlr3.Runtime, Version=3.5.0.2, Culture=neutral, PublicKeyToken=eb42632606e9261f, processorArchitecture=MSIL">
      <HintPath>..\packages\Antlr.3.5.0.2\lib\Antlr3.Runtime.dll</HintPath>

still think it would be handy if the build taks could use a nuget.config file to set the options for the packages