private static void TargetIlMerge(ITaskContext context) { CreateDirectoryTask.Execute(context, "./output", false); string projectTargetDir = Path.Combine("Flubu.Console", "bin", context.Properties[BuildProps.BuildConfiguration]); IRunProgramTask progTask = new RunProgramTask(@"lib\IlMerge\IlMerge.exe") .SetWorkingDir(projectTargetDir); progTask .EncloseParametersInQuotes(false) .ExecutionTimeout(TimeSpan.FromSeconds(30)) .AddArgument("/t:exe") .AddArgument("/xmldocs") .AddArgument("/v4") .AddArgument("/out:..\\..\\..\\output\\Build.exe") .AddArgument("flubu.console.exe") .AddArgument("CommandLine.dll") .AddArgument("CSScriptLibrary.dll") .AddArgument("Flubu.dll") .AddArgument("Flubu.Contrib.dll") .AddArgument("ICSharpCode.SharpZipLib.dll") .AddArgument("Microsoft.Web.Administration.dll") .AddArgument("Mono.CSharp.dll") .Execute(context); }
public void ExecuteDotNetCommandWithFullPath() { var fileName = GetOsPlatform() == OSPlatform.Windows ? "C:\\Program Files\\dotnet\\dotnet.exe" : "/usr/bin/dotnet"; string currentFolder = Directory.GetCurrentDirectory(); var path = Path.GetFullPath(fileName); _commandFactory.Setup(i => i.Create(path, new List <string> { "--version" }, null, "Debug")).Returns(_command.Object); _command.Setup(i => i.CaptureStdErr()).Returns(_command.Object); _command.Setup(i => i.CaptureStdOut()).Returns(_command.Object); _command.Setup(i => i.WorkingDirectory(currentFolder)).Returns(_command.Object); _command.Setup(i => i.OnErrorLine(It.IsAny <Action <string> >())).Returns(_command.Object); _command.Setup(i => i.OnOutputLine(It.IsAny <Action <string> >())).Returns(_command.Object); _command.Setup(i => i.Execute()).Returns(new CommandResult(new ProcessStartInfo { Arguments = "aa" }, 0, string.Empty, string.Empty)); RunProgramTask task = new RunProgramTask(_commandFactory.Object, fileName); int res = task .WithArguments("--version") .Execute(Context); Assert.Equal(0, res); }
protected override int DoExecute(ITaskContextInternal context) { RunProgramTask task = new RunProgramTask(new CommandFactory(), _openCoverPath); string testExecutable = GetExecutable(); task .WithArguments( $"-target:{testExecutable}", "-register:user", "-oldstyle", "-returntargetcode", $"-output:{_output}"); if (!string.IsNullOrEmpty(_workingFolder)) { task.WorkingFolder(_workingFolder); } if (!string.IsNullOrEmpty(_testExecutableArgs)) { task.WithArguments($"-targetargs:{_testExecutableArgs}"); } string filter = PrepareFilter(); if (!string.IsNullOrEmpty(filter)) { task.WithArguments($"-filter:{filter}"); } task.ExecuteVoid(context); return(0); }
public void ExecuteCommand() { string currentFolder = Directory.GetCurrentDirectory(); _commandFactory.Setup(i => i.Create("git", new List <string> { "--version" }, null, "Debug")).Returns(_command.Object); _command.Setup(i => i.CaptureStdErr()).Returns(_command.Object); _command.Setup(i => i.CaptureStdOut()).Returns(_command.Object); _command.Setup(i => i.WorkingDirectory(currentFolder)).Returns(_command.Object); _command.Setup(i => i.OnErrorLine(It.IsAny <Action <string> >())).Returns(_command.Object); _command.Setup(i => i.OnOutputLine(It.IsAny <Action <string> >())).Returns(_command.Object); _command.Setup(i => i.Execute()).Returns(new CommandResult(new ProcessStartInfo { Arguments = "aa" }, 0, string.Empty, string.Empty)); RunProgramTask task = new RunProgramTask(_commandFactory.Object, "git"); int res = task .WithArguments("--version") .Execute(Context); Assert.Equal(0, res); }
/// <summary> /// Abstract method defining the actual work for a task. /// </summary> /// <remarks>This method has to be implemented by the inheriting task.</remarks> /// <param name="context">The script execution environment.</param> protected override void DoExecute(ITaskContext context) { if (nunitConsoleFileName == null) { nunitConsoleFileName = context.Properties.Get <string>(BuildProps.NUnitConsolePath); } RunProgramTask task = new RunProgramTask(nunitConsoleFileName, false); SetAssemblyFileNameAndWorkingDirFromProjectName(context); Validate(); task .SetWorkingDir(workingDirectory) .EncloseParametersInQuotes(false) .AddArgument(string.Format(CultureInfo.InvariantCulture, "\"{0}\"", testAssemblyFileName)); foreach (var nunitCommandLineOption in nunitCommandLineOptions) { task.AddArgument(nunitCommandLineOption); } if (!string.IsNullOrEmpty(targetFramework)) { task.AddArgument("/framework:{0}", targetFramework); } if (!string.IsNullOrEmpty(categories)) { task.AddArgument("--where \"{0}\"", categories); } task.Execute(context); }
private static void TargetIlMerge(ITaskContext context) { CreateDirectoryTask.Execute(context, "./output", false); string projectTargetDir = Path.Combine( "Flubu.Console", "bin", context.Properties[BuildProps.BuildConfiguration]); IRunProgramTask progTask = new RunProgramTask(@"packages\ILRepack.2.0.16\tools\ILRepack.exe") .SetWorkingDir(projectTargetDir); progTask .EncloseParametersInQuotes(false) .ExecutionTimeout(TimeSpan.FromSeconds(30)) .AddArgument("/target:exe") .AddArgument("/xmldocs") //.AddArgument("/v4.6") //.AddArgument(@"/targetplatform:v4.6,""C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6""") //.AddArgument(@"/targetplatform:v4,""C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0""") //.AddArgument(@"/lib:""C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0""") .AddArgument("/out:..\\..\\..\\output\\Build.exe") .AddArgument("flubu.console.exe") //.AddArgument("CommandLine.dll") .AddArgument("CSScriptLibrary.dll") .AddArgument("Flubu.dll") .AddArgument("Flubu.Contrib.dll") .AddArgument("ICSharpCode.SharpZipLib.dll") .AddArgument("Microsoft.Web.Administration.dll") .AddArgument("Mono.CSharp.dll") .Execute(context); }
protected override void DoExecute(ITaskContext context) { IRunProgramTask task = new RunProgramTask(ExecutablePath) .SetWorkingDir(WorkingDirectory); task.AddArgument(AssemblyName) .Execute(context); }
private static void TargetSetupIis(ITaskContext context) { RunProgramTask task = new RunProgramTask("PowerShell.exe"); task .AddArgument("-executionpolicy").AddArgument("remotesigned") .AddArgument(@"AppVeyor\BuildInstall.ps1"); task.Execute(context); }
protected override void DoExecute(ITaskContext context) { var task = new RunProgramTask(ExecutablePath); if (string.IsNullOrEmpty(CertCommonName)) { throw new TaskExecutionException("Certificate common name must be set."); } task .EncloseParametersInQuotes(false) .AddArgument("-n \"CN={0}\"", CertCommonName) .AddArgument("-cy {0}", CertType == Misc.CertificateType.Authority ? "authority" : "end"); if (CertType == Misc.CertificateType.Authority) { task .AddArgument("-sv \"{0}\"", AuthorityPrivateKeyFile) .AddArgument("-r"); } else { if (string.IsNullOrEmpty(OutputFile)) { throw new TaskExecutionException("Output filename must be set."); } task .AddArgument("-a sha1") .AddArgument("-sky exchange") .AddArgument("-sy 12") .AddArgument("-sp \"Microsoft RSA SChannel Cryptographic Provider\"") .AddArgument("-ss My") .AddArgument("-ic \"{0}\"", AuthorityCertificateFile) .AddArgument("-iv \"{0}\"", AuthorityPrivateKeyFile) .AddArgument("-pe"); if (CertType == Misc.CertificateType.Server) { task.AddArgument("-eku 1.3.6.1.5.5.7.3.1") .AddArgument("-sr localmachine"); } else { task.AddArgument("-eku 1.3.6.1.5.5.7.3.2") .AddArgument("-sr currentuser") .AddArgument("-sk \"{0}\"", CertCommonName) .AddArgument("-ir localmachine"); } } task.AddArgument("\"{0}\"", OutputFile) .Execute(context); }
private void SetupRunProgramTask() { Tasks.Setup(x => x.RunProgramTask(It.IsAny <string>())).Returns(RunProgramTask.Object); RunProgramTask.Setup(x => x.WorkingFolder(".")).Returns(RunProgramTask.Object); RunProgramTask.Setup(x => x.WithArguments(It.IsAny <string>(), false)).Returns(RunProgramTask.Object); RunProgramTask.Setup(x => x.WithArguments(It.IsAny <string[]>())).Returns(RunProgramTask.Object); RunProgramTask.Setup(x => x.WithArguments("/p:Configuration=Release", false)) .Returns(RunProgramTask.Object); RunProgramTask.Setup(x => x.WithArguments("/p:Platform=Any CPU", false)).Returns(RunProgramTask.Object); RunProgramTask.Setup(x => x.WithArguments("/clp:NoSummary", false)).Returns(RunProgramTask.Object); RunProgramTask.Setup(x => x.WithArguments("/maxcpucount:3", false)).Returns(RunProgramTask.Object); }
protected override int DoExecute(ITaskContextInternal context) { RunProgramTask task = new RunProgramTask(new CommandFactory(), _toolPath); task .WorkingFolder(_workingFolder) .WithArguments($"-input:{_input}", $"-output:{_output}"); task.ExecuteVoid(context); return(0); }
protected override int DoExecute(ITaskContextInternal context) { RunProgramTask task = new RunProgramTask(new CommandFactory(), _toolPath); task .WorkingFolder(_workingFolder) .WithArguments($"-targetdir:{_targetFolder}", $"-reports:{string.Join(";", _inputFiles)}"); task.ExecuteVoid(context); return(0); }
protected override void DoExecute(IScriptExecutionEnvironment environment) { StringBuilder argumentLineBuilder = new StringBuilder(); argumentLineBuilder.Append("transform "); argumentLineBuilder.AppendFormat("\"-i={0}\" ", GallioReportPath); argumentLineBuilder.AppendFormat("\"-o={0}\" ", AccipioTransformsPath); RunProgramTask task = new RunProgramTask(AccipioPath, argumentLineBuilder.ToString(), new TimeSpan(0, 1, 0, 0)) { WorkingDirectory = WorkingDirectory, }; task.Execute(environment); }
public void QueryStoppedService() { Properties.Setup(i => i.Set("eventlog.status", ServiceStatus.Stopped, true)); RunProgramTask.Setup(i => i.GetOutput()).Returns(@"SERVICE_NAME: AppIDSvc TYPE : 20 WIN32_SHARE_PROCESS STATE : 1 STOPPED WIN32_EXIT_CODE : 1077 (0x435) SERVICE_EXIT_CODE : 0 (0x0) CHECKPOINT : 0x0 WAIT_HINT : 0x0"); _task.ExecuteVoid(Context.Object); Properties.VerifyAll(); }
private static string MergeCoverageSnapshots(ITaskContext context, string dotCoverExeFileName, List <string> snapshots) { context.WriteInfo("Merging coverage snapshots..."); string buildDir = context.Properties[BuildProps.BuildDir]; string mergedSnapshotFileName = Path.Combine(buildDir, "{0}.dcvr".Fmt(context.Properties[BuildProps.ProductId])); IRunProgramTask runDotCovertask = new RunProgramTask(dotCoverExeFileName).AddArgument("merge").AddArgument("/Source={0}", snapshots.Concat(x => x, ";")).AddArgument("/Output={0}", mergedSnapshotFileName) //.AddArgument("/LogFile={0}", Path.Combine(buildDir, "dotCover-log.xml")) ; runDotCovertask.Execute(context); return(mergedSnapshotFileName); }
private void RunCoverTask( ITaskContext context, IPathBuilder assemblyFullFileName, string dotCoverExeFileName, string snapshotFileName) { string projectDir = Path.GetDirectoryName(assemblyFullFileName.ToString()); string projectBinFileName = Path.GetFileName(assemblyFullFileName.FileName); context.WriteInfo("Running unit tests (with code coverage)..."); IRunProgramTask runDotCovertask = new RunProgramTask(dotCoverExeFileName).AddArgument("cover").AddArgument("/TargetExecutable={0}", nunitRunnerFileName).AddArgument("/TargetArguments={0} {1}", projectBinFileName, NUnitCmdLineOptions).AddArgument("/TargetWorkingDir={0}", projectDir).AddArgument("/Filters={0}", DotCoverFilters).AddArgument("/AttributeFilters={0}", DotCoverAttributeFilters).AddArgument("/Output={0}", snapshotFileName) //.AddArgument("/LogFile={0}", Path.Combine(buildDir, "dotCover-log.xml")) .AddArgument("/ReturnTargetExitCode"); runDotCovertask.Execute(context); }
private string RunDupFinder(ITaskContext context) { DownloadNugetPackageInUserRepositoryTask downloadPackageTask = new DownloadNugetPackageInUserRepositoryTask( ResharperCmdLineToolsPackageId); downloadPackageTask.Execute(context); string dupFinderExeFileName = Path.Combine(downloadPackageTask.PackageDirectory, "tools/dupfinder.exe"); if (!File.Exists(dupFinderExeFileName)) { context.WriteMessage( TaskMessageLevel.Warn, "R# dupfinder is not present in the expected location ('{0}'), cannot run source code duplicates analysis", dupFinderExeFileName); return(null); } string buildsDir = context.Properties[BuildProps.BuildDir]; string dupFinderXmlReportFileName = Path.Combine(buildsDir, "dupfinder-report.xml"); IRunProgramTask task = new RunProgramTask( dupFinderExeFileName) .AddArgument("--output={0}", dupFinderXmlReportFileName) .AddArgument("--show-text"); if (exclude != null) { task.AddArgument("--exclude={0}", exclude); } if (excludeByComment != null) { task.AddArgument("--exclude-by-comment={0}", excludeByComment); } if (excludeCodeRegions != null) { task.AddArgument("--exclude-code-regions={0}", excludeCodeRegions); } task .AddArgument(context.Properties[BuildProps.SolutionFileName]) .Execute(context); return(dupFinderXmlReportFileName); }
protected override void DoExecute(IScriptExecutionEnvironment environment) { StringBuilder argumentLineBuilder = new StringBuilder(); argumentLineBuilder.Append("report "); argumentLineBuilder.AppendFormat("\"-i={0}\" ", AccipioTransformsPath); argumentLineBuilder.AppendFormat("\"-o={0}\" ", AccipioOutputPath); argumentLineBuilder.Append("\"-p=Push Dispatcher\" "); argumentLineBuilder.AppendFormat("\"-t={0}\" ", AccipioTemplatePath); argumentLineBuilder.AppendFormat("\"-c={0}\" ", "TestReport.css"); RunProgramTask task = new RunProgramTask(AccipioPath, argumentLineBuilder.ToString(), new TimeSpan(0, 1, 0, 0)) { WorkingDirectory = WorkingDirectory, }; task.Execute(environment); }
public void WaitForStopService() { Properties.Setup(i => i.Get <ServiceStatus>("eventlog.status", true, string.Empty)).Returns(ServiceStatus.Stopped); var task = new WaitForServiceStopTask("eventlog"); Tasks.Setup(x => x.RunProgramTask("sc")).Returns(RunProgramTask.Object); RunProgramTask.Setup(i => i.GetOutput()).Returns(@"SERVICE_NAME: AppIDSvc TYPE : 20 WIN32_SHARE_PROCESS STATE : 1 ST WIN32_EXIT_CODE : 1077 (0x435) SERVICE_EXIT_CODE : 0 (0x0) CHECKPOINT : 0x0 WAIT_HINT : 0x0"); var res = task.Execute(Context.Object); Assert.Equal(1, res); }
public void QueryRunningService() { Properties.Setup(i => i.Set("eventlog.status", ServiceStatus.Running, true)); RunProgramTask.Setup(i => i.GetOutput()).Returns(@"SERVICE_NAME: eventlog TYPE : 30 WIN32 STATE : 4 RUNNING (STOPPABLE, NOT_PAUSABLE, ACCEPTS_SHUTDOWN) WIN32_EXIT_CODE : 0 (0x0) SERVICE_EXIT_CODE : 0 (0x0) CHECKPOINT : 0x0 WAIT_HINT : 0x0 PID : 2928 FLAGS :"); _task.ExecuteVoid(Context.Object); Properties.VerifyAll(); }
protected override void DoExecute(IScriptExecutionEnvironment environment) { string regIisExePath = Path.Combine( environment.GetDotNetFWDir(dotNetVersion), "aspnet_regiis.exe"); string commandLine = String.Format( System.Globalization.CultureInfo.InvariantCulture, "-s {0}{1}", parentVirtualDirectoryName, virtualDirectoryName); RunProgramTask.Execute( environment, regIisExePath, commandLine, TimeSpan.FromSeconds(30)); }
protected override void DoExecute(ITaskContext context) { IRunProgramTask task = new RunProgramTask(NDoc3Path) .SetWorkingDir(WorkingDirectory); foreach (string assembly in AssembliesToDocument) { task.AddArgument("\"{0}\" ", assembly); } task.AddArgument("\"{0}\" ", "-OutputTarget=Web"); if (!string.IsNullOrEmpty(OutputDirectory)) { task.AddArgument("\"-OutputDirectory={0}\" ", OutputDirectory); } task.Execute(context); }
/// <summary> /// Abstract method defining the actual work for a task. /// </summary> /// <remarks>This method has to be implemented by the inheriting task.</remarks> /// <param name="environment">The script execution environment.</param> protected override void DoExecute(IScriptExecutionEnvironment environment) { StringBuilder argumentLineBuilder = new StringBuilder(); argumentLineBuilder.AppendFormat("\"{0}\" ", AssemblyToTest); argumentLineBuilder.AppendFormat("\"{0}\" ", "/nodots"); argumentLineBuilder.AppendFormat("\"{0}\" ", "/labels"); if (!string.IsNullOrEmpty(ExcludeCategories)) { argumentLineBuilder.AppendFormat("\"/exclude={0}\" ", ExcludeCategories); } RunProgramTask task = new RunProgramTask(NUnitPath, argumentLineBuilder.ToString(), new TimeSpan(0, 1, 0, 0)) { WorkingDirectory = WorkingDirectory, }; task.Execute(environment); }
private static string GenerateCoverageReport( ITaskContext context, string dotCoverExeFileName, string snapshotFileName, string reportType) { context.WriteInfo("Generating code coverage {0} report...", reportType); string buildDir = context.Properties[BuildProps.BuildDir]; string coverageReportFileName = Path.Combine(buildDir, "dotCover-results.{0}".Fmt(reportType.ToLowerInvariant())); IRunProgramTask runDotCovertask = new RunProgramTask(dotCoverExeFileName).AddArgument("report").AddArgument("/Source={0}", snapshotFileName).AddArgument("/Output={0}", coverageReportFileName).AddArgument("/ReportType={0}", reportType) //.AddArgument("/LogFile={0}", Path.Combine(buildDir, "dotCover-log.xml")) ; runDotCovertask.Execute(context); return(coverageReportFileName); }
public void CaptureOutput() { Action <string> onOutput = null, onError = null; _commandFactory.Setup(i => i.Create("gitversion", new List <string>(), null, "Debug")).Returns(_command.Object); _command.Setup(i => i.CaptureStdErr()).Returns(_command.Object); _command.Setup(i => i.CaptureStdOut()).Returns(_command.Object); _command.Setup(i => i.WorkingDirectory(It.IsAny <string>())).Returns(_command.Object); _command.Setup(i => i.OnErrorLine(It.IsAny <Action <string> >())).Returns(_command.Object); _command.Setup(i => i.OnOutputLine(It.IsAny <Action <string> >())).Returns(_command.Object); _command.Setup(i => i.Execute()).Returns(new CommandResult(new ProcessStartInfo { Arguments = "aa" }, 0, string.Empty, string.Empty)); _command.Setup(i => i.OnOutputLine(It.IsAny <Action <string> >())) .Callback <Action <string> >(action => onOutput = action) .Returns(_command.Object); _command.Setup(i => i.OnErrorLine(It.IsAny <Action <string> >())) .Callback <Action <string> >(action => onError = action) .Returns(_command.Object); var task = new RunProgramTask(_commandFactory.Object, "gitversion"); int res = task.CaptureOutput() .CaptureErrorOutput() .DoNotLogOutput() .Execute(Context); onOutput?.Invoke("output line 1"); onOutput?.Invoke("output line 2"); onError?.Invoke("error line 1"); onError?.Invoke("error line 2"); string output = task.GetOutput()?.Replace("\r", string.Empty)?.Replace("\n", string.Empty); string outputError = task.GetErrorOutput()?.Replace("\r", string.Empty)?.Replace("\n", string.Empty); Assert.Equal(0, res); Assert.Equal("output line 1output line 2", output); Assert.Equal("error line 1error line 2", outputError); }
protected override void DoExecute(ITaskContext context) { if (NuGetCmdLineExePath == null) { Version nuGetCmdLineVersion = FindNuGetCmdLineExePath(); if (NuGetCmdLineExePath == null) { context.Fail( "Could not find NuGet.CommandLine package in the {0} directory. You have to download it yourself.", PackagesDirName); return; } if (nuGetCmdLineVersion < new Version("3.4.3")) { context.Fail( "This version of Flubu NuGet task work with NuGet 3.4.3 or later, but you have an older version {0}. Please download the newer version yourself.", nuGetCmdLineVersion); return; } } RunProgramTask runProgramTask = new RunProgramTask(NuGetCmdLineExePath); if (workingDirectory != null) { runProgramTask.SetWorkingDir(workingDirectory); } runProgramTask.EncloseParametersInQuotes(false); runProgramTask.AddArgument(command); foreach (string arg in args) { runProgramTask.AddArgument(arg); } runProgramTask.Execute(context); exitCode = runProgramTask.LastExitCode; }
/// <summary> /// Abstract method defining the actual work for a task. /// </summary> /// <remarks>This method has to be implemented by the inheriting task.</remarks> /// <param name="environment">The script execution environment.</param> protected override void DoExecute(IScriptExecutionEnvironment environment) { StringBuilder argumentLineBuilder = new StringBuilder(); argumentLineBuilder.AppendFormat("\"{0}\" ", AssemblyToTest); argumentLineBuilder.AppendFormat("\"{0}\" ", "/verbosity:debug"); argumentLineBuilder.AppendFormat("\"{0}\" ", "/rt:Html"); argumentLineBuilder.AppendFormat("\"{0}\" ", "/rt:Xml"); argumentLineBuilder.Append("\"/rnf:LastTestResults\" "); argumentLineBuilder.AppendFormat("\"/rd:{0}\" ", ReportDirectory); string filter = null; if (!string.IsNullOrEmpty(FixtureToRun)) { filter = "ExactType: " + FixtureToRun; } if (!string.IsNullOrEmpty(TestToRun)) { if (!string.IsNullOrEmpty(filter)) { filter += " and "; } filter += "Member: " + TestToRun; } if (!string.IsNullOrEmpty(filter)) { argumentLineBuilder.AppendFormat("\"/f:{0}\" ", filter); } RunProgramTask task = new RunProgramTask(GallioEchoPath, argumentLineBuilder.ToString(), new TimeSpan(0, 1, 0, 0)) { WorkingDirectory = WorkingDirectory, FailOnError = false, }; task.Execute(environment); }
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); }
public void ResolveExecutableWithDefaultWorkingFolder() { string currentFolder = Directory.GetCurrentDirectory(); string file = Directory.EnumerateFiles(currentFolder).FirstOrDefault(); string command = Path.GetFileName(file); _commandFactory.Setup(i => i.Create(file, new List <string>(), null, "Debug")).Returns(_command.Object); _command.Setup(i => i.CaptureStdErr()).Returns(_command.Object); _command.Setup(i => i.CaptureStdOut()).Returns(_command.Object); _command.Setup(i => i.WorkingDirectory(currentFolder)).Returns(_command.Object); _command.Setup(i => i.OnErrorLine(It.IsAny <Action <string> >())).Returns(_command.Object); _command.Setup(i => i.OnOutputLine(It.IsAny <Action <string> >())).Returns(_command.Object); _command.Setup(i => i.Execute()).Returns(new CommandResult(new ProcessStartInfo { Arguments = "aa" }, 0, string.Empty, string.Empty)); RunProgramTask task = new RunProgramTask(_commandFactory.Object, command); task .ExecuteVoid(Context); }
/// <summary> /// Abstract method defining the actual work for a task. /// </summary> /// <remarks>This method has to be implemented by the inheriting task.</remarks> /// <param name="environment">The script execution environment.</param> protected override void DoExecute(IScriptExecutionEnvironment environment) { StringBuilder argumentLineBuilder = new StringBuilder(); foreach (string assembly in AssembliesToDocument) { argumentLineBuilder.AppendFormat("\"{0}\" ", assembly); } argumentLineBuilder.AppendFormat("\"{0}\" ", "-OutputTarget=Web"); if (!string.IsNullOrEmpty(OutputDirectory)) { argumentLineBuilder.AppendFormat("\"-OutputDirectory={0}\" ", OutputDirectory); } RunProgramTask task = new RunProgramTask(NDoc3Path, argumentLineBuilder.ToString(), new TimeSpan(0, 1, 0, 0)) { WorkingDirectory = WorkingDirectory, }; task.Execute(environment); }
private static void TargetNuGet(ITaskContext context, string nugetId) { FullPath packagesDir = new FullPath(context.Properties.Get(BuildProps.ProductRootDir, ".")); packagesDir = packagesDir.CombineWith(context.Properties.Get<string>(BuildProps.BuildDir)); string sourceNuspecFile = string.Format( CultureInfo.InvariantCulture, @"{0}\{0}.nuspec", nugetId); FileFullPath destNuspecFile = packagesDir.AddFileName("{0}.nuspec", nugetId); context.WriteInfo("Preparing the {0} file", destNuspecFile); ExpandPropertiesTask task = new ExpandPropertiesTask( sourceNuspecFile, destNuspecFile.ToString(), Encoding.UTF8, Encoding.UTF8); task.AddPropertyToExpand("version", context.Properties.Get<Version>(BuildProps.BuildVersion).ToString()); task.Execute(context); // package it context.WriteInfo("Creating a NuGet package file"); RunProgramTask progTask = new RunProgramTask(@"lib\NuGet\NuGet.exe"); progTask.SetWorkingDir(destNuspecFile.Directory.ToString()); progTask .AddArgument("pack") .AddArgument(destNuspecFile.FileName) .AddArgument("-Verbose") .Execute(context); string nupkgFileName = string.Format( CultureInfo.InvariantCulture, "{0}.{1}.nupkg", nugetId, context.Properties.Get<Version>(BuildProps.BuildVersion)); context.WriteInfo("NuGet package file {0} created", nupkgFileName); string apiKeyFileName = "NuGet API key.txt"; if (!File.Exists(apiKeyFileName)) { context.WriteInfo("'NuGet API key.txt' does not exist, cannot publish the package."); return; } string apiKey = File.ReadAllText(apiKeyFileName); // publish the package file context.WriteInfo("Pushing the NuGet package to the repository"); progTask = new RunProgramTask(@"lib\NuGet\NuGet.exe"); progTask.SetWorkingDir(destNuspecFile.Directory.ToString()); progTask .AddArgument("push") .AddArgument(nupkgFileName) .AddArgument(apiKey) .AddArgument("-Source") .AddArgument("http://packages.nuget.org/v1/") .Execute(context); }