Пример #1
0
        public static int AddPackage(string[] args, [CanBeNull] AbsolutePath rootDirectory, [CanBeNull] AbsolutePath buildScript)
        {
            PrintInfo();
            Logging.Configure();
            Telemetry.AddPackage();
            ProjectModelTasks.Initialize();

            var packageId      = args.ElementAt(0);
            var packageVersion =
                (EnvironmentInfo.GetParameter <string>("version") ??
                 args.ElementAtOrDefault(1) ??
                 NuGetPackageResolver.GetLatestPackageVersion(packageId, includePrereleases: false).GetAwaiter().GetResult() ??
                 NuGetPackageResolver.GetGlobalInstalledPackage(packageId, version: null, packagesConfigFile: null)?.Version.ToString())
                .NotNull("packageVersion != null");

            var configuration    = GetConfiguration(buildScript, evaluate: true);
            var buildProjectFile = configuration[BUILD_PROJECT_FILE];

            Host.Information($"Installing {packageId}/{packageVersion} to {buildProjectFile} ...");
            AddOrReplacePackage(packageId, packageVersion, PACKAGE_TYPE_DOWNLOAD, buildProjectFile);
            DotNetTasks.DotNet($"restore {buildProjectFile}");

            var installedPackage = NuGetPackageResolver.GetGlobalInstalledPackage(packageId, packageVersion, packagesConfigFile: null)
                                   .NotNull("installedPackage != null");
            var hasToolsDirectory = installedPackage.Directory.GlobDirectories("tools").Any();

            if (!hasToolsDirectory)
            {
                AddOrReplacePackage(packageId, packageVersion, PACKAGE_TYPE_REFERENCE, buildProjectFile);
            }

            Host.Information($"Done installing {packageId}/{packageVersion} to {buildProjectFile}");
            return(0);
        }
Пример #2
0
        static Telemetry()
        {
            var optoutParameter = EnvironmentInfo.GetParameter <string>(OptOutEnvironmentKey) ?? string.Empty;

            if (optoutParameter == "1" || optoutParameter.EqualsOrdinalIgnoreCase(bool.TrueString))
            {
                return;
            }

            ProjectModelTasks.Initialize();
            s_confirmedVersion = SuppressErrors(CheckAwareness, includeStackTrace: true);
            if (s_confirmedVersion == null)
            {
                return;
            }

            var configuration = TelemetryConfiguration.CreateDefault();

            s_client = new TelemetryClient(configuration)
            {
                InstrumentationKey = InstrumentationKey
            };
            s_client.Context.Session.Id         = Guid.NewGuid().ToString();
            s_client.Context.Location.Ip        = "N/A";
            s_client.Context.Cloud.RoleInstance = "N/A";
        }
Пример #3
0
        private static void UpdateBuildProject(AbsolutePath buildScript)
        {
            var configuration = GetConfiguration(buildScript, evaluate: true);
            var projectFile   = configuration[BUILD_PROJECT_FILE];

            ProjectModelTasks.Initialize();
            ProjectUpdater.Update(projectFile);
        }
Пример #4
0
        public Build()
        {
            NugetVersion = new Lazy <string>(GetNugetVersion);

            // This initialisation is required to ensure the build script can
            // perform actions such as GetRuntimeIdentifiers() on projects.
            ProjectModelTasks.Initialize();
        }
Пример #5
0
        public static int CakeConvert(string[] args, [CanBeNull] AbsolutePath rootDirectory, [CanBeNull] AbsolutePath buildScript)
        {
            PrintInfo();
            Logging.Configure();
            Telemetry.ConvertCake();
            ProjectModelTasks.Initialize();

            Host.Warning(
                new[]
            {
                "Converting .cake files is a best effort approach using syntax rewriting.",
                "Compile errors are to be expected, however, the following elements are currently covered:",
                "  - Target definitions",
                "  - Default targets",
                "  - Parameter declarations",
                "  - Absolute paths",
                "  - Globbing patterns",
                "  - Tool invocations (dotnet CLI, SignTool)",
                "  - Addin and tool references",
            }.JoinNewLine());

            Host.Debug();
            if (!PromptForConfirmation("Continue?"))
            {
                return(0);
            }
            Host.Debug();

            if (buildScript == null &&
                PromptForConfirmation("Should a NUKE project be created for better results?"))
            {
                Setup(args, rootDirectory: null, buildScript: null);
            }

            var buildProjectFile = File.Exists(WorkingDirectory / CurrentBuildScriptName)
                ? GetConfiguration(WorkingDirectory / CurrentBuildScriptName, evaluate: true)
                                   .GetValueOrDefault(BUILD_PROJECT_FILE, defaultValue: null)
                : null;

            string GetOutputDirectory(string file)
            => Path.GetDirectoryName(buildProjectFile ?? file);

            string GetOutputFile(string file)
            => (AbsolutePath)GetOutputDirectory(file) / Path.GetFileNameWithoutExtension(file).Capitalize() + ".cs";

            GetCakeFiles().ForEach(x => File.WriteAllText(path: GetOutputFile(x), contents: GetCakeConvertedContent(File.ReadAllText(x))));

            if (buildProjectFile != null)
            {
                GetCakeFiles().SelectMany(x => GetCakePackages(File.ReadAllText(x)))
                .ForEach(x => AddOrReplacePackage(x.PackageId, x.PackageVersion, x.PackageType, buildProjectFile));
            }

            return(0);
        }