-
Notifications
You must be signed in to change notification settings - Fork 176
Improved support for local NuGet.Config files. #466
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3a8404e
Use ProjectFileInfo to return config path and project file path
seesharper 1be69e3
Added relative test and removed dead code
seesharper 23a6075
Added test for NuGet.Config in parent folder
seesharper 80c059c
Moved ProjectFileInfo out in a separate file
seesharper 22a9555
Log the location of selected NuGet config file
seesharper File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what app
8000
ears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 3 additions & 53 deletions
56
src/Dotnet.Script.DependencyModel/ProjectSystem/NuGetUtilities.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,14 @@ | ||
using NuGet.Configuration; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace Dotnet.Script.DependencyModel.ProjectSystem | ||
{ | ||
internal static class NuGetUtilities | ||
{ | ||
public static void CreateNuGetConfigFromLocation(string pathToEvaluate, string targetDirectory) | ||
public static string GetNearestConfigPath(string pathToEvaluate) | ||
{ | ||
var sourceSettings = Settings.LoadDefaultSettings(pathToEvaluate); | ||
var targetSettings = new Settings(targetDirectory); | ||
|
||
CopySection(sourceSettings, targetSettings, "config"); | ||
CopySection(sourceSettings, targetSettings, "bindingRedirects"); | ||
CopySection(sourceSettings, targetSettings, "packageRestore"); | ||
CopySection(sourceSettings, targetSettings, "solution"); | ||
CopySection(sourceSettings, targetSettings, "packageSources"); | ||
CopySection(sourceSettings, targetSettings, "packageSourceCredentials"); | ||
CopySection(sourceSettings, targetSettings, "apikeys"); | ||
CopySection(sourceSettings, targetSettings, "disabledPackageSources"); | ||
CopySection(sourceSettings, targetSettings, "activePackageSource"); | ||
|
||
targetSettings.SaveToDisk(); | ||
} | ||
|
||
private static void CopySection(ISettings sourceSettings, ISettings targetSettings, string sectionName) | ||
{ | ||
var existingAddItems = sourceSettings.GetSection(sectionName)?.Items.Where(item => item is object && (item is SourceItem || item is AddItem) && item.ElementName.ToLowerInvariant() == "add").Cast<AddItem>(); | ||
|
||
if (existingAddItems == null) | ||
{ | ||
return; | ||
} | ||
|
||
foreach (var addItem in existingAddItems) | ||
{ | ||
if (ShouldResolvePath(sectionName, addItem.Key)) | ||
{ | ||
targetSettings.AddOrUpdate(sectionName, new AddItem(addItem.Key, addItem.GetValueAsPath())); | ||
} | ||
else | ||
{ | ||
targetSettings.AddOrUpdate(sectionName, addItem); | ||
} | ||
} | ||
} | ||
|
||
private static bool ShouldResolvePath(string sectionName, string key) | ||
{ | ||
if (sectionName == "packageSources") | ||
{ | ||
return true; | ||
} | ||
|
||
if (sectionName == "config") | ||
{ | ||
return key == "globalPackagesFolder" || key == "repositoryPath"; | ||
} | ||
|
||
return false; | ||
var settings = Settings.LoadDefaultSettings(pathToEvaluate); | ||
return settings.GetConfigFilePaths().FirstOrDefault(); | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/Dotnet.Script.DependencyModel/ProjectSystem/ProjectFileInfo.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
namespace Dotnet.Script.DependencyModel.ProjectSystem | ||
{ | ||
/// <summary> | ||
/// Contains information about the generated project file and | ||
/// where to find the "nearest" NuGet.Config file. | ||
/// </summary> | ||
public class ProjectFileInfo | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="ProjectFileInfo"/> class. | ||
/// </summary> | ||
/// <param name="path">The path to the generated project file to be used during restore.</param> | ||
/// <param name="nugetConfigFile">The path to the nearest NuGet.Config file seen from the target script folder.</param> | ||
public ProjectFileInfo(string path, string nugetConfigFile) | ||
{ | ||
Path = path; | ||
NuGetConfigFile = nugetConfigFile; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the path of the generated project file to be used during restore. | ||
/// </summary> | ||
public string Path { get; } | ||
|
||
/// <summary> | ||
/// Gets the path to the nearest NuGet.Config file seen from the target script folder. | ||
/// </summary> | ||
public string NuGetConfigFile { get; } | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be ap
2E91
plied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.