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()); }
public static void TargetCleanOutput(ITaskContext context) { string buildConfiguration = context.Properties.Get <string>(BuildProps.BuildConfiguration); string productRootDir = context.Properties.Get(BuildProps.ProductRootDir, "."); VSSolution solution = context.Properties.Get <VSSolution>(BuildProps.Solution); solution.ForEachProject( delegate(VSProjectInfo projectInfo) { if (projectInfo is VSProjectWithFileInfo) { VSProjectWithFileInfo info = (VSProjectWithFileInfo)projectInfo; LocalPath projectOutputPath = info.GetProjectOutputPath(buildConfiguration); if (projectOutputPath == null) { return; } FullPath projectFullOutputPath = info.ProjectDirectoryPath.CombineWith(projectOutputPath); DeleteDirectoryTask.Execute(context, projectFullOutputPath.ToString(), false); string projectObjPath = String.Format( CultureInfo.InvariantCulture, @"{0}\obj\{1}", projectInfo.ProjectName, buildConfiguration); projectObjPath = Path.Combine(productRootDir, projectObjPath); DeleteDirectoryTask.Execute(context, projectObjPath, false); } }); }
/// <summary> /// Calculates the loc metrics for the whole project. /// </summary> /// <param name="projectWithFileInfo">The project info.</param> /// <param name="map">The map of <see cref="ILocStats"/> objects which can calculate LoC metrics for different source file types.</param> /// <returns> /// Returns the VSProjectLocMetrics instance. /// </returns> public static VSProjectLocMetrics CalculateLocForProject(VSProjectWithFileInfo projectWithFileInfo, LocStatsMap map) { VSProjectLocMetrics projectMetrics = new VSProjectLocMetrics(projectWithFileInfo); //For each Item file in project foreach (VSProjectItem item in projectWithFileInfo.Project.Items) { if (item.ItemType == VSProjectItem.CompileItem || item.ItemType == VSProjectItem.Content) { string filePath = Path.Combine( projectMetrics.ProjectWithFileInfo.ProjectDirectoryPath, item.Item); SourceFileLocMetrics sourceFile = SourceFileLocMetrics.CalcLocStatData(filePath, map); // make sure the file was not ignored (it wasn't a source file) if (sourceFile != null) { projectMetrics.AddLocMetrics(sourceFile); } } } return(projectMetrics); }
//private static void TargetPackageSource (ConcreteBuildRunner runner) //{ // List<string> files = new List<string>(); // string solutionDirectoryPath = Path.GetFullPath ( // Path.Combine ( // Environment.CurrentDirectory, // runner.Solution.SolutionDirectoryPath)); // files.Add(Path.GetFullPath(runner.Solution.SolutionFileName)); // Regex excludeFilter = new Regex(@"\.snk$"); // runner // .Solution // .ForEachProject(p => AddProjectFiles(p, solutionDirectoryPath, files, excludeFilter)); // ZipFilesTask zipFilesTask = new ZipFilesTask( // Path.Combine(runner.BuildPackagesDir, runner.ProductName + "-sources.zip"), // solutionDirectoryPath, // files); // zipFilesTask.CompressionLevel = 9; // zipFilesTask.ZipFileHeaderCallback = GetLicenseHeaderForSourceFiles; // runner.RunTask(zipFilesTask); //} private static void AddProjectFiles( VSProjectInfo project, string solutionDirectoryPath, ICollection <string> files, Regex excludeFilter) { if (project is VSProjectWithFileInfo) { VSProjectWithFileInfo projectWithFileInfo = (VSProjectWithFileInfo)project; files.Add(projectWithFileInfo.ProjectFileNameFull.ToFullPath().ToString()); foreach (VSProjectItem item in projectWithFileInfo.Project.Items) { if (item.ItemType == VSProjectItem.CompileItem || item.ItemType == VSProjectItem.Content || item.ItemType == VSProjectItem.NoneItem) { if (item.ItemProperties.ContainsKey("Link")) { continue; } string itemPath = Path.GetFullPath( Path.Combine( solutionDirectoryPath, Path.Combine( projectWithFileInfo.ProjectDirectoryPath.ToString(), item.Item))); if (excludeFilter.IsMatch(itemPath)) { continue; } files.Add(itemPath); } } } else if (project is VSSolutionFilesInfo) { VSSolutionFilesInfo solutionFilesInfo = (VSSolutionFilesInfo)project; foreach (string file in solutionFilesInfo.Files) { string fullPath = Path.GetFullPath(Path.Combine(solutionDirectoryPath, file)); if (excludeFilter.IsMatch(fullPath)) { continue; } files.Add(fullPath); } } }
public static FullPath GetProjectOutputPath(this ITaskContext context, string projectName) { VSSolution solution = context.Properties.Get <VSSolution>(BuildProps.Solution); VSProjectWithFileInfo projectInfo = (VSProjectWithFileInfo)solution.FindProjectByName(projectName); LocalPath projectOutputPath = projectInfo.GetProjectOutputPath( context.Properties.Get <string>(BuildProps.BuildConfiguration)); FullPath projectTargetDir = projectInfo.ProjectDirectoryPath.CombineWith(projectOutputPath); return(projectTargetDir); }
public TRunner Gendarme(params string[] projectNames) { string reportDir = EnsureBuildLogsTestDirectoryExists(); string reportFileName = string.Format( CultureInfo.InvariantCulture, "{0}.GendarmeReport.xml", ProductId); string gendarmeXmlReportFile = Path.Combine(reportDir, reportFileName); ProgramRunner .AddArgument("--html") .AddArgument("{0}.GendarmeReport.html", ProductId) .AddArgument("--xml") .AddArgument(gendarmeXmlReportFile) .AddArgument("--severity") .AddArgument("all"); new List <string>(projectNames).ForEach( projectName => { string outputPath = GetProjectOutputPath(projectName); if (outputPath == null) { return; } VSProjectWithFileInfo projectInfo = (VSProjectWithFileInfo)Solution.FindProjectByName(projectName); string projectOutputType = projectInfo.Project.Properties["OutputType"]; string projectAssemblyName = projectInfo.Project.Properties["AssemblyName"]; string projectAssemblyFileName = string.Format( CultureInfo.InvariantCulture, "{0}.{1}", projectAssemblyName, projectOutputType == "Library" ? "dll" : "exe"); string projectAssemblyFullPath = Path.Combine( Path.Combine( projectInfo.ProjectDirectoryPath, outputPath), projectAssemblyFileName); ProgramRunner.AddArgument(projectAssemblyFullPath); }); string gendarmePath = MakePathFromRootDir(LibDir + @"\Gendarme\gendarme.exe"); AssertFileExists("Gendarme.exe", gendarmePath); ProgramRunner.Run(gendarmePath, true); return(ReturnThisTRunner()); }
private void SetAssemblyFileNameAndWorkingDirFromProjectName(ITaskContext context) { if (projectName != null) { VSSolution solution = context.Properties.Get <VSSolution>(BuildProps.Solution); string buildConfiguration = context.Properties.Get <string>(BuildProps.BuildConfiguration); VSProjectWithFileInfo project = (VSProjectWithFileInfo)solution.FindProjectByName(projectName); FileFullPath projectTarget = project.ProjectDirectoryPath.CombineWith(project.GetProjectOutputPath(buildConfiguration)) .AddFileName("{0}.dll", project.ProjectName); testAssemblyFileName = projectTarget.ToString(); workingDirectory = Path.GetDirectoryName(projectTarget.ToString()); } }
private static void TargetPackage(ITaskContext context) { FullPath packagesDir = new FullPath(context.Properties.Get(BuildProps.ProductRootDir, ".")); packagesDir = packagesDir.CombineWith(context.Properties.Get <string>(BuildProps.BuildDir)); FullPath simplexPackageDir = packagesDir.CombineWith("Detergent"); FileFullPath zipFileName = packagesDir.AddFileName( "Detergent-{0}.zip", context.Properties.Get <Version>(BuildProps.BuildVersion)); StandardPackageDef packageDef = new StandardPackageDef("Detergent", context); VSSolution solution = context.Properties.Get <VSSolution>(BuildProps.Solution); VSProjectWithFileInfo projectInfo = (VSProjectWithFileInfo)solution.FindProjectByName("Detergent"); LocalPath projectOutputPath = projectInfo.GetProjectOutputPath( context.Properties.Get <string>(BuildProps.BuildConfiguration)); FullPath projectTargetDir = projectInfo.ProjectDirectoryPath.CombineWith(projectOutputPath); packageDef.AddFolderSource( "bin", projectTargetDir, false); ICopier copier = new Copier(context); CopyProcessor copyProcessor = new CopyProcessor( context, copier, simplexPackageDir); copyProcessor .AddTransformation("bin", new LocalPath(string.Empty)); IPackageDef copiedPackageDef = copyProcessor.Process(packageDef); Zipper zipper = new Zipper(context); ZipProcessor zipProcessor = new ZipProcessor( context, zipper, zipFileName, simplexPackageDir, null, "bin"); zipProcessor.Process(copiedPackageDef); }
public DetergentBuildRunner RunTests2(string projectName, bool collectCoverageData) { Log("Runs tests on '{0}' assembly ({1})", new object[] { projectName, collectCoverageData ? "with coverage" : "without coverage" }); string buildLogsDir = EnsureBuildLogsTestDirectoryExists(); VSProjectWithFileInfo testProjectWithFileInfo = (VSProjectWithFileInfo)Solution.FindProjectByName(projectName); string projectTargetPath = GetProjectOutputPath(testProjectWithFileInfo.ProjectName); projectTargetPath = Path.Combine(testProjectWithFileInfo.ProjectDirectoryPath, projectTargetPath) + testProjectWithFileInfo.ProjectName + ".dll"; projectTargetPath = Path.GetFullPath(MakePathFromRootDir(projectTargetPath)); string gallioEchoExePath = MakePathFromRootDir(Path.Combine(LibDir, @"Gallio\bin\Gallio.Echo.exe")); try { //if (collectCoverageData) //{ // ProgramRunner.AddArgument(Path.Combine(LibDir, @"NCover v1.5.8\CoverLib.dll")).AddArgument("/s").Run("regsvr32"); // ProgramRunner.AddArgument(gallioEchoExePath); //} ProgramRunner .AddArgument(projectTargetPath) .AddArgument("/runner:NCover") .AddArgument("/report-directory:{0}", new object[] { buildLogsDir }) .AddArgument("/report-name-format:TestResults-{0}", new object[] { TestRuns }) .AddArgument("/report-type:xml") .AddArgument("/verbosity:verbose"); //if (collectCoverageData) //{ // ProgramRunner.AddArgument("//x").AddArgument(@"{0}\Coverage-{1}.xml", new object[] { buildLogsDir, TestRuns }).AddArgument("//ea").AddArgument("MbUnit.Framework.TestFixtureAttribute").AddArgument("//w").AddArgument(Path.GetDirectoryName(projectTargetPath)).AddArgument("//v").Run(MakePathFromRootDir(Path.Combine(libDir, @"NCover v1.5.8\NCover.Console.exe"))); // CoverageResultsExist = true; //} //else //{ ProgramRunner.Run(gallioEchoExePath); //} IncrementTestRunsCounter(); } finally { //if (collectCoverageData) //{ // ProgramRunner.AddArgument(Path.Combine(LibDir, @"NCover v1.5.8\CoverLib.dll")).AddArgument("/s").AddArgument("/u").Run("regsvr32"); //} } return(this); }
public static void TargetRunTestsNUnit( ITaskContext context, string projectName) { VSSolution solution = context.Properties.Get <VSSolution>(BuildProps.Solution); string buildConfiguration = context.Properties.Get <string>(BuildProps.BuildConfiguration); VSProjectWithFileInfo project = (VSProjectWithFileInfo)solution.FindProjectByName(projectName); FileFullPath projectTarget = project.ProjectDirectoryPath.CombineWith(project.GetProjectOutputPath(buildConfiguration)) .AddFileName("{0}.dll", project.ProjectName); IRunProgramTask task = new RunProgramTask( context.Properties[BuildProps.NUnitConsolePath]) .AddArgument(projectTarget.ToString()) .AddArgument("/labels") .AddArgument("/trace=Verbose") .AddArgument("/nodots") .AddArgument("/noshadow"); task.Execute(context); }
/// <summary> /// Adds the specified VisualStudio project to the list of build products. /// </summary> /// <param name="productPartId">The ID of the product part this project belongs to.</param> /// <param name="projectName">Name of the project.</param> /// <param name="productDirectoryPath">The path relative to the package directory where this product's files will be copied. /// If set to <see cref="string.Empty"/>, the files will be copied directly on the top-level directory.</param> /// <param name="includeDebugFiles">Indicates whether the PDB files should be included in the package.</param> /// <returns> /// This same instance of the <see cref="BuildProductsRegistry{TRunner}"/>. /// </returns> public BuildProductsRegistry <TRunner> AddProject( string productPartId, string projectName, string productDirectoryPath, bool includeDebugFiles) { VSProjectWithFileInfo projectWithFileInfo = (VSProjectWithFileInfo)runner.Solution.FindProjectByName(projectName); if (runner.ProjectExtendedInfos.ContainsKey(projectName)) { VSProjectExtendedInfo extendedInfo = runner.ProjectExtendedInfos[projectName]; if (extendedInfo.IsWebProject) { buildProducts.Add( new WebApplicationBuildProduct <TRunner> ( productPartId, projectWithFileInfo.ProjectDirectoryPath, productDirectoryPath)); return(this); } } string excludeFilter = null; if (false == includeDebugFiles) { excludeFilter = @".*\.pdb$"; } buildProducts.Add( new SimpleBuildProduct <TRunner> ( productPartId, Path.Combine(projectWithFileInfo.ProjectDirectoryPath, runner.GetProjectOutputPath(projectName)), productDirectoryPath, null, excludeFilter)); return(this); }
/// <summary> /// Gets the output path for a specified VisualStudio project. The output path is relative /// to the directory where the project file is located. /// </summary> /// <param name="projectWithFileInfo">Project info.</param> /// <returns>The output path or <c>null</c> if the project is not compatibile.</returns> /// <exception cref="ArgumentException">The method could not extract the data from the project file.</exception> public string GetProjectOutputPath(VSProjectWithFileInfo projectWithFileInfo) { if (projectWithFileInfo == null) { return(null); } // skip non-C# projects if (projectWithFileInfo.ProjectTypeGuid != VSProjectType.CSharpProjectType.ProjectTypeGuid) { return(null); } // find the project configuration string condition = FormatString(" '$(Configuration)|$(Platform)' == '{0}|AnyCPU' ", buildConfiguration); VSProjectConfiguration projectConfiguration = projectWithFileInfo.Project.FindConfiguration(condition); if (projectConfiguration == null) { throw new ArgumentException( FormatString( "Could not find '{0}' configuration for the project '{1}'.", condition, projectWithFileInfo.ProjectName)); } if (false == projectConfiguration.Properties.ContainsKey("OutputPath")) { throw new ArgumentException( FormatString( "Missing OutputPath for the '{0}' configuration of the project '{1}'.", buildConfiguration, projectWithFileInfo.ProjectName)); } return(projectConfiguration.Properties["OutputPath"]); }
public VSProjectLocMetrics(VSProjectWithFileInfo projectWithFileInfo) : base(projectWithFileInfo.ProjectFileNameFull) { this.projectWithFileInfo = projectWithFileInfo; }
/// <summary> /// Gets the output path for a specified VisualStudio project. The output path is relative /// to the directory where the project file is located. /// </summary> /// <param name="projectName">Project name.</param> /// <returns>The output path or <c>null</c> if the project is not compatibile.</returns> /// <exception cref="ArgumentException">The method could not extract the data from the project file.</exception> public string GetProjectOutputPath(string projectName) { VSProjectWithFileInfo projectWithFileInfo = (VSProjectWithFileInfo)solution.FindProjectByName(projectName); return(GetProjectOutputPath(projectWithFileInfo)); }