diff --git a/Assets/NuGet.config b/Assets/NuGet.config
index 21d1187f..2175e841 100644
--- a/Assets/NuGet.config
+++ b/Assets/NuGet.config
@@ -12,24 +12,4 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/Assets/NuGet.meta b/Assets/NuGet.meta
deleted file mode 100644
index ebd53bf0..00000000
--- a/Assets/NuGet.meta
+++ /dev/null
@@ -1,9 +0,0 @@
-fileFormatVersion: 2
-guid: 368b791ccf0f7b24cb719569f591b87e
-folderAsset: yes
-timeCreated: 1446687423
-licenseType: Pro
-DefaultImporter:
- userData:
- assetBundleName:
- assetBundleVariant:
diff --git a/Assets/NuGet/Editor/NugetConfigFile.cs b/Assets/NuGet/Editor/NugetConfigFile.cs
index 05e253cc..32dd26fe 100644
--- a/Assets/NuGet/Editor/NugetConfigFile.cs
+++ b/Assets/NuGet/Editor/NugetConfigFile.cs
@@ -52,11 +52,6 @@ public class NugetConfigFile
///
public bool ReadOnlyPackageFiles { get; set; }
- ///
- /// Gets or sets the mapping from NuGet runtimes folder naming convention to Unity BuildTargets
- ///
- public Dictionary> NativeRuntimesMappings { get; set; }
-
///
/// The incomplete path that is saved. The path is expanded and made public via the property above.
///
@@ -157,28 +152,12 @@ public void Save(string filepath)
config.Add(addElement);
}
- XElement nativeRuntimesMapping = new XElement("nativeRuntimesMapping");
- foreach (var mapping in NativeRuntimesMappings)
- {
- var platform = new XElement("platform");
- platform.Add(new XAttribute("name", mapping.Key));
-
- foreach (var target in mapping.Value)
- {
- var buildTarget = new XElement("buildTarget");
- buildTarget.Add(new XAttribute("name", target.ToString()));
- platform.Add(buildTarget);
- }
- nativeRuntimesMapping.Add(platform);
- }
-
XElement configuration = new XElement("configuration");
configuration.Add(packageSources);
configuration.Add(disabledPackageSources);
configuration.Add(packageSourceCredentials);
configuration.Add(activePackageSource);
configuration.Add(config);
- configuration.Add(nativeRuntimesMapping);
configFile.Add(configuration);
@@ -211,17 +190,7 @@ public static NugetConfigFile Load(string filePath)
configFile.PackageSources = new List();
configFile.InstallFromCache = true;
configFile.ReadOnlyPackageFiles = false;
- configFile.NativeRuntimesMappings =
- new Dictionary>()
- {
- {"win7-x64", new List {BuildTarget.StandaloneWindows64}},
- {"win7-x86", new List {BuildTarget.StandaloneWindows}},
- {"win-x64", new List {BuildTarget.StandaloneWindows64}},
- {"win-x86", new List {BuildTarget.StandaloneWindows}},
- {"linux-x64", new List {BuildTarget.StandaloneLinux64}},
- {"osx-x64", new List {BuildTarget.StandaloneOSX}},
- };
-
+
XDocument file = XDocument.Load(filePath);
// Force disable
@@ -337,36 +306,7 @@ public static NugetConfigFile Load(string filePath)
}
}
- // Read native runtime mappings
- XElement nativeRuntimesMapping = file.Root.Element("nativeRuntimesMapping");
- if (nativeRuntimesMapping != null)
- {
- configFile.NativeRuntimesMappings = new Dictionary>();
- var platforms = nativeRuntimesMapping.Elements("platform");
- foreach (var platform in platforms)
- {
- var platformName = platform.Attribute("name").Value;
- var buildTargets = new List();
- var targets = platform.Elements("buildTarget");
-
- foreach (var target in targets)
- {
- var targetName = target.Attribute("name").Value;
- BuildTarget parsedTarget;
- if (BuildTarget.TryParse(targetName, true, out parsedTarget))
- {
- buildTargets.Add(parsedTarget);
- }
- else
- {
- Debug.LogWarning(string.Format("{0} of {1} not found", targetName, platformName));
- }
- }
- configFile.NativeRuntimesMappings.Add(platformName, buildTargets);
- }
- }
-
- return configFile;
+ return configFile;
}
///
diff --git a/Assets/NuGet/Editor/NugetHelper.cs b/Assets/NuGet/Editor/NugetHelper.cs
index 21bd689d..97ab3feb 100644
--- a/Assets/NuGet/Editor/NugetHelper.cs
+++ b/Assets/NuGet/Editor/NugetHelper.cs
@@ -1,5 +1,6 @@
using System.Reflection;
using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
// To support play mode testing we have to use assembly defs, so to keep the methods internal we'll make
// the test assemblies able to see the internal methods
@@ -37,6 +38,11 @@ public static class NugetHelper
/// The path to the nuget.config file.
///
public static readonly string NugetConfigFilePath = Path.Combine(Application.dataPath, "./NuGet.config");
+
+ ///
+ /// The path to the settings.xml file
+ ///
+ public static readonly string SettingsFilePath = Path.Combine(Application.dataPath, "./NuGet/settings.xml");
///
/// The path to the packages.config file.
@@ -55,8 +61,15 @@ public static class NugetHelper
///
/// The loaded NuGet.config file that holds the settings for NuGet.
+ ///
///
public static NugetConfigFile NugetConfigFile { get; private set; }
+
+ ///
+ /// The loaded settings.json file that holds settings for NuGetForUnity.
+ ///
+ ///
+ public static Settings SettingsFile { get; private set; }
///
/// Backing field for the packages.config file.
@@ -141,6 +154,20 @@ static NugetHelper()
}
}
+ public static void LoadSettingFile()
+ {
+ if (File.Exists(SettingsFilePath))
+ {
+ SettingsFile = Settings.Load(SettingsFilePath);
+ }
+ else
+ {
+ Debug.LogFormat("No settings.json file found. Creating default at {0}", SettingsFilePath);
+ SettingsFile = Settings.CreateDefault(SettingsFilePath);
+ AssetDatabase.Refresh();
+ }
+ }
+
///
/// Loads the NuGet.config file.
///
@@ -866,7 +893,22 @@ private static void DeleteDirectory(string directoryPath)
directoryInfo.Attributes = FileAttributes.Normal;
// recursively delete the directory
- directoryInfo.Delete(true);
+ try
+ {
+ directoryInfo.Delete(true);
+ }
+ catch (UnauthorizedAccessException e)
+ {
+ if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && e.Message.Contains(".dll"))
+ {
+ Debug.LogError("Windows was unable to delete all the files, if you are using Native files this is because the file is in use by Unity. Please restart Unity to remove all the files");
+ }
+ else
+ {
+ throw;
+ }
+ }
+
}
///
@@ -878,7 +920,22 @@ private static void DeleteFile(string filePath)
if (File.Exists(filePath))
{
File.SetAttributes(filePath, FileAttributes.Normal);
- File.Delete(filePath);
+ try
+ {
+ File.Delete(filePath);
+ }
+ catch (UnauthorizedAccessException e)
+ {
+ if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && e.Message.Contains(".dll"))
+ {
+ Debug.LogError(
+ "Windows was unable to delete all the files, if you are using Native files this is because the file is in use by Unity. Please restart Unity to remove all the files");
+ }
+ else
+ {
+ throw;
+ }
+ }
}
}
@@ -915,7 +972,7 @@ internal static void UninstallAll()
public static void Uninstall(NugetPackageIdentifier package, bool refreshAssets = true)
{
LogVerbose("Uninstalling: {0} {1}", package.Id, package.Version);
-
+
// update the package.config file
PackagesConfigFile.RemovePackage(package);
PackagesConfigFile.Save(PackagesConfigFilePath);
@@ -1306,7 +1363,7 @@ private static void HandleRuntimes(NugetPackageIdentifier package, string runtim
foreach (var runtimeDir in runtimes)
{
var platform = new DirectoryInfo(runtimeDir).Name;
- if (!NugetConfigFile.NativeRuntimesMappings.ContainsKey(platform))
+ if (!SettingsFile.NativeRuntimesMappings.ContainsKey(platform))
{
LogVerbose("Runtime {0} of package {1} is not supported", platform, package);
Directory.Delete(runtimeDir, true);
@@ -1316,7 +1373,7 @@ private static void HandleRuntimes(NugetPackageIdentifier package, string runtim
var platformAndArch = platform.Split('-');
var arch = platformAndArch[1];
- var compatibleTargets = NugetConfigFile.NativeRuntimesMappings[platform];
+ var compatibleTargets = SettingsFile.NativeRuntimesMappings[platform];
var incompatibleTargets = NotObsoleteBuildTargets.Except(compatibleTargets).ToList();
var nativeFiles = Directory.GetFiles(Path.Combine(runtimeDir, "native"));
diff --git a/Assets/NuGet/Editor/Settings.cs b/Assets/NuGet/Editor/Settings.cs
new file mode 100644
index 00000000..ae14b4fa
--- /dev/null
+++ b/Assets/NuGet/Editor/Settings.cs
@@ -0,0 +1,119 @@
+using System.Collections.Generic;
+using System.IO;
+using System.Xml.Linq;
+using UnityEditor;
+using UnityEngine;
+
+namespace NugetForUnity
+{
+ public class Settings
+ {
+ ///
+ /// Gets or sets the mapping from NuGet runtimes folder naming convention to Unity BuildTargets
+ ///
+ public Dictionary> NativeRuntimesMappings { get; set; }
+
+ public void Save(string filepath)
+ {
+ XDocument configFile = new XDocument();
+
+ XElement nativeRuntimesMapping = new XElement("nativeRuntimesMapping");
+ foreach (var mapping in NativeRuntimesMappings)
+ {
+ var platform = new XElement("platform");
+ platform.Add(new XAttribute("name", mapping.Key));
+
+ foreach (var target in mapping.Value)
+ {
+ var buildTarget = new XElement("buildTarget");
+ buildTarget.Add(new XAttribute("name", target.ToString()));
+ platform.Add(buildTarget);
+ }
+
+ nativeRuntimesMapping.Add(platform);
+ }
+
+ XElement settings = new XElement("settings");
+ settings.Add(nativeRuntimesMapping);
+ configFile.Add(settings);
+
+ bool fileExists = File.Exists(filepath);
+ // remove the read only flag on the file, if there is one.
+ if (fileExists)
+ {
+ FileAttributes attributes = File.GetAttributes(filepath);
+ if ((attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
+ {
+ attributes &= ~FileAttributes.ReadOnly;
+ File.SetAttributes(filepath, attributes);
+ }
+ }
+
+ configFile.Save(filepath);
+ }
+
+ public static Settings Load(string filepath)
+ {
+ Settings settingsFile = DefaultSettings();
+ XDocument file = XDocument.Load(filepath);
+
+ XElement nativeRuntimesMapping = file.Root.Element("nativeRuntimesMapping");
+ if (nativeRuntimesMapping != null)
+ {
+ settingsFile.NativeRuntimesMappings = new Dictionary>();
+ var platforms = nativeRuntimesMapping.Elements("platform");
+ foreach (var platform in platforms)
+ {
+ var platformName = platform.Attribute("name").Value;
+ var buildTargets = new List();
+ var targets = platform.Elements("buildTarget");
+
+ foreach (var target in targets)
+ {
+ var targetName = target.Attribute("name").Value;
+ BuildTarget parsedTarget;
+ if (BuildTarget.TryParse(targetName, true, out parsedTarget))
+ {
+ buildTargets.Add(parsedTarget);
+ }
+ else
+ {
+ Debug.LogWarning(string.Format("{0} of {1} not found", targetName, platformName));
+ }
+ }
+
+ settingsFile.NativeRuntimesMappings.Add(platformName, buildTargets);
+ }
+ }
+
+ return settingsFile;
+ }
+
+ public static Settings CreateDefault(string filepath)
+ {
+ var settings = DefaultSettings();
+ settings.Save(filepath);
+
+ return settings;
+ }
+
+ private static Settings DefaultSettings()
+ {
+ var settings = new Settings();
+
+ var nativeRuntimes = new Dictionary>
+ {
+ { "win7-x64", new List() { BuildTarget.StandaloneWindows64 } },
+ { "win7-x86", new List() { BuildTarget.StandaloneWindows } },
+ { "win-x64", new List() { BuildTarget.StandaloneWindows64 } },
+ { "win-x86", new List() { BuildTarget.StandaloneWindows } },
+ { "linux-x64", new List() { BuildTarget.StandaloneLinux64 } },
+ { "osc-x64", new List() { BuildTarget.StandaloneOSX } }
+ };
+
+ settings.NativeRuntimesMappings = nativeRuntimes;
+
+ return settings;
+ }
+ }
+}
\ No newline at end of file
diff --git a/Assets/NuGet/Editor/Settings.cs.meta b/Assets/NuGet/Editor/Settings.cs.meta
new file mode 100644
index 00000000..ab112e01
--- /dev/null
+++ b/Assets/NuGet/Editor/Settings.cs.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 9b843fff1874478c890dcea11fbda40d
+timeCreated: 1638795981
\ No newline at end of file
diff --git a/Assets/PlayTests/NuGetPlayTests.cs b/Assets/PlayTests/NuGetPlayTests.cs
index 34b59f0e..754ced7d 100644
--- a/Assets/PlayTests/NuGetPlayTests.cs
+++ b/Assets/PlayTests/NuGetPlayTests.cs
@@ -59,6 +59,8 @@ public void Setup()
// For windows we end up importing two identical DLLs temporarily, this causes an error log that NUnit detects
// and would fail the test if we don't tell it to ignore the Failing messages
+ NugetHelper.LoadNugetConfigFile();
+ NugetHelper.LoadSettingFile();
LogAssert.ignoreFailingMessages = true;
NugetHelper.InstallIdentifier(sqlite);
Assert.IsTrue(NugetHelper.IsInstalled(sqlite), "The package was NOT installed: {0} {1}", sqlite.Id,
@@ -67,8 +69,6 @@ public void Setup()
public void Cleanup()
{
- // Need to reinitialise NugetHelper, but not sure why
- NugetHelper.LoadNugetConfigFile();
NugetHelper.Uninstall(sqlite);
Assert.IsFalse(NugetHelper.IsInstalled(sqlite), "The packages are STILL installed: {0} {1}", sqlite.Id,
sqlite.Version);
diff --git a/Assets/Tests/Editor/NuGetTests.cs b/Assets/Tests/Editor/NuGetTests.cs
index 851aece1..c1703d83 100644
--- a/Assets/Tests/Editor/NuGetTests.cs
+++ b/Assets/Tests/Editor/NuGetTests.cs
@@ -1,4 +1,5 @@
-using NUnit.Framework;
+using System.Collections.Generic;
+using NUnit.Framework;
using NugetForUnity;
using System.IO;
using UnityEditor;
@@ -15,6 +16,7 @@ public void SimpleRestoreTest()
public void LoadConfigFileTest()
{
NugetHelper.LoadNugetConfigFile();
+ NugetHelper.LoadSettingFile();
}
[Test]
@@ -190,4 +192,23 @@ public void VersionOutOfRangeTest(string versionRange, string version)
Assert.IsFalse(id.InRange(version), "{0} WAS in range of {1}!", version, versionRange);
}
+
+ [Test]
+ [TestCase("win7-x64", BuildTarget.StandaloneWindows64)]
+ [TestCase("win7-x86", BuildTarget.StandaloneWindows)]
+ [TestCase("win-x64", BuildTarget.StandaloneWindows64)]
+ [TestCase("win-x86", BuildTarget.StandaloneWindows)]
+ [TestCase("linux-x64", BuildTarget.StandaloneLinux64)]
+ [TestCase("osc-x64", BuildTarget.StandaloneOSX)]
+ public void NativeSettingsTest(string key, BuildTarget buildTarget)
+ {
+ Settings.CreateDefault(NugetHelper.SettingsFilePath);
+ // Call load settings directly to ensure we're testing the deserialised file
+ var settings = Settings.Load(NugetHelper.SettingsFilePath);
+ var nativeRuntimes = settings.NativeRuntimesMappings;
+
+ Assert.IsTrue(nativeRuntimes.ContainsKey(key), $"Native mappings is missing {key}");
+ Assert.IsTrue(nativeRuntimes[key].Contains(buildTarget),
+ $"Native mapping for {key} is missing build target {buildTarget}");
+ }
}
diff --git a/CreateDLL/CreateDLL.csproj b/CreateDLL/CreateDLL.csproj
index 311cd11a..94052bb5 100644
--- a/CreateDLL/CreateDLL.csproj
+++ b/CreateDLL/CreateDLL.csproj
@@ -87,6 +87,9 @@
NuspecFile.cs
+
+ Settings.cs
+
PackagesConfigFile.cs