Skip to content

Commit

Permalink
Added Nuget package referencing to Install script (WIP)
Browse files Browse the repository at this point in the history
DOESN'T WORK YET! It is still experimental. I have several problems with only selecting and only installing the best available target framework the package can provide. It's not as trivial as it sounds originally.
  • Loading branch information
microdee committed Jun 8, 2017
1 parent 084f99b commit 61a707a
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 2 deletions.
14 changes: 14 additions & 0 deletions examples/ReferenceNugetPackages.vpack
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<vpack>
<meta>
<name>My Avvvvesome Pack</name>
<author>microdee</author>
</meta>
<nuget>
<package version="10.0.2">Newtonsoft.Json</package>
<package>EntityFramework</package>
</nuget>
<install>
using System;
Console.WriteLine("tada");
</install>
</vpack>
1 change: 1 addition & 0 deletions src/vpm/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ static void Main(string[] args)
Console.ResetColor();
Console.WriteLine(ArgUsage.GenerateUsageFromTemplate<VpmArgs>());
VpmUtils.CleanUp();
Environment.Exit(0);
}
try
{
Expand Down
5 changes: 5 additions & 0 deletions src/vpm/config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Reflection;
using System.Windows;
using System.Xml;
using NuGet;
using PowerArgs;

namespace vpm
Expand All @@ -13,6 +14,10 @@ public class VpmConfig
private static VpmConfig _instance;
public static VpmConfig Instance => _instance ?? (_instance = new VpmConfig());

private IPackageRepository _defaultNugetRepository;
public IPackageRepository DefaultNugetRepository => _defaultNugetRepository ??
(_defaultNugetRepository = PackageRepositoryFactory.Default.CreateRepository("https://packages.nuget.org/api/v2"));

private string _vvvvarch;
public string VVVVArcitecture
{
Expand Down
61 changes: 59 additions & 2 deletions src/vpm/vpack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
using System.Linq;
using System.Net;
using System.Text.RegularExpressions;
using System.Windows.Controls;
using System.Xml;
using Microsoft.CodeAnalysis.CSharp.Scripting;
using Microsoft.CodeAnalysis.Scripting;
using PowerArgs;
using NuGet;

namespace vpm
{
Expand Down Expand Up @@ -61,6 +63,7 @@ public class VPack
public string RawXml;
public bool Agreed = false;
public List<string> Aliases = new List<string>();
public XmlNodeList NugetPackages;
public List<VPack> Dependencies = new List<VPack>();

public VPack(string name, string source, IEnumerable<string> aliases = null, XmlDocument srcxml = null)
Expand Down Expand Up @@ -99,7 +102,7 @@ public VPack(string name, string source, IEnumerable<string> aliases = null, Xml
{
RawXml = xmldoc.ToString();
var licensenode = xmldoc.SelectSingleNode("/vpack/meta/license");
LicenseUrl = licensenode != null ? licensenode.InnerText.Trim() : "http://www.imxprs.com/free/microdee/vpmnolicense";
LicenseUrl = licensenode?.InnerText.Trim() ?? "http://www.imxprs.com/free/microdee/vpmnolicense";

var namenode = xmldoc.SelectSingleNode("/vpack/meta/name");
if (namenode == null)
Expand All @@ -122,6 +125,12 @@ public VPack(string name, string source, IEnumerable<string> aliases = null, Xml
throw new Exception("VPack doesn't contain installing script.");
}
InstallScript = installnode.InnerText;

var nugetnode = xmldoc.SelectSingleNode("/vpack/nuget");
if (nugetnode != null)
{
NugetPackages = nugetnode.ChildNodes;
}

var dependenciesnode = xmldoc.SelectSingleNode("/vpack/meta/dependencies");
if (dependenciesnode != null)
Expand Down Expand Up @@ -241,13 +250,61 @@ public void Install()
{
d.Install();
}

Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Installing " + Name);
Console.ResetColor();

var vpmglobal = new VpmGlobals(this);
var assemblies = VpmConfig.Instance.ReferencedAssemblies;
if (NugetPackages != null && NugetPackages.Count > 0)
{
Console.WriteLine("Initializing Nuget for this pack");
var packdir = Path.Combine(TempDir, "NugetPackages");
Directory.CreateDirectory(packdir);
var repo = VpmConfig.Instance.DefaultNugetRepository;
var packman = new PackageManager(repo, packdir);
packman.PackageInstalled += (sender, args) =>
{
Console.WriteLine("Installed " + args.Package.Id);
};
for (int i = 0; i < NugetPackages.Count; i++)
{
var packnode = NugetPackages[i];
Console.WriteLine("Installing Nuget Package " + packnode.InnerText);
var version = packnode.Attributes?["version"]?.Value;

var packages = repo.FindPackagesById(packnode.InnerText);
IPackage package = null;
foreach (var p in packages)
{
bool versioncheck = p.IsLatestVersion;
if (version != null)
versioncheck = SemanticVersion.Parse(version) == p.Version;

if (versioncheck)
{
package = p;
break;
}
}
if (package == null)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("No nuget package found with those conditions");
Console.ResetColor();
}
else
{
packman.InstallPackage(package, false, true);
}
}
}
try
{
CSharpScript.EvaluateAsync(InstallScript,
globals: vpmglobal,
options: ScriptOptions.Default.WithReferences(VpmConfig.Instance.ReferencedAssemblies));
options: ScriptOptions.Default.WithReferences(assemblies));
}
catch (CompilationErrorException e)
{
Expand Down

0 comments on commit 61a707a

Please sign in to comment.