cake-build / cake

:cake: Cake (C# Make) is a cross platform build automation system.
https://cakebuild.net
MIT License
3.89k stars 726 forks source link

DotNetCoreBuild is only using the default nuget package source #1836

Closed josemaia closed 6 years ago

josemaia commented 6 years ago

What You Are Seeing?

DotNetCoreBuild is only using the default nuget package source, even though my cake script explicitly adds a new source.

What is Expected?

DotNetCoreBuild should search all available package sources in the global nuget config, as there is no local one.

What version of Cake are you using?

0.21.1

Are you running on a 32 or 64 bit system?

64-bit

What environment are you running on? Windows? Linux? Mac?

Linux (Ubuntu 16.04 LTS) inside a Docker host that is also on Ubuntu 16.04

Are you running on a CI Server? If so, which one?

TeamCity

How Did You Get This To Happen? (Steps to Reproduce)

I add, on build start, the credentials to access a private nuget source to my global config. Upon invoking the build, only the default NuGet server is loaded.

There is no NuGet.Config file in the repository.

    //TeamCity NuGet Setup
    var nugetSourceSettings = new NuGetSourcesSettings
    {
        UserName = EnvironmentVariable("OMNIA_PRIVATE_NUGET_USERNAME"),
        Password = EnvironmentVariable("OMNIA_PRIVATE_NUGET_APIKEY"),
        IsSensitiveSource = true,
        Verbosity = NuGetVerbosity.Detailed
    };

    var feed = new {
        Name = "OmniaPrivateFeed",
        Source = EnvironmentVariable("OMNIA_PRIVATE_NUGET_SERVER"),
     };

    if (!NuGetHasSource(source:feed.Source,
    settings:nugetSourceSettings))
    {
        NuGetAddSource(
            feed.Name,
            feed.Source,
            nugetSourceSettings
        );
    }

//INVOKING THE BUILD:

var buildSettings = new DotNetCoreBuildSettings
{
    Configuration = configuration,
    ArgumentCustomization = args=>args.Append($"/p:Version=\"{version}\"")
};

DotNetCoreBuild("./OMNIA.sln", buildSettings);  

Output Log

This is the TeamCity execution log.

https://gist.github.com/josemaia/429c3483f9f395f50feb87ed3c67dd7d

Any builds ran after this display the new feed as having been successfully added, i.e.:

[14:00:53]  [Step 1/1] Downloading NuGet...
[14:00:57]  [Step 1/1] Feeds used:
[14:00:57]  [Step 1/1] /root/.nuget/packages/
[14:00:57]  [Step 1/1] https://api.nuget.org/v3/index.json
[14:00:57]  [Step 1/1] https://teamcity.example.com/httpAuth/app/nuget/v1/FeedService.svc/

A verbose execution log is also available here, but it is a manual execution, not via TeamCity: https://gist.github.com/josemaia/94aef12b6a3d53a7826272b5041359cc

devlead commented 6 years ago

What sources do you have specified for DotNetCoreRestore?

josemaia commented 6 years ago

I am not using DotNetCoreRestore, as this is a .NET Core 2.0.0 project. I attempted to add it, and add "--no-restore" to DotNetCoreBuild, but the problem still ocurred.

Should I do this, but without specifying source on Restore?

devlead commented 6 years ago

Also .NET CLI doesn't handle encrypted credentials so you'll need to specify to store as plain text https://cakebuild.net/api/Cake.Common.Tools.NuGet.Sources/NuGetSourcesSettings/E1D7BE8B

josemaia commented 6 years ago

Task("Restore")
    .IsDependentOn("Clean")
    .Does(() => {
        DotNetCoreRestore("./OMNIA.sln");   
});

Task("Build")
    .IsDependentOn("Restore")
    .Does(() => {
        var buildSettings = new DotNetCoreBuildSettings
        {
         Configuration = configuration,
         ArgumentCustomization = args=>args.Append($"--no-restore /p:Version=\"{version}\"")
        };

        DotNetCoreBuild("./OMNIA.sln", buildSettings);  
});

With this strategy, the build passed (it's failing elsewhere but that's my fault! :) )

With .NET Core 2.0, it shouldn't be necessary to do a manual restore first, though, right? Does this seem like Cake's or dotnet's fault? I can close the issue if you suspect dotnet.

devlead commented 6 years ago

Well Cake only shells out to the tools, if you launch Cake with diagnostic verbosity you'll see the command line used by Cake and could try the same in a console.

josemaia commented 6 years ago

Manual restore made the problem not happen anymore.