private static void CheckEnvironment(NuGetRunner runner)
        {
            // Workaround for issue https://github.com/NuGet/Home/issues/4277
            if (runner.NuGetVersion < NuGet35Version || !IsSystemAccount())
            {
                return;
            }

            var variables = Environment.GetEnvironmentVariables();

            if (variables.Contains(NugetPackagesPath))
            {
                return;
            }

            var tempDirectory = Path.GetTempPath();

            if (string.IsNullOrEmpty(tempDirectory))
            {
                return;
            }

            var packagesPath = Path.Combine(tempDirectory, ".nuget", "packages");

            Console.Out.WriteLine("Setting '{0}' environment variable to '{1}'", NugetPackagesPath, packagesPath);
            runner.AddEnvironmentVariable(NugetPackagesPath, packagesPath);

            // Set nuget packages path for subsequent MSBuild launch
            Console.Out.WriteLine("##teamcity[setParameter name='env.{0}' value='{1}']", NugetPackagesPath, packagesPath);
        }
        public NuGetRunMutex(NuGetRunner runner)
        {
            var m = new Mutex(false, "JetBrains.TeamCity.NuGet.RunMutex");

            runner.BeforeNuGetStarted += (_, __) => m.WaitOne();
            runner.AfterNuGetFinished += (_, __) => m.ReleaseMutex();
        }
Example #3
0
        static int Main2(string[] args)
        {
            Console.Out.WriteLine("JetBrains TeamCity NuGet Runner " + typeof(Program).Assembly.GetName().Version);
            Console.Out.WriteLine("Starting NuGet with TeamCity provided plugins...");
            if (args.Length < 2)
            {
                return(Usage());
            }

            string nuget  = args[0];
            var    runner = new NuGetRunner(nuget);

            ConfigureExtensions(runner);

            Console.Out.WriteLine("Starting NuGet.exe {1} from {0}", runner.NuGetAssembly.GetAssemblyPath(), runner.NuGetVersion);

            switch (args[1])
            {
            case "---TeamCity.DumpExtensionsPath":
                Console.Out.WriteLine("ExtensionsPath: {0}", runner.LocateNuGetExtensionsPath() ?? "null");
                return(0);

            case "--TeamCity.NuGetVersion":
                Console.Out.WriteLine("TeamCity.NuGetVersion: " + runner.NuGetVersion);
                Console.Out.WriteLine();
                return(0);

            default:
                return(runner.Run(args.Skip(1).ToArray()));
            }
        }
        private static IEnumerable <string> Extensions(NuGetRunner runner)
        {
            Func <string, string> path = p => Path.Combine(typeof(Program).GetAssemblyDirectory(), "plugins-" + p, "JetBrains.TeamCity.NuGet.ExtendedCommands." + p + ".dll");

            if (runner.NuGetVersion.Major >= 3 && runner.NuGetVersion.Minor >= 2)
            {
                yield return(path("3.2"));
            }
            else if (runner.NuGetVersion.Major >= 2 && runner.NuGetVersion.Minor >= 8)
            {
                yield return(path("2.8"));
            }
            else if (runner.NuGetVersion.Major >= 2 && runner.NuGetVersion.Minor >= 5)
            {
                yield return(path("2.5"));
            }
            else if (runner.NuGetVersion.Major >= 2)
            {
                yield return(path("2.0"));
            }
            else
            {
                yield return(path("1.4"));
            }
        }
Example #5
0
        public NuGetInstallExtensions5(NuGetRunner runner, IEnumerable <string> extensions) : base(runner)
        {
            string extensionPaths = string.Join("; ", extensions.Select(Path.GetDirectoryName).Select(Path.GetFullPath).Where(NotNull).Distinct());

            Console.Out.WriteLine("Registered additional extensions from paths: {0}", extensionPaths);
            runner.AddEnvironmentVariable("NUGET_EXTENSIONS_PATH", extensionPaths);

            runner.BeforeNuGetStarted += (_, __) => CleanupHome();
        }
        private static void ConfigureExtensions(NuGetRunner runner)
        {
            if (runner.NuGetVersion.Major == 1 && runner.NuGetVersion.Minor <= 4 && runner.NuGetVersion.Revision < 20905)
            {
                Console.Out.WriteLine("Using shared plugin and mutex");
                new NuGetRunMutex(runner);
                new NuGetInstallExtensions4(runner, Extensions(runner));
                return;
            }

            new NuGetInstallExtensions5(runner, Extensions(runner));
        }
Example #7
0
        public static string LocateNuGetExtensionsPath(this NuGetRunner runner)
        {
            Assembly nuGetAssembly = runner.NuGetAssembly;
            var      mi            = nuGetAssembly.EntryPoint.DeclaringType;

            foreach (var type in new Func <Type>[] { () => mi.DeclaringType, () => nuGetAssembly.GetType("NuGet.Program") }.Select(Compute).Where(x => x != null))
            {
                var field = type.GetField("ExtensionsDirectoryRoot", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
                if (field != null && field.FieldType == typeof(string))
                {
                    var extensionsPath = field.GetValue(null) as string;
                    if (extensionsPath != null)
                    {
                        return(extensionsPath);
                    }
                }
            }
            //This is explicit path value taken from NuGet source code
            return(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "NuGet", "Commands"));
        }
        public NuGetInstallExtensions4(NuGetRunner runner, IEnumerable <string> extensions) : base(runner)
        {
            runner.BeforeNuGetStarted += (_, __) =>
            {
                string home = NuGetSharedExntensions;
                CleanupHome();

                if (!Directory.Exists(home))
                {
                    Directory.CreateDirectory(home);
                }

                foreach (var ext in extensions)
                {
                    var destFileName = Path.Combine(home, Path.GetFileName(ext));
                    File.Copy(ext, destFileName);
                }
            };

            runner.AfterNuGetFinished += (_, __) => CleanupHome();
        }
 protected NuGetInstallExtensionsBase(NuGetRunner runner)
 {
     NuGetExtensionsHome = new Lazy <string>(() => Path.Combine(runner.LocateNuGetExtensionsPath(), "TeamCity.Extensions"));
 }
Example #10
0
 private static IEnumerable <string> Extensions(NuGetRunner runner)
 {
     return(new[] { Path.Combine(typeof(Program).GetAssemblyDirectory(), "plugins4/JetBrains.TeamCity.NuGet.ExtendedCommands.dll") });
 }