Example #1
0
        public TRunner CleanOutput()
        {
            ScriptExecutionEnvironment.LogTaskStarted("Cleaning solution outputs");

            solution.ForEachProject(
                delegate(VSProjectInfo projectInfo)
            {
                if (projectInfo is VSProjectWithFileInfo)
                {
                    VSProjectWithFileInfo info = (VSProjectWithFileInfo)projectInfo;

                    string projectOutputPath = GetProjectOutputPath(info);

                    if (projectOutputPath == null)
                    {
                        return;
                    }

                    projectOutputPath = Path.Combine(info.ProjectDirectoryPath, projectOutputPath);

                    DeleteDirectory(projectOutputPath, false);

                    string projectObjPath = String.Format(
                        CultureInfo.InvariantCulture,
                        @"{0}\obj\{1}",
                        projectInfo.ProjectName,
                        buildConfiguration);
                    projectObjPath = Path.Combine(productRootDir, projectObjPath);
                    DeleteDirectory(projectObjPath, false);
                }
            });

            ScriptExecutionEnvironment.LogTaskFinished();
            return(ReturnThisTRunner());
        }
Example #2
0
        public TRunner PrepareBuildDirectory()
        {
            ScriptExecutionEnvironment.LogTaskStarted("Preparing the build directory");

            string fullBuildDir = MakePathFromRootDir(buildDir);

            DeleteDirectory(fullBuildDir, false);
            CreateDirectory(fullBuildDir, true);

            ScriptExecutionEnvironment.LogTaskFinished();

            return(ReturnThisTRunner());
        }
Example #3
0
        public DetergentBuildRunner CompileSolution2(string dotNetVersion)
        {
            ScriptExecutionEnvironment.LogTaskStarted("Compiling the solution");
            string msbuildPath = ScriptExecutionEnvironment.GetDotNetFWDir(dotNetVersion);

            ProgramRunner
            .AddArgument(MakePathFromRootDir(ProductId) + ".2010.sln")
            .AddArgument("/p:Configuration={0}", BuildConfiguration)
            .AddArgument("/consoleloggerparameters:NoSummary")
            .Run(Path.Combine(msbuildPath, @"msbuild.exe"));

            ScriptExecutionEnvironment.LogTaskFinished();
            return(this);
        }
Example #4
0
        public TRunner HudsonFetchBuildVersion()
        {
            ScriptExecutionEnvironment.LogTaskStarted("Fetching the build version");

            if (IsRunningUnderHudson)
            {
                ScriptExecutionEnvironment.LogMessage("Running under Hudson");

                string projectVersionFileName = MakePathFromRootDir(ProductId) + ".ProjectVersion.txt";

                if (false == File.Exists(projectVersionFileName))
                {
                    Fail("Project version file ('{0}') is missing.", projectVersionFileName);
                }

                using (Stream stream = File.Open(projectVersionFileName, FileMode.Open))
                {
                    using (StreamReader reader = new StreamReader(stream))
                    {
                        string versionAsString = reader.ReadLine();
                        BuildVersion = new Version(versionAsString);
                    }
                }

                string hudsonBuildNumberString = Environment.GetEnvironmentVariable("BUILD_NUMBER");
                int    hudsonBuildNumber       = int.Parse(hudsonBuildNumberString, CultureInfo.InvariantCulture);

                string svnRevisionNumberString = Environment.GetEnvironmentVariable("SVN_REVISION");
                int    svnRevisionNumber       = int.Parse(svnRevisionNumberString, CultureInfo.InvariantCulture);

                BuildVersion = new Version(
                    BuildVersion.Major,
                    BuildVersion.Minor,
                    svnRevisionNumber,
                    hudsonBuildNumber);

                Log("Project build version: {0}", BuildVersion);

                ScriptExecutionEnvironment.LogTaskFinished();
                return(ReturnThisTRunner());
            }

            return(FetchBuildVersion());
        }
Example #5
0
        /// <summary>
        /// Fetches the build version, either from the local version info file or from CCNet
        /// (if the build is running under CCNet).
        /// </summary>
        /// <param name="loadFromFile">If not running under CCNet, fetch version from file or not.</param>
        /// <returns>
        /// The same instance of this <see cref="TRunner"/>.
        /// </returns>
        public TRunner FetchBuildVersion(bool loadFromFile)
        {
            ScriptExecutionEnvironment.LogTaskStarted("Fetching the build version");

            if (IsRunningUnderCruiseControl)
            {
                string ccnetLabel      = Environment.GetEnvironmentVariable("CCNetLabel");
                Regex  ccnetLabelRegex = new Regex(@"(?<version>([0-9]+.){3}[0-9]+)", RegexOptions.ExplicitCapture);
                Match  match           = ccnetLabelRegex.Match(ccnetLabel);
                if (false == match.Success)
                {
                    Log(
                        "CCNet build label '{0}' could not be parsed to extract the build version. Using the default version instead",
                        ccnetLabel);
                }
                else
                {
                    BuildVersion = new Version(match.Groups["version"].Value);
                }
            }
            else if (loadFromFile)
            {
                string projectVersionFileName = MakePathFromRootDir(ProductId) + ".ProjectVersion.txt";

                if (false == File.Exists(projectVersionFileName))
                {
                    Fail("Project version file ('{0}') is missing.", projectVersionFileName);
                }

                using (Stream stream = File.Open(projectVersionFileName, FileMode.Open))
                {
                    using (StreamReader reader = new StreamReader(stream))
                    {
                        string versionAsString = reader.ReadLine();
                        BuildVersion = new Version(versionAsString);
                    }
                }
            }

            Log("Project build version: {0}", BuildVersion);

            ScriptExecutionEnvironment.LogTaskFinished();
            return(ReturnThisTRunner());
        }
Example #6
0
        public TRunner GenerateCommonAssemblyInfo(bool generateConfigurationAttribute, bool generateCultureAttribute, bool generateAssemblyVersion)
        {
            ScriptExecutionEnvironment.LogTaskStarted("Generating CommonAssemblyInfo file");

            if (buildVersion == null)
            {
                Fail("Assembly file version is not set.");
            }

            using (Stream stream = File.Open(Path.Combine(productRootDir, "CommonAssemblyInfo.cs"), FileMode.Create))
            {
                using (StreamWriter writer = new StreamWriter(stream))
                {
                    writer.WriteLine(
                        @"using System.Reflection;
using System.Runtime.InteropServices;

//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

[assembly: AssemblyCompanyAttribute(""{0}"")]
[assembly: AssemblyProductAttribute(""{1}"")]
[assembly: AssemblyCopyrightAttribute(""{2}"")]
[assembly: AssemblyTrademarkAttribute(""{3}"")]
[assembly: AssemblyFileVersionAttribute(""{4}"")]
[assembly: AssemblyInformationalVersionAttribute(""{5}"")]
[assembly: ComVisible(false)]",
                        companyName,
                        productName,
                        companyCopyright,
                        companyTrademark,
                        buildVersion,
                        buildVersion.ToString(2));

                    if (generateAssemblyVersion)
                    {
                        writer.WriteLine(@"[assembly: AssemblyVersionAttribute(""{0}.0.0"")]", buildVersion.ToString(2));
                    }

                    if (generateConfigurationAttribute)
                    {
                        writer.WriteLine(@"[assembly: AssemblyConfigurationAttribute(""{0}"")]", buildConfiguration);
                    }

                    if (generateCultureAttribute)
                    {
                        writer.WriteLine(@"[assembly: AssemblyCultureAttribute("""")]");
                    }
                }
            }

            ScriptExecutionEnvironment.LogTaskFinished();

            return(ReturnThisTRunner());
        }
Example #7
0
        public TRunner FxCop()
        {
            ScriptExecutionEnvironment.LogTaskStarted("Running FxCop analysis");

            string fxProjectPath = MakePathFromRootDir(productId) + ".FxCop";

            AssertFileExists("FxCop project file", fxProjectPath);

            string fxReportPath = EnsureBuildLogsTestDirectoryExists();

            fxReportPath = Path.Combine(fxReportPath, productId);
            fxReportPath = String.Format(
                CultureInfo.InvariantCulture,
                "{0}.FxCopReport.xml",
                fxReportPath);

            ProgramRunner
            .AddArgument(@"/project:{0}", fxProjectPath)
            .AddArgument(@"/out:{0}", fxReportPath)
            .AddArgument(@"/dictionary:CustomDictionary.xml")
            .AddArgument(@"/ignoregeneratedcode");

            string fxCopCmdPath = MakePathFromRootDir(
                Path.Combine(libDir, @"Microsoft FxCop 1.36\FxCopCmd.exe"));

            AssertFileExists("FxCopCmd.exe", fxCopCmdPath);
            ProgramRunner.Run(fxCopCmdPath, true);

            // check if the report file was generated
            bool isReportFileGenerated = File.Exists(fxReportPath);

            // FxCop returns different exit codes for different things
            // see http://msdn.microsoft.com/en-us/library/bb164705(VS.80).aspx for the list of exit codes
            // exit code 4 means "Project load error" but it occurs when the old FxCop violations exist
            // which are then removed from the code
            if ((ProgramRunner.LastExitCode != 0 && ProgramRunner.LastExitCode != 4) || isReportFileGenerated)
            {
                if (IsRunningUnderCruiseControl)
                {
                    if (File.Exists(fxReportPath))
                    {
                        string fxcopReportFileName = Path.GetFileName(fxReportPath);
                        try
                        {
                            CopyFile(fxReportPath, Path.Combine(ccnetDir, fxcopReportFileName), true);
                        }
                        catch (IOException)
                        {
                            Log(
                                "Warning: could not copy FxCop report file '{0}' to the CC.NET dir",
                                fxReportPath);
                        }
                    }
                }
                else if (IsRunningUnderHudson)
                {
                }
                else
                {
                    // run FxCop GUI
                    ProgramRunner
                    .AddArgument(fxProjectPath)
                    .Run(MakePathFromRootDir(Path.Combine(libDir, @"Microsoft FxCop 1.36\FxCop.exe")));
                }

                Fail("FxCop found violations in the code.");
            }

            ScriptExecutionEnvironment.LogTaskFinished();
            return(ReturnThisTRunner());
        }