From e8afad8b8d3759fcd0975ae4b06a74879b7bcc2a Mon Sep 17 00:00:00 2001 From: Anass Bouassaba <anass.bouassaba@icloud.com> Date: Mon, 4 Nov 2019 01:44:29 +0100 Subject: [PATCH] added .editorconfig, code formatting --- .editorconfig | 7 + NuSave.Core/IPackageExtensions.cs | 12 +- NuSave.Core/MsBuildPackageRef.cs | 12 +- NuSave.Core/NuSave.cs | 482 ++++++++++++------------ NuSave.Core/Properties/AssemblyInfo.cs | 2 +- NuSave.Core/SimplifiedPackageInfo.cs | 14 +- NuSave.Core/packages.config | 1 + NuSave.Tests/Properties/AssemblyInfo.cs | 2 +- NuSave.Tests/UnitTests.cs | 20 +- NuSave.Tests/packages.config | 1 + NuSave/App.config | 9 +- NuSave/Program.cs | 111 +++--- NuSave/Properties/AssemblyInfo.cs | 2 +- NuSave/packages.config | 1 + 14 files changed, 347 insertions(+), 329 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..8da7682 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,7 @@ +[*] +charset=utf-8 +end_of_line=lf +trim_trailing_whitespace=false +insert_final_newline=false +indent_style=space +indent_size=2 \ No newline at end of file diff --git a/NuSave.Core/IPackageExtensions.cs b/NuSave.Core/IPackageExtensions.cs index 3cc524d..3489690 100644 --- a/NuSave.Core/IPackageExtensions.cs +++ b/NuSave.Core/IPackageExtensions.cs @@ -3,11 +3,11 @@ namespace NuSave.Core { - public static class IPackageExtensions + public static class IPackageExtensions + { + public static string GetFileName(this IPackage package) { - public static string GetFileName(this IPackage package) - { - return $"{package.Id}.{package.Version}.nupkg".ToLower(); - } + return $"{package.Id}.{package.Version}.nupkg".ToLower(); } -} + } +} \ No newline at end of file diff --git a/NuSave.Core/MsBuildPackageRef.cs b/NuSave.Core/MsBuildPackageRef.cs index 38b1ab6..a2307a4 100644 --- a/NuSave.Core/MsBuildPackageRef.cs +++ b/NuSave.Core/MsBuildPackageRef.cs @@ -1,8 +1,8 @@ namespace NuSave.Core { - public class MsBuildPackageRef - { - public string Include { get; set; } - public string Version { get; set; } - } -} + public class MsBuildPackageRef + { + public string Include { get; set; } + public string Version { get; set; } + } +} \ No newline at end of file diff --git a/NuSave.Core/NuSave.cs b/NuSave.Core/NuSave.cs index 12cd25e..fba10da 100644 --- a/NuSave.Core/NuSave.cs +++ b/NuSave.Core/NuSave.cs @@ -1,4 +1,4 @@ -using Newtonsoft.Json; +using Newtonsoft.Json; using NuGet; using System; using System.Collections.Generic; @@ -10,277 +10,283 @@ namespace NuSave.Core { - public class Downloader + public class Downloader + { + const string DefaultSource = "https://packages.nuget.org/api/v2"; + readonly string _source; + readonly string _outputDirectory; + readonly string _id; + readonly string _version; + readonly bool _allowPreRelease; + readonly bool _allowUnlisted; + readonly bool _silent; + readonly bool _json; + private readonly bool _useDefaultProxyConfig; + List<IPackage> _toDownload = new List<IPackage>(); + + public Downloader( + string source, + string outputDirectory, + string id, + string version, + bool allowPreRelease = false, + bool allowUnlisted = false, + bool silent = false, + bool json = false, + bool useDefaultProxyConfig = false) { - const string DefaultSource = "https://packages.nuget.org/api/v2"; - readonly string _source; - readonly string _outputDirectory; - readonly string _id; - readonly string _version; - readonly bool _allowPreRelease; - readonly bool _allowUnlisted; - readonly bool _silent; - readonly bool _json; - private readonly bool _useDefaultProxyConfig; - List<IPackage> _toDownload = new List<IPackage>(); - - public Downloader( - string source, - string outputDirectory, - string id, - string version, - bool allowPreRelease = false, - bool allowUnlisted = false, - bool silent = false, - bool json = false, - bool useDefaultProxyConfig = false) + _source = source; + _outputDirectory = outputDirectory; + _id = id; + _version = version; + _allowPreRelease = allowPreRelease; + _allowUnlisted = allowUnlisted; + _json = json; + _useDefaultProxyConfig = useDefaultProxyConfig; + _silent = _json ? true : silent; + } + + public void Download() + { + if (!_silent) + { + Console.ForegroundColor = ConsoleColor.Yellow; + Console.WriteLine($"Downloading"); + Console.ResetColor(); + } + + var webClient = new WebClient(); + + foreach (var package in _toDownload) + { + if (PackageExists(package.Id, package.Version.ToString())) continue; + + if (!_silent) { - _source = source; - _outputDirectory = outputDirectory; - _id = id; - _version = version; - _allowPreRelease = allowPreRelease; - _allowUnlisted = allowUnlisted; - _json = json; - _useDefaultProxyConfig = useDefaultProxyConfig; - _silent = _json ? true : silent; + Console.WriteLine($"{package.Id} {package.Version}"); } - public void Download() + var dataServicePackage = (DataServicePackage) package; + // We keep retrying forever until the user will press Ctrl-C + // This lets the user decide when to stop retrying. + // The reason for this is that building the dependencies list is expensive + // on slow internet connection, when the CLI crashes because of a WebException + // the user has to wait for the dependencies list to build rebuild again. + while (true) { - if (!_silent) + try + { + string nugetPackageOutputPath = GetNuGetPackagePath(package.Id, package.Version.ToString()); + var downloadUrl = dataServicePackage.DownloadUrl; + if (_useDefaultProxyConfig) { - Console.ForegroundColor = ConsoleColor.Yellow; - Console.WriteLine($"Downloading"); - Console.ResetColor(); + var proxy = webClient.Proxy; + if (proxy != null) + { + var proxyUri = proxy.GetProxy(downloadUrl).ToString(); + webClient.UseDefaultCredentials = true; + webClient.Proxy = new WebProxy(proxyUri, false) {Credentials = CredentialCache.DefaultCredentials}; + } } - var webClient = new WebClient(); - - foreach (var package in _toDownload) - { - if (PackageExists(package.Id, package.Version.ToString())) continue; - - if (!_silent) - { - Console.WriteLine($"{package.Id} {package.Version}"); - } - - var dataServicePackage = (DataServicePackage)package; - // We keep retrying forever until the user will press Ctrl-C - // This lets the user decide when to stop retrying. - // The reason for this is that building the dependencies list is expensive - // on slow internet connection, when the CLI crashes because of a WebException - // the user has to wait for the dependencies list to build rebuild again. - while (true) - { - try - { - string nugetPackageOutputPath = GetNuGetPackagePath(package.Id, package.Version.ToString()); - var downloadUrl = dataServicePackage.DownloadUrl; - if (_useDefaultProxyConfig) - { - var proxy = webClient.Proxy; - if (proxy != null) - { - var proxyUri = proxy.GetProxy(downloadUrl).ToString(); - webClient.UseDefaultCredentials = true; - webClient.Proxy = new WebProxy(proxyUri, false) { Credentials = CredentialCache.DefaultCredentials }; - } - } - webClient.DownloadFile(downloadUrl, nugetPackageOutputPath); - break; - } - catch (WebException e) - { - Console.ForegroundColor = ConsoleColor.Red; - Console.WriteLine($"{e.Message}. Retrying in one second..."); - Console.ResetColor(); - Thread.Sleep(1000); - } - } - } + webClient.DownloadFile(downloadUrl, nugetPackageOutputPath); + break; + } + catch (WebException e) + { + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine($"{e.Message}. Retrying in one second..."); + Console.ResetColor(); + Thread.Sleep(1000); + } } + } + } - public void ResolveDependencies(string csprojPath = null) - { - if (_toDownload != null && _toDownload.Count > 1) - { - _toDownload = new List<IPackage>(); - } + public void ResolveDependencies(string csprojPath = null) + { + if (_toDownload != null && _toDownload.Count > 1) + { + _toDownload = new List<IPackage>(); + } - if (!_silent) - { - Console.ForegroundColor = ConsoleColor.Yellow; - Console.WriteLine($"Resolving dependencies"); - Console.ResetColor(); - } + if (!_silent) + { + Console.ForegroundColor = ConsoleColor.Yellow; + Console.WriteLine($"Resolving dependencies"); + Console.ResetColor(); + } - if (csprojPath == null) - { - IPackage package = string.IsNullOrWhiteSpace(_version) ? - Repository.FindPackage(_id) : - Repository.FindPackage(_id, SemanticVersion.Parse(_version), _allowPreRelease, _allowUnlisted); + if (csprojPath == null) + { + IPackage package = string.IsNullOrWhiteSpace(_version) + ? Repository.FindPackage(_id) + : Repository.FindPackage(_id, SemanticVersion.Parse(_version), _allowPreRelease, _allowUnlisted); - if (package == null) throw new Exception("Could not resolve package"); + if (package == null) throw new Exception("Could not resolve package"); - ResolveDependencies(package); - } - else - { - XNamespace @namespace = "http://schemas.microsoft.com/developer/msbuild/2003"; - XDocument csprojDoc = XDocument.Load(csprojPath); - - IEnumerable<MsBuildPackageRef> references = csprojDoc - .Element(@namespace + "Project") - .Elements(@namespace + "ItemGroup") - .Elements(@namespace + "PackageReference") - .Select(e => new MsBuildPackageRef() - { - Include = e.Attribute("Include").Value, - Version = e.Element(@namespace + "Version").Value - }); - ResolveDependencies(references); - - IEnumerable<MsBuildPackageRef> dotnetCliToolReferences = csprojDoc - .Element(@namespace + "Project") - .Elements(@namespace + "ItemGroup") - .Elements(@namespace + "DotNetCliToolReference") - .Select(e => new MsBuildPackageRef() - { - Include = e.Attribute("Include").Value, - Version = e.Element(@namespace + "Version").Value - }); - ResolveDependencies(dotnetCliToolReferences); - } + ResolveDependencies(package); + } + else + { + XNamespace @namespace = "http://schemas.microsoft.com/developer/msbuild/2003"; + XDocument csprojDoc = XDocument.Load(csprojPath); - if (_json) - { - Console.WriteLine(JsonConvert.SerializeObject(GetDependencies())); - } - } + IEnumerable<MsBuildPackageRef> references = csprojDoc + .Element(@namespace + "Project") + .Elements(@namespace + "ItemGroup") + .Elements(@namespace + "PackageReference") + .Select(e => new MsBuildPackageRef() + { + Include = e.Attribute("Include").Value, + Version = e.Element(@namespace + "Version").Value + }); + ResolveDependencies(references); - void ResolveDependencies(IEnumerable<MsBuildPackageRef> references) - { - foreach (var packageRef in references) - { - Console.ForegroundColor = ConsoleColor.Green; - Console.WriteLine($"{packageRef.Include} {packageRef.Version}"); - Console.ResetColor(); + IEnumerable<MsBuildPackageRef> dotnetCliToolReferences = csprojDoc + .Element(@namespace + "Project") + .Elements(@namespace + "ItemGroup") + .Elements(@namespace + "DotNetCliToolReference") + .Select(e => new MsBuildPackageRef() + { + Include = e.Attribute("Include").Value, + Version = e.Element(@namespace + "Version").Value + }); + ResolveDependencies(dotnetCliToolReferences); + } - ResolveDependencies(packageRef); - } - } + if (_json) + { + Console.WriteLine(JsonConvert.SerializeObject(GetDependencies())); + } + } - string GetNuGetPackagePath(string id, string version) - { - return Path.Combine(_outputDirectory, $"{id}.{version}.nupkg".ToLower()); - } + void ResolveDependencies(IEnumerable<MsBuildPackageRef> references) + { + foreach (var packageRef in references) + { + Console.ForegroundColor = ConsoleColor.Green; + Console.WriteLine($"{packageRef.Include} {packageRef.Version}"); + Console.ResetColor(); - string GetNuGetHierarchialDirPath(string id, string version) - { - return Path.Combine(_outputDirectory, id.ToLower(), version); - } + ResolveDependencies(packageRef); + } + } - bool PackageExists(string id, string version) - { - string nugetPackagePath = GetNuGetPackagePath(id, version); - if (File.Exists(nugetPackagePath)) return true; + string GetNuGetPackagePath(string id, string version) + { + return Path.Combine(_outputDirectory, $"{id}.{version}.nupkg".ToLower()); + } - string nuGetHierarchialDirPath = GetNuGetHierarchialDirPath(id, version); - if (Directory.Exists(nuGetHierarchialDirPath)) return true; + string GetNuGetHierarchialDirPath(string id, string version) + { + return Path.Combine(_outputDirectory, id.ToLower(), version); + } - return false; - } + bool PackageExists(string id, string version) + { + string nugetPackagePath = GetNuGetPackagePath(id, version); + if (File.Exists(nugetPackagePath)) return true; - void ResolveDependencies(MsBuildPackageRef msBuildpackageRef) - { - IPackage nugetPackage = Repository.FindPackage(msBuildpackageRef.Include, SemanticVersion.Parse(msBuildpackageRef.Version), true, true); - ResolveDependencies(nugetPackage); - } + string nuGetHierarchialDirPath = GetNuGetHierarchialDirPath(id, version); + if (Directory.Exists(nuGetHierarchialDirPath)) return true; - void ResolveDependencies(IPackage package) - { - if (PackageExists(package.Id, package.Version.ToString())) return; + return false; + } - _toDownload.Add(package); + void ResolveDependencies(MsBuildPackageRef msBuildpackageRef) + { + IPackage nugetPackage = Repository.FindPackage(msBuildpackageRef.Include, + SemanticVersion.Parse(msBuildpackageRef.Version), true, true); + ResolveDependencies(nugetPackage); + } - foreach (var set in package.DependencySets) - { - foreach (var dependency in set.Dependencies) - { - if (PackageExists(dependency.Id, dependency.VersionSpec.ToString())) continue; - - var found = Repository.FindPackage( - dependency.Id, - dependency.VersionSpec, - _allowPreRelease, - _allowUnlisted); - - if (found == null) - { - Console.ForegroundColor = ConsoleColor.Red; - Console.WriteLine($"Could not resolve dependency: {dependency.Id} {dependency.VersionSpec.ToString()}"); - Console.ResetColor(); - } - else - { - if (!_toDownload.Any(p => p.Title == found.Title && p.Version == found.Version)) - { - _toDownload.Add(found); - if (!_silent) - { - Console.WriteLine($"{found.Id} {found.Version}"); - } - ResolveDependencies(found); - } - } - } - } - } + void ResolveDependencies(IPackage package) + { + if (PackageExists(package.Id, package.Version.ToString())) return; + + _toDownload.Add(package); - string GetSource() + foreach (var set in package.DependencySets) + { + foreach (var dependency in set.Dependencies) { - if (_source == null) - { - return DefaultSource; - } - else + if (PackageExists(dependency.Id, dependency.VersionSpec.ToString())) continue; + + var found = Repository.FindPackage( + dependency.Id, + dependency.VersionSpec, + _allowPreRelease, + _allowUnlisted); + + if (found == null) + { + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine($"Could not resolve dependency: {dependency.Id} {dependency.VersionSpec.ToString()}"); + Console.ResetColor(); + } + else + { + if (!_toDownload.Any(p => p.Title == found.Title && p.Version == found.Version)) { - return _source; + _toDownload.Add(found); + if (!_silent) + { + Console.WriteLine($"{found.Id} {found.Version}"); + } + + ResolveDependencies(found); } + } } + } + } - /// <summary> - /// Convenience method that can be used in powershell in combination with Out-GridView - /// </summary> - /// <returns></returns> - public List<SimplifiedPackageInfo> GetDependencies() + string GetSource() + { + if (_source == null) + { + return DefaultSource; + } + else + { + return _source; + } + } + + /// <summary> + /// Convenience method that can be used in powershell in combination with Out-GridView + /// </summary> + /// <returns></returns> + public List<SimplifiedPackageInfo> GetDependencies() + { + var list = new List<SimplifiedPackageInfo>(); + foreach (var p in _toDownload) + { + list.Add(new SimplifiedPackageInfo { - var list = new List<SimplifiedPackageInfo>(); - foreach (var p in _toDownload) - { - list.Add(new SimplifiedPackageInfo - { - Id = p.Id, - Version = p.Version.ToString(), - Authors = string.Join(" ", p.Authors) - }); - } - return list; - } + Id = p.Id, + Version = p.Version.ToString(), + Authors = string.Join(" ", p.Authors) + }); + } + + return list; + } + + IPackageRepository _repository; - IPackageRepository _repository; - IPackageRepository Repository + IPackageRepository Repository + { + get + { + if (_repository == null) { - get - { - if (_repository == null) - { - _repository = PackageRepositoryFactory.Default.CreateRepository(GetSource()); - } - return _repository; - } + _repository = PackageRepositoryFactory.Default.CreateRepository(GetSource()); } + + return _repository; + } } -} + } +} \ No newline at end of file diff --git a/NuSave.Core/Properties/AssemblyInfo.cs b/NuSave.Core/Properties/AssemblyInfo.cs index 38ae1af..5af7415 100644 --- a/NuSave.Core/Properties/AssemblyInfo.cs +++ b/NuSave.Core/Properties/AssemblyInfo.cs @@ -33,4 +33,4 @@ // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file diff --git a/NuSave.Core/SimplifiedPackageInfo.cs b/NuSave.Core/SimplifiedPackageInfo.cs index b225a50..347ef38 100644 --- a/NuSave.Core/SimplifiedPackageInfo.cs +++ b/NuSave.Core/SimplifiedPackageInfo.cs @@ -1,9 +1,9 @@ namespace NuSave.Core { - public class SimplifiedPackageInfo - { - public string Id { get; set; } - public string Version { get; set; } - public string Authors { get; set; } - } -} + public class SimplifiedPackageInfo + { + public string Id { get; set; } + public string Version { get; set; } + public string Authors { get; set; } + } +} \ No newline at end of file diff --git a/NuSave.Core/packages.config b/NuSave.Core/packages.config index 598bb5f..f5b1dce 100644 --- a/NuSave.Core/packages.config +++ b/NuSave.Core/packages.config @@ -1,4 +1,5 @@ <?xml version="1.0" encoding="utf-8"?> + <packages> <package id="Microsoft.Web.Xdt" version="2.1.1" targetFramework="net462" /> <package id="Newtonsoft.Json" version="9.0.1" targetFramework="net462" /> diff --git a/NuSave.Tests/Properties/AssemblyInfo.cs b/NuSave.Tests/Properties/AssemblyInfo.cs index a0c52eb..551dcf4 100644 --- a/NuSave.Tests/Properties/AssemblyInfo.cs +++ b/NuSave.Tests/Properties/AssemblyInfo.cs @@ -33,4 +33,4 @@ // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file diff --git a/NuSave.Tests/UnitTests.cs b/NuSave.Tests/UnitTests.cs index 7428b56..5604ead 100644 --- a/NuSave.Tests/UnitTests.cs +++ b/NuSave.Tests/UnitTests.cs @@ -4,16 +4,16 @@ namespace NuSave.Tests { - [TestClass] - public class UnitTests + [TestClass] + public class UnitTests + { + [TestMethod] + public void TestDependencyResolver() { - [TestMethod] - public void TestDependencyResolver() - { - var downloader = new Downloader(null, Environment.CurrentDirectory, "System.Collections", "4.3.0"); - downloader.ResolveDependencies(); - var deps = downloader.GetDependencies(); - Assert.AreEqual(deps.Count, 4); - } + var downloader = new Downloader(null, Environment.CurrentDirectory, "System.Collections", "4.3.0"); + downloader.ResolveDependencies(); + var deps = downloader.GetDependencies(); + Assert.AreEqual(deps.Count, 4); } + } } \ No newline at end of file diff --git a/NuSave.Tests/packages.config b/NuSave.Tests/packages.config index b04d31c..475e699 100644 --- a/NuSave.Tests/packages.config +++ b/NuSave.Tests/packages.config @@ -1,4 +1,5 @@ <?xml version="1.0" encoding="utf-8"?> + <packages> <package id="MSTest.TestAdapter" version="1.1.4-preview" targetFramework="net462" /> <package id="MSTest.TestFramework" version="1.0.5-preview" targetFramework="net462" /> diff --git a/NuSave/App.config b/NuSave/App.config index b50c74f..8609e96 100644 --- a/NuSave/App.config +++ b/NuSave/App.config @@ -1,6 +1,7 @@ -<?xml version="1.0" encoding="utf-8" ?> +<?xml version="1.0" encoding="utf-8"?> + <configuration> - <startup> - <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2" /> - </startup> + <startup> + <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2" /> + </startup> </configuration> \ No newline at end of file diff --git a/NuSave/Program.cs b/NuSave/Program.cs index 57f738d..72b33a9 100644 --- a/NuSave/Program.cs +++ b/NuSave/Program.cs @@ -1,72 +1,73 @@ -using Microsoft.Extensions.CommandLineUtils; +using Microsoft.Extensions.CommandLineUtils; using NuSave.Core; using System; namespace NuSave.CLI { - class Program + class Program + { + const string Version = "1.0.0"; + + static void Main(string[] args) { - const string Version = "1.0.0-preview.2"; + CommandLineApplication app = new CommandLineApplication(); - static void Main(string[] args) - { - CommandLineApplication app = new CommandLineApplication(); + var msbuildProject = app.Option("-msbuildProject", "MSBuild Project file", CommandOptionType.SingleValue); + var source = app.Option("-source", "Package source", CommandOptionType.SingleValue); + var packageId = app.Option("-id", "Package ID", CommandOptionType.SingleValue); + var outputDirectory = app.Option("-outputDirectory", "Output directory", CommandOptionType.SingleValue); + var packageVersion = app.Option("-version", "Package version", CommandOptionType.SingleValue); + var allowPreRelease = app.Option("-allowPreRelease", "Allow pre-release packages", CommandOptionType.NoValue); + var allowUnlisted = app.Option("-allowUnlisted", "Allow unlisted packages", CommandOptionType.NoValue); + var silent = app.Option("-silent", "Don't write anything to stdout", CommandOptionType.NoValue); + var noDownload = app.Option("-noDownload", "Don't download packages", CommandOptionType.NoValue); + var json = app.Option("-json", "Dependencies list will be printed in json format", CommandOptionType.NoValue); + var useDefaultProxyConfig = app.Option("-useDefaultProxyConfig", "Uses a default proxy configuration", + CommandOptionType.NoValue); - var msbuildProject = app.Option("-msbuildProject", "MSBuild Project file", CommandOptionType.SingleValue); - var source = app.Option("-source", "Package source", CommandOptionType.SingleValue); - var packageId = app.Option("-id", "Package ID", CommandOptionType.SingleValue); - var outputDirectory = app.Option("-outputDirectory", "Output directory", CommandOptionType.SingleValue); - var packageVersion = app.Option("-version", "Package version", CommandOptionType.SingleValue); - var allowPreRelease = app.Option("-allowPreRelease", "Allow pre-release packages", CommandOptionType.NoValue); - var allowUnlisted = app.Option("-allowUnlisted", "Allow unlisted packages", CommandOptionType.NoValue); - var silent = app.Option("-silent", "Don't write anything to stdout", CommandOptionType.NoValue); - var noDownload = app.Option("-noDownload", "Don't download packages", CommandOptionType.NoValue); - var json = app.Option("-json", "Dependencies list will be printed in json format", CommandOptionType.NoValue); - var useDefaultProxyConfig = app.Option("-useDefaultProxyConfig", "Uses a default proxy configuration", CommandOptionType.NoValue); + app.Command("version", (target) => { }) + .OnExecute(() => + { + string revision = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.Revision.ToString(); + Console.WriteLine($"{Version}+{revision}"); + return 0; + }); - app.Command("version", (target) => { }) - .OnExecute(() => - { - string revision = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.Revision.ToString(); - Console.WriteLine($"{Version}+{revision}"); - return 0; - }); + app.HelpOption("-? | --help | -help"); - app.HelpOption("-? | --help | -help"); + app.OnExecute(() => + { + string outputDirectoryStr = noDownload.HasValue() ? null : outputDirectory.Value(); - app.OnExecute(() => - { - string outputDirectoryStr = noDownload.HasValue() ? null : outputDirectory.Value(); + var downloader = new Downloader( + source: source.Value(), + outputDirectory: outputDirectoryStr, + id: packageId.Value(), + version: packageVersion.Value(), + allowPreRelease: allowPreRelease.HasValue(), + allowUnlisted: allowUnlisted.HasValue(), + silent: silent.HasValue(), + json: json.HasValue(), + useDefaultProxyConfig: useDefaultProxyConfig.HasValue()); - var downloader = new Downloader( - source: source.Value(), - outputDirectory: outputDirectoryStr, - id: packageId.Value(), - version: packageVersion.Value(), - allowPreRelease: allowPreRelease.HasValue(), - allowUnlisted: allowUnlisted.HasValue(), - silent: silent.HasValue(), - json: json.HasValue(), - useDefaultProxyConfig: useDefaultProxyConfig.HasValue()); + if (msbuildProject.HasValue()) + { + downloader.ResolveDependencies(msbuildProject.Value()); + } + else + { + downloader.ResolveDependencies(); + } - if (msbuildProject.HasValue()) - { - downloader.ResolveDependencies(msbuildProject.Value()); - } - else - { - downloader.ResolveDependencies(); - } - - if (!noDownload.HasValue()) - { - downloader.Download(); - } + if (!noDownload.HasValue()) + { + downloader.Download(); + } - return 0; - }); + return 0; + }); - app.Execute(args); - } + app.Execute(args); } + } } \ No newline at end of file diff --git a/NuSave/Properties/AssemblyInfo.cs b/NuSave/Properties/AssemblyInfo.cs index d8005ae..a2cd681 100644 --- a/NuSave/Properties/AssemblyInfo.cs +++ b/NuSave/Properties/AssemblyInfo.cs @@ -33,4 +33,4 @@ // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file diff --git a/NuSave/packages.config b/NuSave/packages.config index 8892bea..51819a1 100644 --- a/NuSave/packages.config +++ b/NuSave/packages.config @@ -1,4 +1,5 @@ <?xml version="1.0" encoding="utf-8"?> + <packages> <package id="Microsoft.Extensions.CommandLineUtils" version="1.1.0" targetFramework="net462" /> </packages> \ No newline at end of file