Skip to content

Commit

Permalink
Get rid of MSBuild engine. Just using cmd-line is much better
Browse files Browse the repository at this point in the history
  • Loading branch information
yevhen committed Aug 20, 2014
1 parent 5980c03 commit 293b6d4
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 178 deletions.
11 changes: 7 additions & 4 deletions Nake.csx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Nake;
using Nake.FS;
using Nake.Log;
using Nake.Env;
using Nake.Run;

using System.IO;
Expand All @@ -14,6 +15,8 @@ using System.Diagnostics;
const string RootPath = "$NakeScriptDirectory$";
const string OutputPath = RootPath + @"\Output";

var MSBuildExe = @"$ProgramFiles(x86)$\MSBuild\12.0\Bin\MSBuild.exe";

/// Builds sources in debug mode
[Task] void Default()
{
Expand All @@ -32,8 +35,8 @@ const string OutputPath = RootPath + @"\Output";
{
Clean(outDir);

MSBuild("Nake.sln",
"Configuration={config};OutDir={outDir};ReferencePath={outDir}");
Exec(MSBuildExe,
"Nake.sln /p:Configuration={config};OutDir={outDir};ReferencePath={outDir} /m");
}

/// Runs unit tests
Expand Down Expand Up @@ -64,8 +67,8 @@ const string OutputPath = RootPath + @"\Output";
@"Packages\Nake.{version}\tools\net45\Nake.exe %*"
);

MSBuild(@"Source\Utility\Utility.shfbproj",
"OutputPath={releasePath};SourcePath={releasePath}");
Exec(MSBuildExe,
@"Source\Utility\Utility.shfbproj /p:OutputPath={releasePath};SourcePath={releasePath}");

Cmd(@"Tools\Nuget.exe pack Build\NuGet\Nake.nuspec -Version {version} " +
"-OutputDirectory {packagePath} -BasePath {RootPath} -NoPackageAnalysis");
Expand Down
4 changes: 2 additions & 2 deletions Source/ProductAssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Reflection;

[assembly: AssemblyVersion("2.0.20.0")]
[assembly: AssemblyInformationalVersion("2.0.20")]
[assembly: AssemblyVersion("2.1.0.0")]
[assembly: AssemblyInformationalVersion("2.1.0")]
[assembly: AssemblyCopyright("Copyright © Yevhen Bobrov 2013-2014")]
75 changes: 0 additions & 75 deletions Source/Utility/MSBuild.Tool.cs

This file was deleted.

122 changes: 27 additions & 95 deletions Source/Utility/Run.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

using Microsoft.Build.Tasks;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;

namespace Nake
Expand Down Expand Up @@ -52,66 +51,37 @@ public static int Cmd(
}

/// <summary>
/// Runs MSBuild tool
/// Executes the specified file with given argument string.
/// </summary>
/// <param name="solutionOrSingleProject">The solution or single project.</param>
/// <param name="properties">The properties to pass.</param>
/// <param name="targets">The targets to execute.</param>
/// <param name="buildInParallel">if set to <c>true</c> will build projects in parallel.</param>
/// <param name="maxDegreeOfParallelism">The maximum degree of parallelism.</param>
/// <param name="toolsVersion">The tools version.</param>
/// <param name="verbosity">The log verbosity.</param>
public static void MSBuild(
string solutionOrSingleProject,
string properties = null,
string targets = null,
bool buildInParallel = true,
int? maxDegreeOfParallelism = null,
string toolsVersion = "4.0",
MSBuildVerbosity verbosity = null)
/// <param name="fileName">Name of the executable file.</param>
/// <param name="arguments">The arguments.</param>
/// <param name="workingDirectory">The working directory. Default is current directory</param>
/// <param name="ignoreExitCode">if set to <c>true</c> ignores exit code</param>
/// <returns> Exit code </returns>
public static int Exec(
string fileName,
string arguments,
string workingDirectory = null,
bool ignoreExitCode = false)
{
MSBuild(new FileSet {solutionOrSingleProject},
properties, targets,
buildInParallel, maxDegreeOfParallelism,
toolsVersion, verbosity);
}
var info = new ProcessStartInfo(fileName, arguments)
{
WorkingDirectory = workingDirectory ?? Location.CurrentDirectory(),
UseShellExecute = false,
};

/// <summary>
/// Runs MSBuild tool
/// </summary>
/// <param name="projects">The set of projects.</param>
/// <param name="properties">The properties to pass.</param>
/// <param name="targets">The targets to execute.</param>
/// <param name="buildInParallel">if set to <c>true</c> will build projects in parallel.</param>
/// <param name="maxDegreeOfParallelism">The maximum degree of parallelism.</param>
/// <param name="toolsVersion">The tools version.</param>
/// <param name="verbosity">The log verbosity.</param>
public static void MSBuild(
FileSet projects,
string properties = null,
string targets = null,
bool buildInParallel = true,
int? maxDegreeOfParallelism = null,
string toolsVersion = "4.0",
MSBuildVerbosity verbosity = null)
{
MSBuildTool.Build(projects,
SplitProperties(properties ?? ""), SplitTargets(targets ?? ""),
buildInParallel, maxDegreeOfParallelism ?? Environment.ProcessorCount,
toolsVersion, verbosity != null ? verbosity.Level : LoggerVerbosity.Normal);
}
using (var process = new Process())
{
process.StartInfo = info;

process.Start();
process.WaitForExit();

static Dictionary<string, string> SplitProperties(string properties)
{
return properties
.Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries)
.Select(x => new { key = x.Split('=')[0], value = x.Split('=')[1] })
.ToDictionary(x => x.key, x => x.value);
}
if (process.ExitCode != 0 && !ignoreExitCode)
throw new ApplicationException(string.Format("Process exited with code {0}", process.ExitCode));

static string[] SplitTargets(string targets)
{
return targets.Split(new[]{';'}, StringSplitOptions.RemoveEmptyEntries);
return process.ExitCode;
}
}

/// <summary>
Expand All @@ -136,42 +106,4 @@ public static TTask MSBuild<TTask>(
return task;
}
}

/// <summary>
/// The MSBuild logger verbosity
/// </summary>
public class MSBuildVerbosity
{
internal readonly LoggerVerbosity Level;

/// <summary>
/// Detailed verbosity, which displays errors, warnings, messages with high or normal importance, all status events, and a build summary.
/// </summary>
public static readonly MSBuildVerbosity Detailed = new MSBuildVerbosity(LoggerVerbosity.Detailed);

/// <summary>
/// Diagnostic verbosity, which displays all errors, warnings, messages, status events, and a build summary.
/// </summary>
public static readonly MSBuildVerbosity Diagnostic = new MSBuildVerbosity(LoggerVerbosity.Diagnostic);

/// <summary>
/// Minimal verbosity, which displays errors, warnings, messages with high importance, and a build summary.
/// </summary>
public static readonly MSBuildVerbosity Minimal = new MSBuildVerbosity(LoggerVerbosity.Minimal);

/// <summary>
/// Normal verbosity, which displays errors, warnings, messages with high importance, some status events, and a build summary.
/// </summary>
public static readonly MSBuildVerbosity Normal = new MSBuildVerbosity(LoggerVerbosity.Normal);

/// <summary>
/// Quiet verbosity, which displays a build summary.
/// </summary>
public static readonly MSBuildVerbosity Quiet = new MSBuildVerbosity(LoggerVerbosity.Quiet);

MSBuildVerbosity(LoggerVerbosity level)
{
Level = level;
}
}
}
2 changes: 0 additions & 2 deletions Source/Utility/Utility.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
<Reference Include="GlobDir">
<HintPath>..\..\packages\globdir.0.0.1.1\lib\net40\GlobDir.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Build" />
<Reference Include="Microsoft.Build.Engine" />
<Reference Include="Microsoft.Build.Framework" />
<Reference Include="Microsoft.Build.Tasks.v4.0" />
Expand Down Expand Up @@ -69,7 +68,6 @@
<Compile Include="Location.cs" />
<Compile Include="MSBuild.EngineStub.cs" />
<Compile Include="MSBuild.Extensions.cs" />
<Compile Include="MSBuild.Tool.cs" />
<Compile Include="Log.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Run.cs" />
Expand Down
Binary file modified Tools/Nake/Meta.dll
Binary file not shown.
Binary file modified Tools/Nake/Meta.pdb
Binary file not shown.
Binary file modified Tools/Nake/Nake.exe
Binary file not shown.
Binary file modified Tools/Nake/Nake.pdb
Binary file not shown.
Binary file modified Tools/Nake/Utility.dll
Binary file not shown.
Binary file modified Tools/Nake/Utility.pdb
Binary file not shown.

0 comments on commit 293b6d4

Please sign in to comment.