Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple -s/--source flags on "dotnet build" and "dotnet restore" not working #27202

Open
dargilco opened this issue Aug 16, 2022 · 10 comments
Open
Assignees
Labels
Area-CLI untriaged Request triage from a team member
Milestone

Comments

@dargilco
Copy link

The "dotnet restore" page: https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-restore says

  • -s|--source <SOURCE>

    Specifies the URI of the NuGet package source to use during the restore operation. This setting overrides all of the sources specified in the nuget.config files. Multiple sources can be provided by specifying this option multiple times.

I believe the same should apply to the -s|--source flag of "dotnet build" (even though its page fails to mention the "Multiple sources can be provided by specifying this option multiple times" part).

But specifying -s|--source multiple times does not seem to work if you try to list a folder and a URL, on either "dotnet build" or "dotnet restore".

My problem: We are building a C# SDK that is entering private preview, hence in order to use it you have to download the NuGet file to your local disk and install it (it is not available on any public feed). So I need to tell dotnet/nuget to use a local folder as one of its sources. On the other hand, our sample application also needs other (public) nuget packages (e.g. Azure.Core). So I need to tell dotnet/nuget to use both a local folder feed and the public nuget.org feed.

I know I can do always add a local nuget source using this separate command to add the local feed (this works fine):

dotnet nuget add source c:\packages --name local

But I don't want users to run that extra command (and then another command to delete this local source).

I want to give them one "dotnet build" command that will also specify the nuget sources, like this:

dotnet build ImageAnalysisQuickstart.csproj --source c:\users\dcohen\downloads --source https://api.nuget.org/v3/index.json

When I run the above I get the following error:

error NU1301: The local source 'd:\git\cognitive-services-vision-sdk-private-preview\https:\api.nuget.org\v3\index.json' doesn't exist.

Looks like it's treating the nuget.org URL as a folder path and adding it to the path where I'm running the command.

Does anyone know the right way to specify multiple nuget sources on the "dotnet build" command?

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-CLI untriaged Request triage from a team member labels Aug 16, 2022
@marcpopMSFT marcpopMSFT self-assigned this Aug 23, 2022
@anggape
Copy link

anggape commented Sep 4, 2022

had same exact issue only happen on windows, it works fine on linux and macos

@marcpopMSFT marcpopMSFT added this to the Discussion milestone Sep 14, 2022
@marcpopMSFT
Copy link
Member

What version of the SDK are you using? I didn't see this issue on windows on 7.0.1xx but maybe it's an older version impacted.

@dargilco
Copy link
Author

dargilco commented Sep 14, 2022

dotnet --version shows 6.0.304.

Is this known to be fixed in version 7?

@Adirsellam
Copy link

Any news regarding this?

@0xced
Copy link

0xced commented Mar 27, 2023

I'm still experiencing this with the .NET SDK 7.0.202 (on Windows only, as already mentioned by @anggape).

The workaround I'm using is to specify the sources in a custom nuget.config file and passing --configfile nuget.config instead of multiple --source arguments to the dotnet restore command.

nuget.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <config>
    <add key="globalPackagesFolder" value="packages" />
  </config>
  <packageSources>
    <clear />
    <add key="local" value="." />
    <add key="nuget" value="https://api.nuget.org/v3/index.json" />
  </packageSources>
</configuration>

Note that in this sample nuget.config file a custom global packages folder (relative to the current working directory) is specified. This is because I don't want to use the actual global packages folder during integration tests.

Full context: https://github.com/serilog/serilog-settings-configuration/blob/d7e0dbd7239df3b230a0dd330fefbe19bb6818bf/test/Serilog.Settings.Configuration.Tests/Support/TestApp.cs#L74-L85

0xced added a commit to 0xced/serilog-settings-configuration that referenced this issue Mar 27, 2023
… command line

This works around dotnet/sdk#27202
It also has the benefit of using settings _only_ from the specified config file, ignoring the global nuget.config where package source mapping could interfere with the local source.
@0xced
Copy link

0xced commented Mar 28, 2023

Another workaround, discussed in dotnet/msbuild#1622 (comment) is to pass the http source first. I.e.

dotnet restore --source https://api.nuget.org/v3/index.json --source .

instead of

dotnet restore --source . --source https://api.nuget.org/v3/index.json

@dargilco
Copy link
Author

Thank you all for your comments!

@marcpopMSFT
Copy link
Member

Coming back to old bugs. I was about to reproduce this as it specifically requires a local source first and then the https source second. From a binlog, the SDK creates a RestoreSources property that is passed through to msbuild and then passed to nuget as a semicolon delimited list. I don't see a bad path anywhere in the sdk and msbuild side of things so I think this is getting messed up in the nuget tasks. I can also reproduce by specifing -p:RestoreSources to an msbuild call as long as the local source is first.

@nkolev92 does this look like it could be a nuget bug? Passing the restore sources in the other order appears to work correctly.

_OutputSources = C:\test\bug\feed%3bhttps:\api.nuget.org\v3\index.json

GetRestoreDotnetCliToolsTask
Assembly = C:\repos\sdk\artifacts\bin\redist\Debug\dotnet\sdk\8.0.100-dev\NuGet.Build.Tasks.dll
Parameters
(in) RestoreSources 'C:\test\bug\feed;https:\api.nuget.org\v3\index.json'

RestoreGraphItems
0b56a9ab-2a7f-41e4-ba46-88c80a62fd99
Sources = C:\test\bug\feed;https:\api.nuget.org\v3\index.json

@nkolev92
Copy link
Contributor

nkolev92 commented Jul 3, 2023

Unsure honestly. dotnet/msbuild#1622 seems to be where a lot of bugs point back to.
Unless there's some sort of an encoding problem, I'm not sure what issue the NuGet targets might have.

@tomarikawa
Copy link

tomarikawa commented Jul 27, 2023

I have stuck most probably on the same root issue, just with dotnet pack.

And this broke after updating from .net 6.x SDK (exact version not known) to .net 7.0.306 SDK

And occurs with http/https-sources, not just file-paths.

This behaviour is on Windows using either a CMD or PowerShell Core 7 CLI. I can't confirm, whether this happens or not on Linux or on Mac.

Examples:

"C:\Program Files\dotnet\dotnet.exe" pack "MyProj.csproj" --configuration "Debug" "-p:RestoreSources=https://api.nuget.org/v3/index.json;http://my-private-v2-http-nuget-server.com/nuget" --nologo --force

Also the alternative parametrizing of RestoreSources (see MSBuild command-line reference (VS 2022)) behaves equally:

"C:\Program Files\dotnet\dotnet.exe" pack "MyProj.csproj" --configuration "Debug" "-restoreProperty:RestoreSources=https://api.nuget.org/v3/index.json;http://my-private-v2-http-nuget-server.com/nuget" --nologo --force

Error message on both is:

MSBuild version 17.6.8+c70978d4d for .NET
MSBUILD : error MSB1006: Property is not valid.
Switch: http://my-private-v2-http-nuget-server.com/nuget

Also changing the order of the elements in semi-colon-separated list (first http-source and then https-source) did not help. Then the command just errors for the latter source.

MSBuild version 17.6.8+c70978d4d for .NET
MSBUILD : error MSB1006: Property is not valid.
Switch: https://api.nuget.org/v3/index.json

A single http-source works.

The workaround to use nuget.config on project or user-level with omitting the RestoreSources-parameter works , but I'm not (yet) convinced, that this is necessarily the better way.

And anyway RestoreSources-parameter is a documented, active feature, so it should work. Or dropped totally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-CLI untriaged Request triage from a team member
Projects
None yet
Development

No branches or pull requests

7 participants