Skip to content
This repository was archived by the owner on Apr 20, 2023. It is now read-only.

Commit b959791

Browse files
author
Peter Huene
committed
Fix --source-feed option for tool install and update commands.
Commit 9cc2b7c regressed the `--source-feed` option so that it no longer accepted relative paths. Because the option is now saved to the temp project file, any relative paths specified by the `--source-feed` option were made relative to the temp project path and not from the current working directory of where dotnet was run. The fix is to use `Path.GetFullPath` of the `--source-feed` option, provided the option specified was not an absolute URI. Fixes #9132.
1 parent 6ae1926 commit b959791

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

src/dotnet/ToolPackage/ToolPackageInstaller.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,17 @@ private string JoinSourceAndOfflineCache(string[] additionalFeeds)
161161
var feeds = new List<string>();
162162
if (additionalFeeds != null)
163163
{
164-
feeds.AddRange(additionalFeeds);
164+
foreach (var feed in additionalFeeds)
165+
{
166+
if (Uri.IsWellFormedUriString(feed, UriKind.Absolute))
167+
{
168+
feeds.Add(feed);
169+
}
170+
else
171+
{
172+
feeds.Add(Path.GetFullPath(feed));
173+
}
174+
}
165175
}
166176

167177
// use fallbackfolder as feed to enable offline

test/Microsoft.DotNet.ToolPackage.Tests/ToolPackageInstallerTests.cs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,50 @@ public void GivenASourceInstallSucceeds(bool testMockBehaviorIsInSync)
259259
package.Uninstall();
260260
}
261261

262+
[Theory]
263+
[InlineData(false)]
264+
[InlineData(true)]
265+
public void GivenARelativeSourcePathInstallSucceeds(bool testMockBehaviorIsInSync)
266+
{
267+
var source = GetTestLocalFeedPath();
268+
269+
var (store, installer, reporter, fileSystem) = Setup(
270+
useMock: testMockBehaviorIsInSync,
271+
feeds: GetMockFeedsForSource(source));
272+
273+
var package = installer.InstallPackage(
274+
packageId: TestPackageId,
275+
versionRange: VersionRange.Parse(TestPackageVersion),
276+
targetFramework: _testTargetframework,
277+
additionalFeeds: new[] { Path.GetRelativePath(Directory.GetCurrentDirectory(), source) });
278+
279+
AssertPackageInstall(reporter, fileSystem, package, store);
280+
281+
package.Uninstall();
282+
}
283+
284+
[Theory]
285+
[InlineData(false)]
286+
[InlineData(true)]
287+
public void GivenAUriSourceInstallSucceeds(bool testMockBehaviorIsInSync)
288+
{
289+
var source = GetTestLocalFeedPath();
290+
291+
var (store, installer, reporter, fileSystem) = Setup(
292+
useMock: testMockBehaviorIsInSync,
293+
feeds: GetMockFeedsForSource(source));
294+
295+
var package = installer.InstallPackage(
296+
packageId: TestPackageId,
297+
versionRange: VersionRange.Parse(TestPackageVersion),
298+
targetFramework: _testTargetframework,
299+
additionalFeeds: new[] { new Uri(source).AbsoluteUri });
300+
301+
AssertPackageInstall(reporter, fileSystem, package, store);
302+
303+
package.Uninstall();
304+
}
305+
262306
[Theory]
263307
[InlineData(false)]
264308
[InlineData(true)]

0 commit comments

Comments
 (0)