-
Notifications
You must be signed in to change notification settings - Fork 696
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
Fix dotnet add package doesn't work with relative path source or when version is not specified #3783
Fix dotnet add package doesn't work with relative path source or when version is not specified #3783
Conversation
c200f9b
to
acd0e7d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This eyeballs fine to me. I would like to see tests specific to this scenario before approving, though.
@zkat |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You won't know if you are the correct thing if you don't test it.
...uGet.CommandLine.XPlat/Commands/PackageReferenceCommands/AddPackageReferenceCommandRunner.cs
Outdated
Show resolved
Hide resolved
@zkat |
test/NuGet.Core.FuncTests/NuGet.XPlat.FuncTest/XPlatTestUtils.cs
Outdated
Show resolved
Hide resolved
test/NuGet.Core.FuncTests/NuGet.XPlat.FuncTest/XPlatAddPkgTests.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple of more suggestions/questions.
src/NuGet.Core/NuGet.CommandLine.XPlat/Utility/AddPackageCommandUtility.cs
Outdated
Show resolved
Hide resolved
@@ -88,9 +88,10 @@ public static async Task<NuGetVersion> GetLatestVersionFromSourceAsync(PackageSo | |||
/// Returns the PackageSource with its credentials if available | |||
/// </summary> | |||
/// <param name="requestedSources">Sources to match</param> | |||
/// <param name="additionalSources">Additional user supplied source feeds as argument</param> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think they are supposed to be additional, but rather they are supposed to replace the existing sources.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe it's treated as addition into existing sources user already setup on project.
Here below screenshot case it already has nuget.org as source and also Mysource
which is I passed as argument on AddPackageReferenceCommandRunner.cs#L347. Maybe user can use this one as alternative sourcefeed for just once during restore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is a technical question.
--source
for restore completely overwrites the sources.
dotnet add package
should work the same.
There are docs that describe this behavior as well: https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-add-package .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nkolev92
Can you suggest name for it?
How about Overriding source
or Replacing source
, New sources
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The sources in the restore request are not used at all.
The sources in the dg spec are used
NuGet.Client/src/NuGet.Core/NuGet.Commands/RestoreCommand/RequestFactory/RestoreArgs.cs
Lines 129 to 144 in 6562ef3
internal List<SourceRepository> GetEffectiveSources(ISettings settings, IList<PackageSource> dgSpecSources) | |
{ | |
if (settings == null) | |
{ | |
throw new ArgumentNullException(nameof(settings)); | |
} | |
var values = settings.GetConfigRoots(); | |
if (dgSpecSources != null) | |
{ | |
values.AddRange(dgSpecSources.Select(e => e.Source)); | |
} | |
var cacheKey = string.Join("|", values); | |
return _sourcesCache.GetOrAdd(cacheKey, (root) => GetEffectiveSourcesCore(settings, dgSpecSources)); | |
} |
Don't think you'd need to change it there. It'd be difficult to do without consequences, so I'd just change in the package spec that you are passing for restore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nkolev92
Yes, can we talk 5-10 min today. Early is better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nkolev92
I tested example on https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-add-package:
dotnet add package Microsoft.AspNetCore.StaticFiles -s https://dotnet.myget.org/F/dotnet-core/api/v3/index.json
It doesn't change the source property on dgspec file. It's only used as temporary thing. It's not persisted, I can't say --source
completely overwrites the sources.
It's still
"sources": {
"https://api.nuget.org/v3/index.json": {}
},
Only sources listed in dotnet nuget list source
or nuget.config go in there.
So when we use --source it's temporary source lets restore package from that source and persist copy of package in cache, but source details not saved. So better to call it temp source
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks one problem with current behavior of --source
we can't do repeatable restore/build if local cache is cleared even though we successfully added package from custom relative source unless that one is added into source list.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks one problem with current behavior of --source we can't do repeatable restore
That's exactly why source is not supported in the PM UI & why you can't select a subset of sources when doing restore, it always uses them all.
I think it's ok if you overwrite the source in this case.
If the customer gets themselves in a non-repeatable position, it is what it is.
They can already do that with /p:RestoreSources when they pass something different from what's specified in their nuget.config.
It doesn't change the source property on dgspec file. It's only used as temporary thing. It's not persisted, I can't say --source completely overwrites the sources.
I'm confused what this means. It doesn't work at all, it's disregarding it, which is what you are trying to fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's ok if you overwrite the source in this case.
I think overwriting is not good idea, maybe append is better.
First of all let's run this:
dotnet restore /p:restoreSources="C:\NuGetProj\IssueRepro\5127\Mypackages3;C:\NuGetProj\IssueRepro\5127\Mysource2"
Csproj file content:
<ItemGroup>
<PackageReference Include="Domain3" Version="1.0.0" />
<PackageReference Include="Domain2" Version="1.0.0" />
</ItemGroup>
RestoreSuccessful
and source changes to below:
"sources": {
"C:\\NuGetProj\\IssueRepro\\5127\\Mypackages3": {},
"C:\\NuGetProj\\IssueRepro\\5127\\Mysource2": {}
},
Another question is do we write relative path or absolute path in case user passed relative path for source?
"sources": {
"..\Mysource2": {}
},
or
"sources": {
"C:\\NuGetProj\\IssueRepro\\5127\\Mysource2": {}
},
Overwrite
By default usually we have this source:
"sources": {
"https://api.nuget.org/v3/index.json": {}
},
dotnet add package Domain2 -s ..\Mysources2
After overwrite we going to have
"sources": {
"..\Mysources2": {},
},
dotnet add package Domain3 -s ..\Mypackages3
After yet another overwrite we going to have
"sources": {
"..\\Mypackages3": {},
},
As you can see it's not great since every action overwrites the previous source.
Append.
By default usually we have this source:
"sources": {
"https://api.nuget.org/v3/index.json": {}
},
dotnet add package Domain2 -s ..\Mysources2
After append we going to have
"sources": {
"..\Mysources2": {},
"https://api.nuget.org/v3/index.json": {}
},
dotnet add package Domain3 -s ..\Mypackages3
After append we going to have
"sources": {
"..\Mysources2": {},
"..\\Mypackages3": {},
"https://api.nuget.org/v3/index.json": {}
},
This looks better, because it looks similar to RestoreSuccessful.
Only issue is we have "https://api.nuget.org/v3/index.json": {}
which is not in RestoreSuccessful.
Please give your thought?
src/NuGet.Core/NuGet.CommandLine.XPlat/Utility/AddPackageCommandUtility.cs
Outdated
Show resolved
Hide resolved
test/NuGet.Core.FuncTests/NuGet.XPlat.FuncTest/XPlatAddPkgTests.cs
Outdated
Show resolved
Hide resolved
test/NuGet.Core.FuncTests/NuGet.XPlat.FuncTest/XPlatAddPkgTests.cs
Outdated
Show resolved
Hide resolved
test/NuGet.Core.FuncTests/NuGet.XPlat.FuncTest/XPlatAddPkgTests.cs
Outdated
Show resolved
Hide resolved
test/NuGet.Core.FuncTests/NuGet.XPlat.FuncTest/XPlatAddPkgTests.cs
Outdated
Show resolved
Hide resolved
@nkolev92 |
I imagine the source problem still stands right? |
Out of 8 scenarios described above, now 6 is working. But last 2(V2 relative paths) need bit more work. Only reason V3 works for relative path is if it can't determine file path type then it defaults to V3. |
My best guess is that the source + weird error message about One might prevent you from hitting the other, but if that's the case you should solve the problems in order. |
Main problem is when we pass "..\Mysource" it doesn't know it was local source type then it default to false. Maybe we can add step to check if Dir.Exists("..\Mysource") then make it |
Look into
We already do that in restore...if we're doing it different in other parts of the code, restore contains a tried and proven concept. |
f108c01
to
1273913
Compare
Ok. Fixed all possible paths and added 16 unit tests for covering them. |
@NuGet/nuget-client please review. |
Just wanted to make sure the comment doesn't get missed, see #3783 (comment). |
I replied, can you check? |
67675df
to
7e386f0
Compare
@nkolev92 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd separate the --source
fix from the other fixes.
...uGet.CommandLine.XPlat/Commands/PackageReferenceCommands/AddPackageReferenceCommandRunner.cs
Outdated
Show resolved
Hide resolved
...uGet.CommandLine.XPlat/Commands/PackageReferenceCommands/AddPackageReferenceCommandRunner.cs
Outdated
Show resolved
Hide resolved
src/NuGet.Core/NuGet.CommandLine.XPlat/Utility/AddPackageCommandUtility.cs
Outdated
Show resolved
Hide resolved
src/NuGet.Core/NuGet.Protocol/LocalRepositories/FindLocalPackagesResourceV3Provider.cs
Outdated
Show resolved
Hide resolved
@nkolev92 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor changes/comments.
A few suggestions to clean-up the code and make it easier to follow.
@@ -102,6 +102,22 @@ public async Task<int> ExecuteCommand(PackageReferenceArgs packageReferenceArgs, | |||
|
|||
var originalPackageSpec = matchingPackageSpecs.FirstOrDefault(); | |||
|
|||
// Convert relative path to absolute path if there is any | |||
List<string> sourcePaths = new List<string>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
naming: sources, not sourcepaths. These can be http sources, not necessarily paths.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. Renamed to sources
.
@@ -334,7 +350,7 @@ public static async Task<NuGetVersion> GetLatestVersionAsync(PackageSpec origina | |||
MachineWideSettings = new XPlatMachineWideSetting(), | |||
GlobalPackagesFolder = packageReferenceArgs.PackageDirectory, | |||
PreLoadedRequestProviders = providers, | |||
Sources = packageReferenceArgs.Sources?.ToList() | |||
Sources = sourcePaths |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tbh, you can cut this. It's not used anyways. We should probably mark it as not used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added comment here for why we're not passing value down here.
@@ -453,6 +461,372 @@ public void TestCommandInvalidArguments(string command, int badCommandIndex) | |||
} | |||
} | |||
|
|||
[Theory] | |||
[InlineData("net5.0")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Doesn't matter for now, but you don't need a theory if you only have 1 test case. Use a fact instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initially I was thinking about testing many frameworks as much possible then considering heavy taxing on testing system I just changed to one framework.
Ok. I changed to Fact
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a rule, you should only pivot on things that can affect the result of your test.
None of the changes you are making affect compat, so it's ok to not pivot on a framework.
Note that the focus should be correctness and completeness.
The testing time is a secondary consideration and imo irrelevant unless the above 2 satisified.
@@ -453,6 +461,372 @@ public void TestCommandInvalidArguments(string command, int badCommandIndex) | |||
} | |||
} | |||
|
|||
[Theory] | |||
[InlineData("net5.0")] | |||
public async Task AddPkg_WithV2_RelativePath_NoVersionSpecified_Success(string targetFrameworks) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is not in the right file. The file suggests sources tests not add package command tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
name: withV2 what? :)
Is the feed type relevant to the whole scenario?
I think local vs http feed is the scenario you are trying to solve.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved in to new DotnetAddPackageTests.cs
Also I renamed each tests to reflect they're local sourcefeed.
var packageX_V1 = new PackageIdentity(packageX, new NuGetVersion("1.0.0")); | ||
var packageX_V2 = new PackageIdentity(packageX, new NuGetVersion("2.0.0")); | ||
var packageXPath = Path.Combine(pathContext.WorkingDirectory, "Custompackages"); | ||
var sourceRelativePath = RuntimeEnvironmentHelper.IsWindows ? "..\\..\\Custompackages" : "../../Custompackages"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: You can use Path.Combine("..","..", custompackages)
That way you don't need the env check, the runtime does it for you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. Addressed it. I'm not sure what I was thinking when I add this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what I was thinking when I add this.
I think that about most of the code I've not written today :D
var packageX = "packageX"; | ||
var packageY = "packageY"; | ||
var packageY_V1 = new PackageIdentity(packageY, new NuGetVersion("1.0.0")); | ||
var packageXPath = Path.Combine(pathContext.WorkingDirectory, "Custompackages"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
naming: I think should name this, custom source. The name suggest a path to the package, but it's really a path to the source.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that sourceRelativePath
already follows that logic, so this is about being consistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. I renamed to customSourcePath
. Please check.
|
||
// Generate Package, but packageX is not in nuget feed. | ||
await SimpleTestPackageUtility.CreateFolderFeedV2Async( | ||
packageXPath, //not using solution source folder |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
packageXPath, but Y is in the source? I'm not following.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code is for unhappy path(fail case). By mistake user placed packageY
package in packageX
's custom location.
Then try to restore packageX
then it should fail.
PackageSpec packageSpec = projectA.AssetsFile.PackageSpec; | ||
string[] sources = packageSpec.RestoreMetadata.Sources.Select(s => s.Name).ToArray(); | ||
Assert.Equal(sources.Count(), 1); | ||
Assert.True(sources[0].Contains("Custompackages")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The value here should be the full path, so you can check it against the full path I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I changed to full address.
} | ||
} | ||
|
||
[Theory] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you are going to write a theory, you can probably combine the test cases.
For example, the theory data can be the version.
[InlineDate("")]
[InlineDate("1.0.0")]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed code to 'Fact'. Since dotnet integration test are slow I don't want overburden with many input cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed code to 'Fact'. Since dotnet integration test are slow I don't want overburden with many input cases.
I was suggesting you merge test cases into 1. I think having a test for scenarios with and without version makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nkolev92
Ok. I addressed PR review.
Moved dotnet integration tests into new DotnetAddPackageTests.cs
file.
Also in order to make sure I'm not breaking existing default behavior before my code changes I added new 2 tests which doesn't use custom source, instead use default solution source.
AddPkg_V2LocalSourceFeed_WithDefaultSolutiuonSource_NoVersionSpecified_Success
AddPkg_V3LocalSourceFeed_WithDefaultSolutiuonSource_NoVersionSpecified_Success
@@ -102,6 +102,22 @@ public async Task<int> ExecuteCommand(PackageReferenceArgs packageReferenceArgs, | |||
|
|||
var originalPackageSpec = matchingPackageSpecs.FirstOrDefault(); | |||
|
|||
// Convert relative path to absolute path if there is any | |||
List<string> sourcePaths = new List<string>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. Renamed to sources
.
@@ -334,7 +350,7 @@ public static async Task<NuGetVersion> GetLatestVersionAsync(PackageSpec origina | |||
MachineWideSettings = new XPlatMachineWideSetting(), | |||
GlobalPackagesFolder = packageReferenceArgs.PackageDirectory, | |||
PreLoadedRequestProviders = providers, | |||
Sources = packageReferenceArgs.Sources?.ToList() | |||
Sources = sourcePaths |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added comment here for why we're not passing value down here.
@@ -453,6 +461,372 @@ public void TestCommandInvalidArguments(string command, int badCommandIndex) | |||
} | |||
} | |||
|
|||
[Theory] | |||
[InlineData("net5.0")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initially I was thinking about testing many frameworks as much possible then considering heavy taxing on testing system I just changed to one framework.
Ok. I changed to Fact
.
var packageX_V1 = new PackageIdentity(packageX, new NuGetVersion("1.0.0")); | ||
var packageX_V2 = new PackageIdentity(packageX, new NuGetVersion("2.0.0")); | ||
var packageXPath = Path.Combine(pathContext.WorkingDirectory, "Custompackages"); | ||
var sourceRelativePath = RuntimeEnvironmentHelper.IsWindows ? "..\\..\\Custompackages" : "../../Custompackages"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. Addressed it. I'm not sure what I was thinking when I add this.
PackageSpec packageSpec = projectA.AssetsFile.PackageSpec; | ||
string[] sources = packageSpec.RestoreMetadata.Sources.Select(s => s.Name).ToArray(); | ||
Assert.Equal(sources.Count(), 1); | ||
Assert.True(sources[0].Contains("Custompackages")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I changed to full address.
var packageX = "packageX"; | ||
var packageY = "packageY"; | ||
var packageY_V1 = new PackageIdentity(packageY, new NuGetVersion("1.0.0")); | ||
var packageXPath = Path.Combine(pathContext.WorkingDirectory, "Custompackages"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. I renamed to customSourcePath
. Please check.
|
||
// Generate Package, but packageX is not in nuget feed. | ||
await SimpleTestPackageUtility.CreateFolderFeedV2Async( | ||
packageXPath, //not using solution source folder |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code is for unhappy path(fail case). By mistake user placed packageY
package in packageX
's custom location.
Then try to restore packageX
then it should fail.
} | ||
} | ||
|
||
[Theory] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed code to 'Fact'. Since dotnet integration test are slow I don't want overburden with many input cases.
@@ -453,6 +461,372 @@ public void TestCommandInvalidArguments(string command, int badCommandIndex) | |||
} | |||
} | |||
|
|||
[Theory] | |||
[InlineData("net5.0")] | |||
public async Task AddPkg_WithV2_RelativePath_NoVersionSpecified_Success(string targetFrameworks) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved in to new DotnetAddPackageTests.cs
Also I renamed each tests to reflect they're local sourcefeed.
f9e5368
to
4943245
Compare
@NuGet/nuget-client |
} | ||
|
||
[Fact] | ||
public async Task AddPkg_V2LocalSourceFeed_WithRelativePath_NoVersionSpecified_Success() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you need both a V2 and a V3 test case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought V2 and V3 sources have different directory structure. So I thought testing both of them relative path would be cover all possible scenarios.
I can remove one of them. So we keep V3 one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nkolev92
I removed V2 source tests. Please check now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought V2 and V3 sources have different directory structure. So I thought testing both of them relative path would be cover all possible scenarios.
The reason why I kept probing around this topic is the fact that I wanted to make you are focusing on the right scenarios for the test.
You needed to test 2 things:
--source
completely overwrites the source.--source
when used with a relative local source, the full path is calculated correctly.
The full path calculation is not affected by the feed type (v2 or v3 local feed), that only matters afterwards.
I think the tests are there right now.
Taking another look :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: watch the Pr title :) source and feed are the same thing.
@@ -219,14 +219,15 @@ internal static PackageReferenceArgs GetPackageReferenceArgs(string packageId, S | |||
} | |||
|
|||
internal static PackageReferenceArgs GetPackageReferenceArgs(string packageId, string packageVersion, SimpleTestProjectContext project, | |||
string frameworks = "", string packageDirectory = "", string sources = "", bool noRestore = false, bool noVersion = false, bool prerelease = false) | |||
string frameworks = "", string packageDirectory = "", string sources = "", bool noRestore = false, bool noVersion = false, bool prerelease = false, string dgFilePath = "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you still need this file change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need, I had some learning curve around Xplat env. I'll do better next time here. Reverted it.
@zkat |
When setting up NuGet sources, if NuGet is unable to parse the path, this tries to resolve relative paths to absolute, and then retries setting up the NuGet source. If the path is unable to be resolved, then this ignores the error and lets NuGet handle the resulting invalid source. This path resolution requires the filesystem to be passed in. This means that various method signatures change to allow access to the filesystem. When using NuGet.Core, then relative paths were able to be resolved. But now with NuGet.Client, relative paths are resolved by clients, not by libraries, which is why this change has to be made. NuGet/NuGet.Client#3783
When setting up NuGet sources, if NuGet is unable to parse the path, this tries to resolve relative paths to absolute, and then retries setting up the NuGet source. If the path is unable to be resolved, then this ignores the error and lets NuGet handle the resulting invalid source. This path resolution requires the filesystem to be passed in. This means that various method signatures change to allow access to the filesystem. When using NuGet.Core, then relative paths were able to be resolved. But now with NuGet.Client, relative paths are resolved by clients, not by libraries, which is why this change has to be made. NuGet/NuGet.Client#3783
When setting up NuGet sources, if NuGet is unable to parse the path, this tries to resolve relative paths to absolute, and then retries setting up the NuGet source. If the path is unable to be resolved, then this ignores the error and lets NuGet handle the resulting invalid source. This path resolution requires the filesystem to be passed in. This means that various method signatures change to allow access to the filesystem. When using NuGet.Core, then relative paths were able to be resolved. But now with NuGet.Client, relative paths are resolved by clients, not by libraries, which is why this change has to be made. NuGet/NuGet.Client#3783
When setting up NuGet sources, if NuGet is unable to parse the path, this tries to resolve relative paths to absolute, and then retries setting up the NuGet source. If the path is unable to be resolved, then this ignores the error and lets NuGet handle the resulting invalid source. This path resolution requires the filesystem to be passed in. This means that various method signatures change to allow access to the filesystem. When using NuGet.Core, then relative paths were able to be resolved. But now with NuGet.Client, relative paths are resolved by clients, not by libraries, which is why this change has to be made. NuGet/NuGet.Client#3783
When setting up NuGet sources, if NuGet is unable to parse the path, this tries to resolve relative paths to absolute, and then retries setting up the NuGet source. If the path is unable to be resolved, then this ignores the error and lets NuGet handle the resulting invalid source. This path resolution requires the filesystem to be passed in. This means that various method signatures change to allow access to the filesystem. When using NuGet.Core, then relative paths were able to be resolved. But now with NuGet.Client, relative paths are resolved by clients, not by libraries, which is why this change has to be made. NuGet/NuGet.Client#3783
Bug
Fixes: Issue#5127
Regression: No
Fix
Details: Currently if user add package with dotnet tool from cli with custom source feed(local, remote) as argument then it doesn't work unless user supply exact version. Also this behavior changes between V3 and V2 format sources.
Below is whole steps:
Create a folder named 'Domain'
Create a folder named 'App'
Inside of Domain, run these commands:
Don't forget to delete Domain package from local cache after successful operation, otherwise always success regardless of input next time.
V3 source:
Absolute path:
dotnet add package Domain3 -s C:\NuGetProj\IssueRepro\5127\Mypackages3 -v 1.0.0
worksdotnet add package Domain3 -s C:\NuGetProj\IssueRepro\5127\Mypackages3
error:There are no versions available for the package 'Domain3'.
(Fixed)Relative path:
dotnet add package Domain3 -s ..\Mypackages3 -v 1.0.0
worksdotnet add package Domain3 -s ..\Mypackages3
error:There are no versions available for the package 'Domain3'.
(Fixed)
V2 source:
Absolute path:
dotnet add package Domain2 -s C:\NuGetProj\IssueRepro\5127\Mysource2 -v 1.0.0
works.dotnet add package Domain2 -s C:\NuGetProj\IssueRepro\5127\Mysource2
error:There are no versions available for the package 'Domain2'.
(Fixed)Relative path:
dotnet add package Domain2 -s ..\Mysource2 -v 1.0.0
error:NU1101: Unable to find package Domain2. No packages exist with this id in source(s): ..\Mysource2, nuget.org
error:
Package 'Domain2' is incompatible with 'all' frameworks in project 'C:\NuGetProj\IssueRepro\5127\App2\App2.csproj'.
(Fixed)
dotnet add package Domain2 -s ..\Mysource2
error:There are no versions available for the package 'Domain2'.
(Fixed)
Please note: To make this code consistent with other
dotnet command
with user supplied custom source feeds in this fix also replaces dgSpec sources with user supplied custom source feeds.For example below replaces source feeds in dgSpec file;
dotnet restore /p:restoreSources="C:\NuGetProj\IssueRepro\5127\Mypackages3;C:\NuGetProj\IssueRepro\5127\Mysource2"
Testing/Validation
Tests Added: Yes
Reason for not adding tests:
Validation: Manual from VS and patched sdk5.