Beispiel #1
0
        private string Execute(string[] commands, out string error, string expectedOutputFilePattern = null, string path = null, bool checkResultForErros = false)
        {
            string result;

            LoggingManager.Instance.Logger.Debug($"executing command(s) [{string.Join("] and [", commands)}]");
            var commandStartTime = DateTime.Now;

            CommandUtil.ExecuteCommands(commands, new string[] { "/C" }, out result, out error);

            if (checkResultForErros)
            {
                //     check the ExecuteCommands out result variable for erros
                //     commands might redirect errors to stdOut (MsBuild.exe specifically - and ExecuteCommand seems to ignore Process.ExitCode):
                if (string.IsNullOrEmpty(error) && Regex.IsMatch(result, pattern: @"(: error )|(\s+Build FAILED\b)"))
                {
                    error  = result;
                    result = null;
                }
            }

            if (expectedOutputFilePattern == null)
            {
                Logg(result, error);
                return(null);
            }
            //-----make sure a new output file was created
            string outputFileFullname = null;

            try
            {
                var expectedMinTime = commandStartTime.ToUniversalTime().AddSeconds(-1);
                var directoryInfo   = new DirectoryInfo(path);
                var fileInfos       = directoryInfo.GetFiles(expectedOutputFilePattern);
                foreach (var expectedFile in fileInfos.OrderByDescending(f => f.CreationTime))
                {
                    if (expectedFile.LastWriteTimeUtc > expectedMinTime)
                    {
                        outputFileFullname = expectedFile.FullName;
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                LoggingManager.Instance.Logger.Warn($"Error in GetLastFile({path}, {expectedOutputFilePattern}, {commandStartTime}, {1})", ex);
            }
            Logg(result, error, doWarnResult: outputFileFullname == null);
            return(outputFileFullname);
        }
Beispiel #2
0
        /// <summary>
        /// builds the nuPkg file
        /// </summary>
        /// <returns>true if the nuPkg file was build, false otherwise</returns>
        private void BuildNuGetPackage(DeploymentInformation deployInfo, ref string nuPkgFilePath)
        {
            LoggingManager.Instance.Logger.Debug("creating nupkg file");

            //-----create the .nuPkg file in the folder
            string result;
            string error;

            nuPkgFilePath = Path.Combine(deployInfo.Build.BuildPath, string.Format("{0}.{1}.nupkg", deployInfo.NuSpecPackage.Metadata.Id, deployInfo.NuSpecPackage.Metadata.Version));
            string commandOne = string.Format(@"cd /D ""{0}"" ", deployInfo.Build.BuildPath);
            string commandTwo = string.Format(@" ""{0}"" pack ""{1}"" ", OptionsManager.Instance.Configuration.GeneralOptions.NuGetOptions.ExePath, deployInfo.NuSpecFileFullName);

            LoggingManager.Instance.Logger.Debug(string.Format("executing command [{0}]  and [{1}]", commandOne, commandTwo));
            CommandUtil.ExecuteCommands(new string[] { commandOne, commandTwo }, new string[] { "/C" }, out result, out error);

            //-----make sure the nuPkg file was build
            if (!string.IsNullOrEmpty(error) || !File.Exists(nuPkgFilePath))
            {
                throw new BuildNuGetPackageFailedExceptions(!string.IsNullOrEmpty(error) ? string.Format("An Error occured while creating the nuPkg file: {0}", error) :
                                                            string.Format("Could not create nuPkg file: {0}", nuPkgFilePath));
            }

            //-----delete the nuSpec file is possible
            if (!deployInfo.ProjectOptions.NuGetOptions.NuSpecOptions.Metadata.UseAny && !deployInfo.ProjectOptions.NuGetOptions.NuSpecOptions.Files.UseFromSettings)
            {
                try
                {
                    File.Delete(deployInfo.NuSpecFileFullName);
                }
                catch (Exception ex)
                {
                    LoggingManager.Instance.Logger.Warn(ex);
                }
            }

            LoggingManager.Instance.Logger.Debug("creating nupkg file finished");
        }