private static void EnsureVersion(string version) { var comparer = new AmmyVersionComparer(); // If Ammy version is lower than 1.2.21 show message box if (comparer.Compare("Ammy" + version, "Ammy.1.2.20") < 0 && version != ".1.0.0") { throw new DirectoryNotFoundException("Please update Ammy NuGet package. " + Environment.NewLine + Environment.NewLine + "Current extension is not compatible with packages older than 1.2.21"); } }
private static string GetAssemblyDirectory(Project project, DTE dte) { var nl = Environment.NewLine; var proj = (VSProject)project.Object; var sidekickReference = proj.References.Cast <Reference>().FirstOrDefault(r => r.Path.EndsWith("AmmySidekick.dll", StringComparison.InvariantCultureIgnoreCase)); string packagesPath = null; if (sidekickReference != null) { var match = Regex.Match(sidekickReference.Path, @"(.+packages\\Ammy)\.\w+((?:\.\d+){3})"); if (match.Success && match.Groups.Count >= 3) { var version = match.Groups[2].Value; packagesPath = match.Groups[1].Value + version + "\\build"; EnsureVersion(version); } else { match = Regex.Match(sidekickReference.Path, @"(.+packages\\Ammy)\.\w+\\(\d+\.\d+\.\d+)"); if (match.Success && match.Groups.Count >= 3) { packagesPath = match.Groups[1].Value + "\\" + match.Groups[2].Value + "\\build"; } } } if (packagesPath == null) { var solutionDirectoryName = Path.GetDirectoryName(dte.Solution.FullName); if (solutionDirectoryName == null) { throw new DirectoryNotFoundException("Ammy extension couldn't find solution directory"); } var packagesFolder = Path.Combine(solutionDirectoryName, "packages"); var comparer = new AmmyVersionComparer(); var ammyPackagePath = Directory.GetDirectories(packagesFolder) .Where(path => Regex.IsMatch(path, @"Ammy\.\d+\.\d+\.\d+")) .OrderByDescending(path => path, comparer) .FirstOrDefault(); if (ammyPackagePath != null) { packagesPath = Path.Combine(ammyPackagePath, "build"); } } if (packagesPath == null) { throw new DirectoryNotFoundException("Ammy extension couldn't find packages directory." + nl + nl + "Run `install-package Ammy` in Package Manager Console and restart Visual Studio"); } return(packagesPath); // Can't copy files from here, because they a being loaded into VS by msbuild first // Need a Task that would copy contents of `Ammy.x.x.x\build` into temp directory before compilation //try { // var tempPath = Path.GetTempPath(); // var packageDirectoryName = new DirectoryInfo(ammyPackagePath).Name; // var runtimeDirectoryPath = Path.Combine(tempPath, packageDirectoryName); // if (!Directory.Exists(runtimeDirectoryPath)) // Directory.CreateDirectory(runtimeDirectoryPath); // var files = Directory.GetFiles(ammyPackageBuildPath); // foreach (var file in files) { // try { // var dest = Path.GetFileName(file); // File.Copy(file, Path.Combine(runtimeDirectoryPath, dest)); // } catch { // } // } // return runtimeDirectoryPath; //} catch { // return ammyPackageBuildPath; //} }