Skip to content
This repository has been archived by the owner on Dec 18, 2017. It is now read-only.

Commit

Permalink
Fix #887, Add prebuild.perconfiguration and prebuild.perframework
Browse files Browse the repository at this point in the history
… scripts

- provide `%project:Configuration%` and `%project:TargetFramework%` to scripts
  • Loading branch information
dougbu committed Dec 1, 2014
1 parent 8dd74a3 commit 673fbbe
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions src/Microsoft.Framework.PackageManager/Building/BuildManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public class BuildManager
private readonly IAssemblyLoaderContainer _loaderContainer;
private readonly IApplicationEnvironment _applicationEnvironment;
private readonly BuildOptions _buildOptions;
private string _configuration;
private string _targetFramework;

public BuildManager(IServiceProvider hostServices, BuildOptions buildOptions)
{
Expand Down Expand Up @@ -99,6 +101,9 @@ public bool Build()
// Build all specified configurations
foreach (var configuration in configurations)
{
_configuration = configuration;
ScriptExecutor.Execute(project, _buildOptions.Reports, "prebuild.perconfiguration", GetScriptVariable);

// Create a new builder per configuration
var packageBuilder = new PackageBuilder();
var symbolPackageBuilder = new PackageBuilder();
Expand All @@ -113,9 +118,13 @@ public bool Build()
// Build all target frameworks a project supports
foreach (var targetFramework in frameworks)
{
_targetFramework = targetFramework.ToString();

_buildOptions.Reports.Information.WriteLine();
_buildOptions.Reports.Information.WriteLine("Building {0} for {1}",
project.Name, targetFramework.ToString().Yellow().Bold());
project.Name, _targetFramework.Yellow().Bold());

ScriptExecutor.Execute(project, _buildOptions.Reports, "prebuild.perframework", GetScriptVariable);

var errors = new List<string>();
var warnings = new List<string>();
Expand Down Expand Up @@ -144,6 +153,8 @@ public bool Build()
allWarnings.AddRange(warnings);

WriteDiagnostics(warnings, errors);

_targetFramework = null;
}

success = success && configurationSuccess;
Expand Down Expand Up @@ -191,6 +202,7 @@ public bool Build()
}
}

_configuration = null;
ScriptExecutor.Execute(project, _buildOptions.Reports, "postbuild", GetScriptVariable);

sw.Stop();
Expand Down Expand Up @@ -219,12 +231,17 @@ private bool ValidateFrameworks(HashSet<FrameworkName> projectFrameworks, IDicti

private string GetScriptVariable(string key)
{
if (string.Equals("project:BuildOutputDir", key, StringComparison.OrdinalIgnoreCase))
var variables = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
{
return GetBuildOutputDir(_buildOptions);
}
{ "project:BuildOutputDir", GetBuildOutputDir(_buildOptions) },
{ "project:Configuration", _configuration },
{ "project:TargetFramework", _targetFramework },
};

string variable;
variables.TryGetValue(key, out variable);

return null;
return variable;
}

private static void InitializeBuilder(Runtime.Project project, PackageBuilder builder)
Expand Down

0 comments on commit 673fbbe

Please sign in to comment.