private void InitializeNuget()
{
View nugetView = _sheet.View.nuget;
_nuget = nugetView;
if (!nugetView.HasChildren ) {
FailAlways(Event<SourceError>.Raise("AP100", _sheet.CurrentView.SourceLocations, "script does not contain a declaration for a NuGet package"));
}
_nuspec = _nuget.nuspec;
if(!_nuspec.HasChildren) {
FailAlways(Event<SourceError>.Raise("AP102", nugetView.SourceLocations, "script does not contain a 'nuspec' declaration in 'nuget'"));
}
var outputs = nugetView.GetMetadataItems("output-packages.");
if (!outputs.Any()) {
FailAlways(Event<SourceError>.Raise("AP101", nugetView.SourceLocations, "script does not contain '#output-packages' declaration in 'nuget'"));
}
if(string.IsNullOrEmpty(_nuspec.id.Value)) {
FailAlways(Event<SourceError>.Raise("AP103", _nuspec.SourceLocations, "script does not contain a 'id' declaration in 'nuspec'"));
}
foreach (var each in outputs.Keys) {
_nugetPackages.Add(each, new NugetPackage(this, each, outputs[each]));
}
// initialize the nuget packages
nugetView.AddChildRoutes(_nugetPackages.Values.SelectMany(each => each.Initialize()));
// do the property sheet mapping
var conditions = new XDictionary<string, string>();
// map the file routes
nugetView.AddChildRoute("files".MapTo(new object() , new [] {
"condition".MapTo(conditions, key => Pivots.GetExpressionFilepath(_nuspec.id, key)),
"*".MapTo(conditions, key => Pivots.GetExpressionFilepath(_nuspec.id, key))
}));
var nuspecid = _nuspec.id;
var conditionFolderMacroHander = (GetMacroValueDelegate)((macro, context) => {
if (macro == "conditionFolder") {
return LinqExtensions.SingleItemAsEnumerable(Pivots.GetExpressionFilepath(nuspecid, ((View)context).GetSingleMacroValue("ElementId")??""));
}
return null;
});
_nuget.props.AddMacroHandler(conditionFolderMacroHander);
_nuget.targets.AddMacroHandler(conditionFolderMacroHander);
nugetView.AddChildRoute("props".MapTo(() => GetPropsProject("default") /*, GetPropsProject("default").ProjectRoutes() */));
// always need a targets
nugetView.AddChildRoute("targets".MapTo(() => GetTargetsProject("default")/*, GetTargetsProject("default").ProjectRoutes() */));
// other variants/frameworks
nugetView.AddChildRoute(
"condition".MapTo(_nugetPackages, key => NormalizeOuptutKey(key), new[] {
"targets".MapTo<NugetPackage>(package => GetTargetsProject(package.PkgRole)),
"props".MapTo<NugetPackage>(package => GetPropsProject(package.PkgRole))
}));
nugetView.AddChildRoute(
"*".MapTo(_nugetPackages, key => NormalizeOuptutKey(key),new [] {
"targets".MapTo<NugetPackage>(package => GetTargetsProject(package.PkgRole)),
"props".MapTo<NugetPackage>(package => GetPropsProject(package.PkgRole))}));
}