diff --git a/Contentless/NuGetHelper.cs b/Contentless/NuGetHelper.cs new file mode 100644 index 0000000..f31a940 --- /dev/null +++ b/Contentless/NuGetHelper.cs @@ -0,0 +1,15 @@ +using NuGet.Configuration; + +namespace Contentless; + +public class NuGetHelper +{ + private readonly ISettings _settings; + + public NuGetHelper(string projectFolder) + { + _settings = Settings.LoadDefaultSettings(projectFolder); + } + + public string PackageFolder => SettingsUtility.GetGlobalPackagesFolder(_settings); +} \ No newline at end of file diff --git a/Contentless/Program.cs b/Contentless/Program.cs index ab5d2da..fa7946f 100644 --- a/Contentless/Program.cs +++ b/Contentless/Program.cs @@ -7,7 +7,6 @@ using System.Text.RegularExpressions; using Microsoft.Build.Construction; using Microsoft.Xna.Framework.Content.Pipeline; using Newtonsoft.Json; -using NuGet.Configuration; namespace Contentless; @@ -47,8 +46,11 @@ public static class Program { var referencesVersions = config.References.ToDictionary(x => x, x => (string)null, StringComparer.OrdinalIgnoreCase); if (config.References.Length > 0) { - if (args.Length > 1) + if (args.Length > 1) + { ExtractVersions(args[1], referencesVersions); + _nuGetHelper = new NuGetHelper(Path.GetDirectoryName(args[1])); + } else Console.Error.WriteLine("You supplied references but there is no project file, this isn't compatible. Please specify the full path of project file, if you want to sync references"); } @@ -233,10 +235,11 @@ public static class Program { Console.Error.WriteLine($"Unable to find library {library.Key} in .csproj"); } + private static NuGetHelper _nuGetHelper; + private static string CalculateFullPathToLibrary(string libraryName, string referencesVersion) { - var settings = Settings.LoadDefaultSettings(null); - return Path.Combine(SettingsUtility.GetGlobalPackagesFolder(settings), libraryName.ToLower(), referencesVersion, "tools", libraryName + ".dll"); + return Path.Combine(_nuGetHelper.PackageFolder, libraryName.ToLower(), referencesVersion, "tools", libraryName + ".dll"); } private static (List, List) GetContentData() { diff --git a/Test/NuGet.Config b/Test/NuGet.Config new file mode 100644 index 0000000..767af86 --- /dev/null +++ b/Test/NuGet.Config @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file