TFS build .net Core with nuget restore end in error - nuget

While trying to build on tfs a .net Code 2.2 solution have a nuget restore task. it's trying to connect to our internal feeds. Then it fail. In the build logs we have :
error : Unable to load the service index for source http://internalSource/index.json. [D:\dummy.csproj]
error : No credentials are available in the security package [D:\dummy.csproj]
Looking at TFS generated files, it's not using the credential we declare in our solution.
Our nuget.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageRestore>
<!-- Allow NuGet to download missing packages -->
<add key="enabled" value="True" />
<add key="automatic" value="True" />
</packageRestore>
<packageSources>
<clear />
<add key="PackageSTN" value="http://internal/index.json" />
</packageSources>
<activePackageSource>
<add key="All" value="(Aggregate source)" />
</activePackageSource>
<packageSourceCredentials>
<PackageSTN>
<add key="Username" value="user" />
<add key="Password" value="pwd" />
</PackageSTN>
</packageSourceCredentials>
</configuration>
The one on TFS the build give us:
<configuration>
<packageRestore>
<add key="enabled" value="True"/>
<add key="automatic" value="True"/>
</packageRestore>
<packageSources>
<clear/>
<add key="PackageSTN" value="http://internal/index.json"/></packageSources>
<activePackageSource>
<add key="All" value="(Aggregate source)"/>
</activePackageSource>
<packageSourceCredentials>
<PackageSTN>
<add key="Username" value="VssSessionToken"/>
<add key="ClearTextPassword" value="Too Big to be display"/>
</PackageSTN>
</packageSourceCredentials>
</configuration>
Seem like it's trying to use some VssSessionToken TFS account to log on.
In addition we replace the %APPDATA% nuget.config on the server with the one with our credential, in case it will have a look inside, no luck as well.

TFS build .net Core with nuget restore end in error
As we know, when we select the option Feeds in my NuGet.config, we also need provide the Credentials for feeds outside this account/collection:
If we use the token we got from CredentialProvider.VSS.exe in the field "Personal Access Token" in the NuGet connection window, we may got the issue like you. The token we got from CredentialProvider.VSS.exe is a short-lived token, you could replace it with PAT (Personal Access Token) to check if it work for you.
Check this thread for some more details.
Besides, if you are using the old nuget.exe, you can use the task NuGet Tool Installer to update it.
If above not help you, please share your build definition about nuget restore task and the steps how to add the Credentials for feeds outside this account/collection.
Hope this helps.

Finally we did a powershell script, to by-pass this :/
try
{
$solutionSln = $env:BUILD_SOURCESDIRECTORY + $env:solutionSln
$nugetConfig = $env:BUILD_SOURCESDIRECTORY + $env:nugetConfig
Write-Host "dotnet restore $solutionSln --configfile $nugetConfig --verbosity Detailed --no-cache"
dotnet restore $solutionSln --configfile $nugetConfig --verbosity Detailed --no-cache
}
catch {
Write-Host $_
exit 1
}

Related

nuget.exe ignores inheritance for packageSourceCredentials

Is it possible to configure Nuget so the package sources are configured in the nuget.config file in the solution dir, while the credentials for those sources are configured in the nuget.config file located at the user level (%appdata%\NuGet\NuGet.Config)?
Reading how settings are applied for nuget operations, seems like nuget.config has some sort of inheritance. I was trying to use this inheritance to configure nuget for my team in the following way.
Each developer will have a personal set of credentials to the Nuget repository.
Each visual studio solution will contain a Nuget.config file in the solution directory.
2.1. The Nuget.config file will contain two package sources: nuget.org, and a private credential required source.
Each developer will configure the credentials to the private Nuget source within the file located in the user profile (%appdata%\NuGet\NuGet.Config). In this way, those credentials are not committed to source control.
here are some examples of the nuget.config files I am trying to use:
Solution level file
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/api/v3/index.json" />
<add key="Private" value="url_for_the_private_feed" />
</packageSources>
<activePackageSource>
<add key="All" value="(Aggregate source)" />
</activePackageSource>
</configuration>
User level file
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>
<packageSourceCredentials>
<Private>
<add key="Username" value="user_name_here" />
<add key="Password" value="encrypted_password_here" />
</Private>
</packageSourceCredentials>
</configuration>
For some reason, I am not able to get this to work.
I finally figured out that if the NuGet command includes the argument -configFile <path to nuget.config> then the behavior described in how settings are applied does not apply, and instead, the NuGet CLI will only consider the configuration file passed as a parameter.
This is not clear in the documentation. For some reason, I thought that I could pass a nuget.config file to the NuGet CLI, and it would use that file in conjunction with the user-level configuration and the computer-level configuration.

Mixing packages from nuget.org and repository folder in VSTS

My solution grabs some nuget packages from Nuget.org and some of them are in my repository under the "lib" folder. I am aware that having packages in my repository is not the best option, but for now, i am stuck with it.
In my solution nuget.config looks like this :
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
<add key="CustomSource" value="../lib" />
</packageSources>
<activePackageSource>
<add key="All" value="(Aggregate source)" />
</activePackageSource>
<solution>
<add key="disableSourceControlIntegration" value="true" />
</solution>
</configuration>
It works fine in Visual Studio.
In VSTS I changed the nuget restore task option :
My build fails like this:
The nuget command failed with exit code(1) and error(Failed to
retrieve information about
'Microsoft.Extensions.Configuration.Abstractions' from remote source
'D:\a\1\lib'.)
Packages failed to restore
Obviously, Microsoft.Extensions.Configuration.Abstractions, is supposed to download from nuget.org. What should I change so it tries to use the 2 nuget sources?
Thanks!
If you specify your own NuGet.config file in NuGet restore task, it will save the content of the specify NuGet.config file to a temporary config file like: D:\a\1\Nuget\tempNuGet_3274.config.
So If you are using Hosted agent, you should specify the local feed path as:
<add key="CustomSource" value="../s/Projectname/lib" />
Besides, you can also use private agent which locate in your local machine, so that the packages can be found from other directory.

AzureDevOps doesn't restore packages from AzureDevOps feed

Using AzureDevOps I should be able to restore packages from the feeds hosted within AzureDevOps.
The Nuget.config seems correct, the build has access to the feed, locally it runs fine with explicitly using the same config file.
I've seen VSTS Build vNext NuGet custom package source but would very much like to stay out of adding apikey's there. The official documentation states it should be possible: https://www.visualstudio.com/docs/package/get-started/build/team-build
NuGet.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageRestore>
<add key="enabled" value="True" />
<add key="automatic" value="True" />
</packageRestore>
<packageSources>
<clear />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
<add key="Net2Library" value="https://xxx.pkgs.visualstudio.com/DefaultCollection/_packaging/yyy/nuget/v3/index.json" />
</packageSources>
<activePackageSource>
<add key="All" value="(Aggregate source)" />
</activePackageSource>
</configuration>
Feed settings
Restore settings (it uses the correct config, visible from listing the feed in the logs)
Relevant logs:
2016-07-30T12:33:37.8085538Z Restoring NuGet package XYZ.2016.7.29.14.
2016-07-30T12:33:42.6885539Z Unable to find version '2016.7.29.14' of package 'XYZ'.
2016-07-30T12:33:42.6915543Z Feeds used:
2016-07-30T12:33:42.6925542Z C:\Users\buildguest\AppData\Local\NuGet\Cache
2016-07-30T12:33:42.6925542Z C:\Users\buildguest\.nuget\packages\
2016-07-30T12:33:42.6925542Z https://api.nuget.org/v3/index.json
2016-07-30T12:33:42.6935552Z https://xxx.pkgs.visualstudio.com/DefaultCollection/_packaging/yyy/nuget/v3/index.json
2016-07-30T12:33:42.7235541Z ##[debug]rc:1
2016-07-30T12:33:42.7245545Z ##[debug]success:false
2016-07-30T12:33:42.7325527Z ##[error]Error: C:\LR\MMS\Services\Mms\TaskAgentProvisioner\Tools\agents\1.103.1\agent\Worker\Tools\nuget.exe failed with return code: 1
2016-07-30T12:33:42.7335525Z ##[error]Packages failed to install
2016-07-30T12:33:42.7335525Z ##[debug]task result: Failed
2016-07-30T12:33:42.7345538Z ##[error]Return code: 1
This is caused by VSTS issue which has been fixed by now, please try the build again.
Issue: Failures while restoring nuget packages in Visual Studio Team Services – 8/1 – Resolved
Other possible issue: Packaging issues with Visual Studio Team Services – 7/30 – Resolved
.
I'm having the exact same issue. I've been experiencing the error most of the times when the build starts from a push from the local repo (either from VS 2015 or git bash). The workaround for me has been to queue a build directly on VSTS build definition, through "Queue Build.It's annoying but it's the only way I found to overcome the issue. I do think this is a bug and hope MS fix it. Hope my workaround helps.

Using NUnit and Nuget with Bamboo Cloud

I'm trying to create a plan on Bamboo Cloud (not Bamboo Server) for a .Net project:
Check out from Bitbucket
Nuget to get all package
MSBuild to compile the solution
NUnit to run the unit tests
1) and 3) is easy, but I can't figure out how to create tasks that run Nuget and NUnit. It seems you first have to install the executables on the build agent. I found documentation on how to do this for Linux, but not for Windows.
How do I create Nuget and NUnit tasks with Bamboo Cloud?
I did this by splitting up my Job into 4 tasks:
Source Code Checkout
As you would expect. It's the default task within a job anyway.
Download NuGet.exe
A one-liner Powershell inline script with
Invoke-WebRequest -Uri 'http://nuget.org/nuget.exe' -OutFile '.\nuget.exe'
Download all package dependencies via NuGet
This approach now seems to be the "new" recommended approach, so it's a simple CMD file that executes
nuget.exe restore
MSBuild
Using the .SLN file as parameter for the Project File option in the task and passing any needed other msbuild options in the Options field
My Bamboo server is on Linux and my remote agent is on the Windows build machine.
In your case you would follow up with the 5. task, e.g. the Nunit tests - though you may decided to put that into a separate stage, and split the tests into jobs that can run in parallel.
Edit: almost forgot: I also have a Nuget.config file
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageRestore>
<!-- Allow NuGet to download missing packages -->
<add key="enabled" value="True" />
<!-- Automatically check for missing packages during build in Visual Studio -->
<add key="automatic" value="True" />
</packageRestore>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
<add key="nuget.org" value="https://www.nuget.org/api/v2/" />
<add key="Syncfusion" value="http://nuget.syncfusion.com/xamarin/" />
</packageSources>
<!-- Used to specify which one of the sources are active -->
<activePackageSource>
<!-- this tells only one given source is active -->
<add key="NuGet official package source" value="https://nuget.org/api/v2/" />
<!-- this tells that all of them are active -->
<add key="All" value="(Aggregate source)" />
</activePackageSource>
</configuration>

How to deploy different App.config values (with WiX)

I've been looking for a best practice recommendation on how to deploy an application with a WiX installer for different values in its App.config file. For example.
On my local development machine, I use App.config settings for our test environment:
<configuration>
<appSettings>
<WorkingDirectory>C:\Working</WorkingDirectory>
</appSettings>
<connectionStrings>
<add name="ApplicationEntities"
connectionString="[TestingConnectionString]"
providerName="System.Data.EntityClient" />
</connectionStrings>
</configuration>
When I deploy to a test environment, those settings are acceptable. However, when we deploy to a production environment, I'd like them to be different. For example:
<configuration>
<appSettings>
<WorkingDirectory>\\prodserver\Working</WorkingDirectory>
</appSettings>
<connectionStrings>
<add name="ApplicationEntities"
connectionString="[ProductionConnectionString]"
providerName="System.Data.EntityClient" />
</connectionStrings>
</configuration>
The answer to my question may very well be independent of WiX. But just in case, here is my WiX Product.wxs file's relavent fragment:
<Fragment>
<ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
<Component Id="ProductComponent" Guid="{MY-GUID}">
<File Id="Application.exe"
Name="Application.exe"
Source="..\Application.exe"
Vital="yes"
KeyPath="yes"
DiskId="1" />
<File Id="Application.exe.config"
Name="Application.exe.config"
Source="..\Application.exe.config"
Vital="yes"
KeyPath="no"
DiskId="1" />
</Component>
</ComponentGroup>
</Fragment>
This setup ends with a manual edit of the App.config on the production server, which invites manual error. What would be a better way to handle this to accommodate an automated deployment?
I can think of two options, either deploy the app.config file and edit it using the XmlFile Element, or maintain multiple app.config files each representing your target environment, then deploy the appropriate file.
Here's an exmaple of both options, notice that I copy the file rather than just placing it on the file system. This serves two purposes, firstly you can see by the filename which one has been deployed, secondly if development.app.config and production.app.config are placed in the same location you will get an ICE30 validation error, by copying the file afterwards it avoids this error.
Notice also that I have a condition associated with the component, you'll need to decide how you identify which environment you are deploying to. Some ideas could be to use the machine name, the OU or simply pass it in on the command line as a property.
<Component Id="development.app.config" Guid="*">
<Condition>DEVELOPMENT</Condition>
<File Name="development.app.config" KeyPath="yes">
<CopyFile Id="development.app.config" DestinationName="app.config" />
</File>
<util:XmlFile
Id="WorkingDirectory"
Action="setValue"
File="app.config"
ElementPath="/configuration/appSettings"
Name="WorkingDirectory"
Value="C:\Working"
Permanent="no" />
</Component>
<Component Id="production.app.config" Guid="*">
<Condition>PRODUCTION</Condition>
<File Name="production.app.config" KeyPath="yes">
<CopyFile Id="production.app.config" DestinationName="app.config" />
</File>
<util:XmlFile
Id="WorkingDirectory"
Action="setValue"
File="app.config"
ElementPath="/configuration/appSettings"
Name="WorkingDirectory"
Value="\\prodserver\Working"
Permanent="no" />
</Component>