From 81ab174765a5117462d551686c2e5bbd9c4c4b88 Mon Sep 17 00:00:00 2001 From: ravensorb Date: Sat, 6 Jun 2015 16:10:22 -0400 Subject: [PATCH 1/5] Updated to latest version of Nancy Added workaround for when using with Nancy and custom DI container (issue related to multiple instances of ISerializer registered) Updated build script to restore Nuget packages --- .nuget/NuGet.Config | 6 + .nuget/NuGet.targets | 144 ++++++++ .nuget/packages.config | 4 +- .../Nancy.CustomErrors.Example.csproj | 4 +- .../Properties/AssemblyInfo.cs | 6 +- Nancy.CustomErrors.Example/packages.config | 4 +- .../Nancy.CustomErrors.Tests.csproj | 29 +- .../Properties/AssemblyInfo.cs | 6 +- Nancy.CustomErrors.Tests/packages.config | 12 +- Nancy.CustomErrors/CustomErrors.cs | 5 +- Nancy.CustomErrors/ErrorStatusCodeHandler.cs | 323 +++++++++--------- Nancy.CustomErrors/Nancy.CustomErrors.csproj | 19 +- Nancy.CustomErrors/Properties/AssemblyInfo.cs | 6 +- Nancy.CustomErrors/packages.config | 2 +- build.ps1 | 3 +- default.ps1 | 21 +- version.json | 2 +- 17 files changed, 389 insertions(+), 207 deletions(-) create mode 100644 .nuget/NuGet.Config create mode 100644 .nuget/NuGet.targets diff --git a/.nuget/NuGet.Config b/.nuget/NuGet.Config new file mode 100644 index 0000000..67f8ea0 --- /dev/null +++ b/.nuget/NuGet.Config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.nuget/NuGet.targets b/.nuget/NuGet.targets new file mode 100644 index 0000000..3f8c37b --- /dev/null +++ b/.nuget/NuGet.targets @@ -0,0 +1,144 @@ + + + + $(MSBuildProjectDirectory)\..\ + + + false + + + false + + + true + + + false + + + + + + + + + + + $([System.IO.Path]::Combine($(SolutionDir), ".nuget")) + + + + + $(SolutionDir).nuget + + + + $(MSBuildProjectDirectory)\packages.$(MSBuildProjectName.Replace(' ', '_')).config + $(MSBuildProjectDirectory)\packages.$(MSBuildProjectName).config + + + + $(MSBuildProjectDirectory)\packages.config + $(PackagesProjectConfig) + + + + + $(NuGetToolsPath)\NuGet.exe + @(PackageSource) + + "$(NuGetExePath)" + mono --runtime=v4.0.30319 "$(NuGetExePath)" + + $(TargetDir.Trim('\\')) + + -RequireConsent + -NonInteractive + + "$(SolutionDir) " + "$(SolutionDir)" + + + $(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" $(NonInteractiveSwitch) $(RequireConsentSwitch) -solutionDir $(PaddedSolutionDir) + $(NuGetCommand) pack "$(ProjectPath)" -Properties "Configuration=$(Configuration);Platform=$(Platform)" $(NonInteractiveSwitch) -OutputDirectory "$(PackageOutputDir)" -symbols + + + + RestorePackages; + $(BuildDependsOn); + + + + + $(BuildDependsOn); + BuildPackage; + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.nuget/packages.config b/.nuget/packages.config index 6bc0ed0..d1244b9 100644 --- a/.nuget/packages.config +++ b/.nuget/packages.config @@ -1,5 +1,5 @@  - - + + \ No newline at end of file diff --git a/Nancy.CustomErrors.Example/Nancy.CustomErrors.Example.csproj b/Nancy.CustomErrors.Example/Nancy.CustomErrors.Example.csproj index 0924407..43c47b2 100755 --- a/Nancy.CustomErrors.Example/Nancy.CustomErrors.Example.csproj +++ b/Nancy.CustomErrors.Example/Nancy.CustomErrors.Example.csproj @@ -33,10 +33,10 @@ - ..\packages\Nancy.0.23.0\lib\net40\Nancy.dll + ..\packages\Nancy.1.2.0\lib\net40\Nancy.dll - ..\packages\Nancy.Hosting.Self.0.23.0\lib\net40\Nancy.Hosting.Self.dll + ..\packages\Nancy.Hosting.Self.1.2.0\lib\net40\Nancy.Hosting.Self.dll diff --git a/Nancy.CustomErrors.Example/Properties/AssemblyInfo.cs b/Nancy.CustomErrors.Example/Properties/AssemblyInfo.cs index d6f74e9..37ba328 100755 --- a/Nancy.CustomErrors.Example/Properties/AssemblyInfo.cs +++ b/Nancy.CustomErrors.Example/Properties/AssemblyInfo.cs @@ -31,6 +31,6 @@ // // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: -// [assembly: AssemblyVersion("1.1.1")] -[assembly: AssemblyVersion("1.1.1")] -[assembly: AssemblyFileVersion("1.1.1")] +// [assembly: AssemblyVersion("1.2.1")] +[assembly: AssemblyVersion("1.2.1")] +[assembly: AssemblyFileVersion("1.2.1")] diff --git a/Nancy.CustomErrors.Example/packages.config b/Nancy.CustomErrors.Example/packages.config index 152fbff..88f0cd4 100755 --- a/Nancy.CustomErrors.Example/packages.config +++ b/Nancy.CustomErrors.Example/packages.config @@ -1,5 +1,5 @@  - - + + \ No newline at end of file diff --git a/Nancy.CustomErrors.Tests/Nancy.CustomErrors.Tests.csproj b/Nancy.CustomErrors.Tests/Nancy.CustomErrors.Tests.csproj index 8957f70..c9f6025 100644 --- a/Nancy.CustomErrors.Tests/Nancy.CustomErrors.Tests.csproj +++ b/Nancy.CustomErrors.Tests/Nancy.CustomErrors.Tests.csproj @@ -1,5 +1,6 @@  + Debug @@ -9,8 +10,10 @@ Properties Nancy.CustomErrors.Tests Nancy.CustomErrors.Tests - v4.0 + v4.5 512 + + b4ddc62d true @@ -20,6 +23,7 @@ DEBUG;TRACE prompt 4 + false pdbonly @@ -28,19 +32,20 @@ TRACE prompt 4 + false ..\packages\CsQuery.1.3.4\lib\net40\CsQuery.dll - ..\packages\Nancy.0.23.0\lib\net40\Nancy.dll + ..\packages\Nancy.1.2.0\lib\net40\Nancy.dll - ..\packages\Nancy.Testing.0.23.0\lib\net40\Nancy.Testing.dll + ..\packages\Nancy.Testing.1.2.0\lib\net40\Nancy.Testing.dll - ..\packages\NSubstitute.1.7.2.0\lib\NET40\NSubstitute.dll + ..\packages\NSubstitute.1.8.2.0\lib\net40\NSubstitute.dll @@ -49,8 +54,14 @@ - - ..\packages\xunit.1.9.2\lib\net20\xunit.dll + + ..\packages\xunit.abstractions.2.0.0\lib\net35\xunit.abstractions.dll + + + ..\packages\xunit.assert.2.0.0\lib\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.assert.dll + + + ..\packages\xunit.extensibility.core.2.0.0\lib\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.dll @@ -76,6 +87,12 @@ + + + This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + + \ No newline at end of file diff --git a/Nancy.CustomErrors/CustomErrors.cs b/src/Nancy.CustomErrors.Shared/CustomErrors.cs similarity index 86% rename from Nancy.CustomErrors/CustomErrors.cs rename to src/Nancy.CustomErrors.Shared/CustomErrors.cs index 9a79e76..4601403 100644 --- a/Nancy.CustomErrors/CustomErrors.cs +++ b/src/Nancy.CustomErrors.Shared/CustomErrors.cs @@ -12,11 +12,6 @@ public static CustomErrorsConfiguration Configuration get { return _configuration ?? (_configuration = new CustomErrorsConfiguration()); } } - public static void Enable(IPipelines pipelines, CustomErrorsConfiguration configuration) - { - Enable(pipelines, configuration, new DefaultJsonSerializer()); - } - public static void Enable(IPipelines pipelines, CustomErrorsConfiguration configuration, ISerializer serializer) { if (pipelines == null) diff --git a/Nancy.CustomErrors/CustomErrorsConfiguration.cs b/src/Nancy.CustomErrors.Shared/CustomErrorsConfiguration.cs similarity index 93% rename from Nancy.CustomErrors/CustomErrorsConfiguration.cs rename to src/Nancy.CustomErrors.Shared/CustomErrorsConfiguration.cs index e101bec..6835276 100644 --- a/Nancy.CustomErrors/CustomErrorsConfiguration.cs +++ b/src/Nancy.CustomErrors.Shared/CustomErrorsConfiguration.cs @@ -39,7 +39,7 @@ public virtual ErrorResponse HandleError(NancyContext context, Exception ex, ISe Message = ex.Message }; - return new ErrorResponse(error, serializer).WithStatusCode(HttpStatusCode.InternalServerError) as ErrorResponse; + return new ErrorResponse(error, serializer, context.Environment).WithStatusCode(HttpStatusCode.InternalServerError) as ErrorResponse; } /// diff --git a/Nancy.CustomErrors/Error.cs b/src/Nancy.CustomErrors.Shared/Error.cs similarity index 100% rename from Nancy.CustomErrors/Error.cs rename to src/Nancy.CustomErrors.Shared/Error.cs diff --git a/Nancy.CustomErrors/ErrorResponse.cs b/src/Nancy.CustomErrors.Shared/ErrorResponse.cs similarity index 78% rename from Nancy.CustomErrors/ErrorResponse.cs rename to src/Nancy.CustomErrors.Shared/ErrorResponse.cs index 1ce1315..01f6bbc 100644 --- a/Nancy.CustomErrors/ErrorResponse.cs +++ b/src/Nancy.CustomErrors.Shared/ErrorResponse.cs @@ -1,4 +1,5 @@ -using Nancy.Responses; +using Nancy.Configuration; +using Nancy.Responses; namespace Nancy.CustomErrors { @@ -7,8 +8,7 @@ public class ErrorResponse : JsonResponse private readonly Error _error; public string ErrorMessage { get { return _error.Message; } } public string FullException { get { return _error.FullException; } } - public ErrorResponse(Error error) : this(error, new DefaultJsonSerializer()) { } - public ErrorResponse(Error error, ISerializer serializer) : base(error, serializer) + public ErrorResponse(Error error, ISerializer serializer, INancyEnvironment environment) : base(error, serializer, environment) { if (!CustomErrors.Configuration.Debug) { diff --git a/Nancy.CustomErrors/ErrorStatusCodeHandler.cs b/src/Nancy.CustomErrors.Shared/ErrorStatusCodeHandler.cs similarity index 86% rename from Nancy.CustomErrors/ErrorStatusCodeHandler.cs rename to src/Nancy.CustomErrors.Shared/ErrorStatusCodeHandler.cs index 1d5d8ea..0c14aa2 100644 --- a/Nancy.CustomErrors/ErrorStatusCodeHandler.cs +++ b/src/Nancy.CustomErrors.Shared/ErrorStatusCodeHandler.cs @@ -12,8 +12,7 @@ public class ErrorStatusCodeHandler : DefaultViewRenderer, IStatusCodeHandler { private readonly ISerializer _serializer; - public ErrorStatusCodeHandler(IViewFactory viewFactory) - : this(viewFactory, new DefaultJsonSerializer()) + public ErrorStatusCodeHandler(IViewFactory viewFactory) : base(viewFactory) { } @@ -71,12 +70,12 @@ public void Handle(HttpStatusCode statusCode, NancyContext context) context.Response = new ErrorResponse(new Error { Message = CustomErrors.Configuration.NotFoundSummary - }); + }, _serializer, context.Environment); break; } } - context.Response = new ErrorResponse(err, _serializer).WithHeaders(headers).WithStatusCode(statusCode); + context.Response = new ErrorResponse(err, _serializer, context.Environment).WithHeaders(headers).WithStatusCode(statusCode); return; } @@ -144,27 +143,10 @@ private static bool ShouldRenderFriendlyErrorPage(NancyContext context) return false; } - var ranges = - context.Request.Headers.Accept.OrderByDescending(o => o.Item2) - .Select(o => MediaRange.FromString(o.Item1)) - .ToList(); - - foreach (var range in ranges) + if (context.Request.Headers.Accept.OrderByDescending(o => o.Item2) + .Any(o => o.Item1 == "application/json" || o.Item1 == "text/json")) { - if (range.Matches("application/json")) - { - return false; - } - - if (range.Matches("text/json")) - { - return false; - } - - if (range.Matches("text/html")) - { - return true; - } + return false; } return true; diff --git a/Nancy.CustomErrors/ErrorViewModel.cs b/src/Nancy.CustomErrors.Shared/ErrorViewModel.cs similarity index 100% rename from Nancy.CustomErrors/ErrorViewModel.cs rename to src/Nancy.CustomErrors.Shared/ErrorViewModel.cs diff --git a/Nancy.CustomErrors/ResponseFormatterExtensions.cs b/src/Nancy.CustomErrors.Shared/ResponseFormatterExtensions.cs similarity index 63% rename from Nancy.CustomErrors/ResponseFormatterExtensions.cs rename to src/Nancy.CustomErrors.Shared/ResponseFormatterExtensions.cs index c10a4c8..69740fe 100644 --- a/Nancy.CustomErrors/ResponseFormatterExtensions.cs +++ b/src/Nancy.CustomErrors.Shared/ResponseFormatterExtensions.cs @@ -1,4 +1,5 @@ using System.Linq; +using Nancy.Responses.Negotiation; namespace Nancy.CustomErrors { @@ -7,9 +8,9 @@ public static class ResponseFormatterExtensions public static Response AsError(this IResponseFormatter formatter, string message, HttpStatusCode statusCode = HttpStatusCode.InternalServerError) { - var serializer = formatter.Serializers.FirstOrDefault(s => s.CanSerialize("application/json")); + var serializer = formatter.SerializerFactory.GetSerializer(new MediaRange("application/json")); - return new ErrorResponse(new Error {Message = message}, serializer).WithStatusCode(statusCode); + return new ErrorResponse(new Error {Message = message}, serializer, formatter.Environment).WithStatusCode(statusCode); } } } \ No newline at end of file diff --git a/Nancy.CustomErrors/Nancy.CustomErrors.csproj b/src/Nancy.CustomErrors/Nancy.CustomErrors.csproj similarity index 78% rename from Nancy.CustomErrors/Nancy.CustomErrors.csproj rename to src/Nancy.CustomErrors/Nancy.CustomErrors.csproj index 4490b32..d8e0139 100644 --- a/Nancy.CustomErrors/Nancy.CustomErrors.csproj +++ b/src/Nancy.CustomErrors/Nancy.CustomErrors.csproj @@ -9,10 +9,10 @@ Properties Nancy.CustomErrors Nancy.CustomErrors - v4.5 + v4.6.1 512 - ..\..\..\..\Humanistory\TixSnap\source\ + ..\..\ true @@ -35,8 +35,8 @@ false - - ..\packages\Nancy.1.2.0\lib\net40\Nancy.dll + + ..\packages\Nancy.2.0.0-clinteastwood\lib\net452\Nancy.dll @@ -60,12 +60,7 @@ - - - This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - false - - - false - - - true - - - false - - - - - - - - - - - $([System.IO.Path]::Combine($(SolutionDir), ".nuget")) - - - - - $(SolutionDir).nuget - - - - $(MSBuildProjectDirectory)\packages.$(MSBuildProjectName.Replace(' ', '_')).config - $(MSBuildProjectDirectory)\packages.$(MSBuildProjectName).config - - - - $(MSBuildProjectDirectory)\packages.config - $(PackagesProjectConfig) - - - - - $(NuGetToolsPath)\NuGet.exe - @(PackageSource) - - "$(NuGetExePath)" - mono --runtime=v4.0.30319 "$(NuGetExePath)" - - $(TargetDir.Trim('\\')) - - -RequireConsent - -NonInteractive - - "$(SolutionDir) " - "$(SolutionDir)" - - - $(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" $(NonInteractiveSwitch) $(RequireConsentSwitch) -solutionDir $(PaddedSolutionDir) - $(NuGetCommand) pack "$(ProjectPath)" -Properties "Configuration=$(Configuration);Platform=$(Platform)" $(NonInteractiveSwitch) -OutputDirectory "$(PackageOutputDir)" -symbols - - - - RestorePackages; - $(BuildDependsOn); - - - - - $(BuildDependsOn); - BuildPackage; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/.nuget/packages.config b/.nuget/packages.config deleted file mode 100644 index d1244b9..0000000 --- a/.nuget/packages.config +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/Nancy.CustomErrors.sln b/Nancy.CustomErrors.sln index 1d8d98f..87163f5 100644 --- a/Nancy.CustomErrors.sln +++ b/Nancy.CustomErrors.sln @@ -1,9 +1,9 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2013 -VisualStudioVersion = 12.0.31101.0 +# Visual Studio 15 +VisualStudioVersion = 15.0.26430.6 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nancy.CustomErrors", "Nancy.CustomErrors\Nancy.CustomErrors.csproj", "{CD7A7211-6563-499B-913D-8E5AF649BFE7}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nancy.CustomErrors", "src\Nancy.CustomErrors\Nancy.CustomErrors.csproj", "{CD7A7211-6563-499B-913D-8E5AF649BFE7}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{56730B51-095D-4010-B942-DCB2696540C0}" ProjectSection(SolutionItems) = preProject @@ -13,16 +13,23 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution version.json = version.json EndProjectSection EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nancy.CustomErrors.Tests", "Nancy.CustomErrors.Tests\Nancy.CustomErrors.Tests.csproj", "{F1930050-9A83-42BB-9E14-1D5D7C6F255B}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nancy.CustomErrors.Tests", "tests\Nancy.CustomErrors.Tests\Nancy.CustomErrors.Tests.csproj", "{F1930050-9A83-42BB-9E14-1D5D7C6F255B}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nancy.CustomErrors.Example", "Nancy.CustomErrors.Example\Nancy.CustomErrors.Example.csproj", "{5A8E7514-E653-4C00-8623-1E71D7DCE6C5}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nancy.CustomErrors.Example", "tests\Nancy.CustomErrors.Example\Nancy.CustomErrors.Example.csproj", "{5A8E7514-E653-4C00-8623-1E71D7DCE6C5}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{1831399C-85E4-4E38-893C-F85DB092CB04}" - ProjectSection(SolutionItems) = preProject - .nuget\packages.config = .nuget\packages.config - EndProjectSection +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nancy.CustomErrors.NetStandard1.6", "src\Nancy.CustomErrors.NetStandard1.6\Nancy.CustomErrors.NetStandard1.6.csproj", "{BBFAEB4A-212F-4F00-AAE7-6723231C6969}" +EndProject +Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Nancy.CustomErrors.Shared", "src\Nancy.CustomErrors.Shared\Nancy.CustomErrors.Shared.shproj", "{0B0C2E66-9FD4-4475-AB31-81AB2F39F4DA}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "source", "source", "{ED70835A-FD7E-43C7-803D-84CD326DA186}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{9CDF45E1-7B40-4BA2-A537-1407CA214AD0}" EndProject Global + GlobalSection(SharedMSBuildProjectFiles) = preSolution + src\Nancy.CustomErrors.Shared\Nancy.CustomErrors.Shared.projitems*{0b0c2e66-9fd4-4475-ab31-81ab2f39f4da}*SharedItemsImports = 13 + src\Nancy.CustomErrors.Shared\Nancy.CustomErrors.Shared.projitems*{cd7a7211-6563-499b-913d-8e5af649bfe7}*SharedItemsImports = 4 + EndGlobalSection GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU @@ -40,8 +47,19 @@ Global {5A8E7514-E653-4C00-8623-1E71D7DCE6C5}.Debug|Any CPU.Build.0 = Debug|Any CPU {5A8E7514-E653-4C00-8623-1E71D7DCE6C5}.Release|Any CPU.ActiveCfg = Release|Any CPU {5A8E7514-E653-4C00-8623-1E71D7DCE6C5}.Release|Any CPU.Build.0 = Release|Any CPU + {BBFAEB4A-212F-4F00-AAE7-6723231C6969}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BBFAEB4A-212F-4F00-AAE7-6723231C6969}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BBFAEB4A-212F-4F00-AAE7-6723231C6969}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BBFAEB4A-212F-4F00-AAE7-6723231C6969}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {CD7A7211-6563-499B-913D-8E5AF649BFE7} = {ED70835A-FD7E-43C7-803D-84CD326DA186} + {F1930050-9A83-42BB-9E14-1D5D7C6F255B} = {9CDF45E1-7B40-4BA2-A537-1407CA214AD0} + {5A8E7514-E653-4C00-8623-1E71D7DCE6C5} = {9CDF45E1-7B40-4BA2-A537-1407CA214AD0} + {BBFAEB4A-212F-4F00-AAE7-6723231C6969} = {ED70835A-FD7E-43C7-803D-84CD326DA186} + {0B0C2E66-9FD4-4475-AB31-81AB2F39F4DA} = {ED70835A-FD7E-43C7-803D-84CD326DA186} + EndGlobalSection EndGlobal diff --git a/build.cake b/build.cake new file mode 100644 index 0000000..adf0adb --- /dev/null +++ b/build.cake @@ -0,0 +1,360 @@ +/////////////////////////////////////////////////////////////////////////////// +// Directives +/////////////////////////////////////////////////////////////////////////////// + +#l "tools/versionUtils.cake" +#l "tools/settingsUtils.cake" +#tool "nuget:?package=NUnit.ConsoleRunner" +#tool "nuget:?package=xunit.runner.console" + +/////////////////////////////////////////////////////////////////////////////// +// ARGUMENTS +/////////////////////////////////////////////////////////////////////////////// + +var settings = SettingsUtils.LoadSettings(Context); +var versionInfo = VersionUtils.LoadVersion(Context, settings); + +/////////////////////////////////////////////////////////////////////////////// +// GLOBAL VARIABLES +/////////////////////////////////////////////////////////////////////////////// + +var solutions = GetFiles(settings.Build.SolutionFilePath); +var solutionPaths = solutions.Select(solution => solution.GetDirectory()); + +/////////////////////////////////////////////////////////////////////////////// +// SETUP / TEARDOWN +/////////////////////////////////////////////////////////////////////////////// + +Setup((c) => +{ + // Executed BEFORE the first task. + settings.Display(c); + versionInfo.Display(c); +}); + +Teardown((c) => +{ + // Executed AFTER the last task. + Information("Finished running tasks."); +}); + +/////////////////////////////////////////////////////////////////////////////// +// TASK DEFINITIONS +/////////////////////////////////////////////////////////////////////////////// + +Task("CleanAll") + .Description("Cleans all directories that are used during the build process.") + .Does(() => +{ + // Clean solution directories. + foreach(var path in solutionPaths) + { + Information("Cleaning {0}", path); + CleanDirectories(path + "/**/bin"); + CleanDirectories(path + "/**/obj"); + CleanDirectories(path + "/packages/**/*"); + CleanDirectories(path + "/artifacts/**/*"); + CleanDirectories(path + "/packages"); + CleanDirectories(path + "/artifacts"); + } + + var pathTest = MakeAbsolute(Directory(settings.Test.SourcePath)).FullPath; + Information("Cleaning {0}", pathTest); + try { CleanDirectories(pathTest + "/**/bin"); } catch {} + try { CleanDirectories(pathTest + "/**/obj"); } catch {} +}); + +Task("Clean") + .Description("Cleans all directories that are used during the build process.") + .WithCriteria(settings.ExecuteBuild) + .Does(() => +{ + // Clean solution directories. + foreach(var path in solutionPaths) + { + Information("Cleaning {0}", path); + try { CleanDirectories(path + "/**/bin/" + settings.Configuration); } catch {} + try { CleanDirectories(path + "/**/obj/" + settings.Configuration); } catch {} + } + + var pathTest = MakeAbsolute(Directory(settings.Test.SourcePath)).FullPath; + Information("Cleaning {0}", pathTest); + try { CleanDirectories(pathTest + "/**/bin/" + settings.Configuration); } catch {} + try { CleanDirectories(pathTest + "/**/obj/" + settings.Configuration); } catch {} + +}); + +Task("CleanPackages") + .Description("Cleans all packages that are used during the build process.") + .Does(() => +{ + // Clean solution directories. + foreach(var path in solutionPaths) + { + Information("Cleaning {0}", path); + CleanDirectories(path + "/packages/**/*"); + CleanDirectories(path + "/packages"); + } +}); + +Task("Restore") + .Description("Restores all the NuGet packages that are used by the specified solution.") + .WithCriteria(settings.ExecuteBuild) + .Does(() => +{ + // Restore all NuGet packages. + foreach(var solution in solutions) + { + Information("Restoring {0}...", solution); + NuGetRestore(solution, new NuGetRestoreSettings { ConfigFile = settings.NuGet.NuGetConfig }); + } +}); + +Task("Build") + .Description("Builds all the different parts of the project.") + .WithCriteria(settings.ExecuteBuild) + .IsDependentOn("Clean") + .IsDependentOn("Restore") + .IsDependentOn("UpdateVersion") + .Does(() => +{ + if (settings.Version.AutoIncrementVersion) + { + RunTarget("IncrementVersion"); + } + + // Build all solutions. + foreach(var solution in solutions) + { + Information("Building {0}", solution); + try { + MSBuild(solution, s => + s.SetPlatformTarget(PlatformTarget.MSIL) + .SetMaxCpuCount(settings.Build.MaxCpuCount) + .WithProperty("TreatWarningsAsErrors",settings.Build.TreatWarningsAsErrors.ToString()) + .WithTarget("Build") + .SetConfiguration(settings.Configuration)); + } + catch (Exception ex) + { + Error("Files to build project: " + solution + ". Error: " + ex.Message); + } + } +}); + +Task("UnitTest") + .Description("Run unit tests for the solution.") + .WithCriteria(settings.ExecuteUnitTest) + .IsDependentOn("Build") + .Does(() => +{ + // Run all unit tests we can find. + + var assemplyFilePath = string.Format("{0}/**/bin/{1}/{2}", settings.Test.SourcePath, settings.Configuration, settings.Test.AssemblyFileSpec); + + Information("Unit Test Files: {0}", assemplyFilePath); + + var unitTestAssemblies = GetFiles(assemplyFilePath); + + foreach(var uta in unitTestAssemblies) + { + Information("Executing Tests for {0}", uta); + + switch (settings.Test.Framework) + { + case TestFrameworkTypes.NUnit2: + NUnit(uta.ToString(), new NUnitSettings { }); + break; + case TestFrameworkTypes.NUnit3: + NUnit3(uta.ToString(), new NUnit3Settings { Configuration=settings.Configuration }); + break; + case TestFrameworkTypes.XUnit: + XUnit(uta.ToString(), new XUnitSettings { OutputDirectory = settings.Test.ResultsPath }); + break; + case TestFrameworkTypes.XUnit2: + XUnit2(uta.ToString(), new XUnit2Settings { OutputDirectory = settings.Test.ResultsPath, XmlReportV1 = true }); + break; + } + } +}); + +Task("Package") + .Description("Packages all nuspec files into nupkg packages.") + .WithCriteria(settings.ExecutePackage) + .IsDependentOn("UnitTest") + .Does(() => +{ + var artifactsPath = Directory(settings.NuGet.ArtifactsPath); + var nugetProps = new Dictionary() { {"Configuration", settings.Configuration} }; + + CreateDirectory(artifactsPath); + + var nuspecFiles = GetFiles(settings.NuGet.NuSpecFileSpec); + foreach(var nsf in nuspecFiles) + { + Information("Packaging {0}", nsf); + + if (settings.NuGet.UpdateVersion) { + VersionUtils.UpdateNuSpecVersion(Context, settings, versionInfo, nsf.ToString()); + } + + if (settings.NuGet.UpdateLibraryDependencies) { + VersionUtils.UpdateNuSpecVersionDependency(Context, settings, versionInfo, nsf.ToString()); + } + + NuGetPack(nsf, new NuGetPackSettings { + Version = versionInfo.ToString(), + ReleaseNotes = versionInfo.ReleaseNotes, + Symbols = true, + Properties = nugetProps, + OutputDirectory = artifactsPath + }); + } +}); + +Task("Publish") + .Description("Publishes all of the nupkg packages to the nuget server. ") + .IsDependentOn("Package") + .Does(() => +{ + var authError = false; + + if (settings.NuGet.FeedApiKey.ToLower() == "local") + { + settings.NuGet.FeedUrl = Directory(settings.NuGet.FeedUrl).Path.FullPath; + //Information("Using Local repository: {0}", settings.NuGet.FeedUrl); + } + + Information("Publishing Packages from {0} to {1} for version {2}", settings.NuGet.ArtifactsPath, settings.NuGet.FeedUrl, versionInfo.ToString()); + + // Lets get the list of packages (we can skip anything that is not part of the current version being built) + var nupkgFiles = GetFiles(settings.NuGet.NuGetPackagesSpec).Where(x => x.ToString().Contains(versionInfo.ToString())).ToList(); + + Information("\t{0}", string.Join("\n\t", nupkgFiles.Select(x => x.GetFilename().ToString()).ToList())); + + foreach (var n in nupkgFiles) + { + try + { + NuGetPush(n, new NuGetPushSettings { + Source = settings.NuGet.FeedUrl, + ApiKey = settings.NuGet.FeedApiKey, + ConfigFile = settings.NuGet.NuGetConfig, + Verbosity = NuGetVerbosity.Normal + }); + } + catch (Exception ex) + { + Information("\tFailed to published: ", ex.Message); + + if (ex.Message.Contains("403")) { authError = true; } + } + } + + if (authError && settings.NuGet.FeedApiKey == "VSTS") + { + Warning("\tYou may need to Configuration Your Credentials.\r\n\t\tCredentialProvider.VSS.exe -Uri {0}", settings.NuGet.FeedUrl); + } +}); + +Task("UnPublish") + .Description("UnPublishes all of the current nupkg packages from the nuget server. Issue: versionToDelete must use : instead of . due to bug in cake") + .Does(() => +{ + var v = Argument("versionToDelete", versionInfo.ToString()).Replace(":","."); + + var nuspecFiles = GetFiles(settings.NuGet.NuSpecFileSpec); + foreach(var f in nuspecFiles) + { + Information("UnPublishing {0}", f.GetFilenameWithoutExtension()); + + var args = string.Format("delete {0} {1} -Source {2} -NonInteractive", + f.GetFilenameWithoutExtension(), + v, + settings.NuGet.FeedUrl + ); + + //if (settings.NuGet.FeedApiKey != "VSTS" ) { + args = args + string.Format(" -ApiKey {0}", settings.NuGet.FeedApiKey); + //} + + if (!string.IsNullOrEmpty(settings.NuGet.NuGetConfig)) { + args = args + string.Format(" -Config {0}", settings.NuGet.NuGetConfig); + } + + Information("NuGet Command Line: {0}", args); + using (var process = StartAndReturnProcess("tools\\nuget.exe", new ProcessSettings { + Arguments = args + })) + { + process.WaitForExit(); + Information("nuget delete exit code: {0}", process.GetExitCode()); + } + } +}); + +Task("UpdateVersion") + .Description("Updates the version number in the necessary files") + .Does(() => +{ + Information("Updating Version to {0}", versionInfo.ToString()); + + VersionUtils.UpdateVersion(Context, settings, versionInfo); +}); + +Task("IncrementVersion") + .Description("Increments the version number and then updates it in the necessary files") + .Does(() => +{ + var oldVer = versionInfo.ToString(); + if (versionInfo.IsPreRelease) versionInfo.PreRelease++; else versionInfo.Build++; + + Information("Incrementing Version {0} to {1}", oldVer, versionInfo.ToString()); + + RunTarget("UpdateVersion"); +}); + +Task("BuildNewVersion") + .Description("Increments and Builds a new version") + .IsDependentOn("IncrementVersion") + .IsDependentOn("Build") + .Does(() => +{ +}); + +Task("PublishNewVersion") + .Description("Increments, Builds, and publishes a new version") + .IsDependentOn("BuildNewVersion") + .IsDependentOn("Publish") + .Does(() => +{ +}); + +Task("DisplaySettings") + .Description("Displays All Settings.") + .Does(() => +{ + // Settings will be displayed as they are part of the Setup task +}); + +Task("DisplayHelp") + .Description("Displays All Settings.") + .Does(() => +{ + // Settings will be displayed as they are part of the Setup task + SettingsUtils.DisplayHelp(Context); +}); + +/////////////////////////////////////////////////////////////////////////////// +// TARGETS +/////////////////////////////////////////////////////////////////////////////// + +Task("Default") + .Description("This is the default task which will be ran if no specific target is passed in.") + .IsDependentOn("Build"); + +/////////////////////////////////////////////////////////////////////////////// +// EXECUTION +/////////////////////////////////////////////////////////////////////////////// + +RunTarget(settings.Target); \ No newline at end of file diff --git a/build.osx.sh b/build.osx.sh new file mode 100644 index 0000000..6e8f207 --- /dev/null +++ b/build.osx.sh @@ -0,0 +1,101 @@ +#!/usr/bin/env bash + +########################################################################## +# This is the Cake bootstrapper script for Linux and OS X. +# This file was downloaded from https://github.com/cake-build/resources +# Feel free to change this file to fit your needs. +########################################################################## + +# Define directories. +SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) +TOOLS_DIR=$SCRIPT_DIR/tools +NUGET_EXE=$TOOLS_DIR/nuget.exe +CAKE_EXE=$TOOLS_DIR/Cake/Cake.exe +PACKAGES_CONFIG=$TOOLS_DIR/packages.config +PACKAGES_CONFIG_MD5=$TOOLS_DIR/packages.config.md5sum + +# Define md5sum or md5 depending on Linux/OSX +MD5_EXE= +if [[ "$(uname -s)" == "Darwin" ]]; then + MD5_EXE="md5 -r" +else + MD5_EXE="md5sum" +fi + +# Define default arguments. +SCRIPT="build.cake" +TARGET="Default" +CONFIGURATION="Release" +VERBOSITY="verbose" +DRYRUN= +SHOW_VERSION=false +SCRIPT_ARGUMENTS=() + +# Parse arguments. +for i in "$@"; do + case $1 in + -s|--script) SCRIPT="$2"; shift ;; + -t|--target) TARGET="$2"; shift ;; + -c|--configuration) CONFIGURATION="$2"; shift ;; + -v|--verbosity) VERBOSITY="$2"; shift ;; + -d|--dryrun) DRYRUN="-dryrun" ;; + --version) SHOW_VERSION=true ;; + --) shift; SCRIPT_ARGUMENTS+=("$@"); break ;; + *) SCRIPT_ARGUMENTS+=("$1") ;; + esac + shift +done + +# Make sure the tools folder exist. +if [ ! -d "$TOOLS_DIR" ]; then + mkdir "$TOOLS_DIR" +fi + +# Make sure that packages.config exist. +if [ ! -f "$TOOLS_DIR/packages.config" ]; then + echo "Downloading packages.config..." + curl -Lsfo "$TOOLS_DIR/packages.config" http://cakebuild.net/download/bootstrapper/packages + if [ $? -ne 0 ]; then + echo "An error occured while downloading packages.config." + exit 1 + fi +fi + +# Download NuGet if it does not exist. +if [ ! -f "$NUGET_EXE" ]; then + echo "Downloading NuGet..." + curl -Lsfo "$NUGET_EXE" https://dist.nuget.org/win-x86-commandline/latest/nuget.exe + if [ $? -ne 0 ]; then + echo "An error occured while downloading nuget.exe." + exit 1 + fi +fi + +# Restore tools from NuGet. +pushd "$TOOLS_DIR" >/dev/null +if [ ! -f $PACKAGES_CONFIG_MD5 ] || [ "$( cat $PACKAGES_CONFIG_MD5 | sed 's/\r$//' )" != "$( $MD5_EXE $PACKAGES_CONFIG | awk '{ print $1 }' )" ]; then + find . -type d ! -name . | xargs rm -rf +fi + +mono "$NUGET_EXE" install -ExcludeVersion +if [ $? -ne 0 ]; then + echo "Could not restore NuGet packages." + exit 1 +fi + +$MD5_EXE $PACKAGES_CONFIG | awk '{ print $1 }' >| $PACKAGES_CONFIG_MD5 + +popd >/dev/null + +# Make sure that Cake has been installed. +if [ ! -f "$CAKE_EXE" ]; then + echo "Could not find Cake.exe at '$CAKE_EXE'." + exit 1 +fi + +# Start Cake +if $SHOW_VERSION; then + exec mono "$CAKE_EXE" -version +else + exec mono "$CAKE_EXE" $SCRIPT -verbosity=$VERBOSITY -configuration=$CONFIGURATION -target=$TARGET $DRYRUN "${SCRIPT_ARGUMENTS[@]}" +fi \ No newline at end of file diff --git a/build.ps1 b/build.ps1 index 9287953..dd0c32c 100644 --- a/build.ps1 +++ b/build.ps1 @@ -1,42 +1,189 @@ -Param( - [Parameter(Position=1,Mandatory=0)] - [string[]]$task_list = @(), +########################################################################## +# This is the Cake bootstrapper script for PowerShell. +# This file was downloaded from https://github.com/cake-build/resources +# Feel free to change this file to fit your needs. +########################################################################## + +<# + +.SYNOPSIS +This is a Powershell script to bootstrap a Cake build. + +.DESCRIPTION +This Powershell script will download NuGet if missing, restore NuGet tools (including Cake) +and execute your Cake build script with the parameters you provide. + +.PARAMETER Script +The build script to execute. +.PARAMETER Target +The build script target to run. +.PARAMETER Configuration +The build configuration to use. +.PARAMETER Verbosity +Specifies the amount of information to be displayed. +.PARAMETER Experimental +Tells Cake to use the latest Roslyn release. +.PARAMETER WhatIf +Performs a dry run of the build script. +No tasks will be executed. +.PARAMETER Mono +Tells Cake to use the Mono scripting engine. +.PARAMETER SkipToolPackageRestore +Skips restoring of packages. +.PARAMETER ScriptArgs +Remaining arguments are added here. + +.LINK +http://cakebuild.net + +#> - [Parameter()] - [string]$BuildMetaData +[CmdletBinding()] +Param( + [string]$Script = "build.cake", + [string]$Target = "Default", + [ValidateSet("Release", "Debug")] + [string]$Configuration = "Release", + [ValidateSet("Quiet", "Minimal", "Normal", "Verbose", "Diagnostic")] + [string]$Verbosity = "Verbose", + [switch]$Experimental, + [Alias("DryRun","Noop")] + [switch]$WhatIf, + [switch]$Mono, + [switch]$SkipToolPackageRestore, + [Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)] + [string[]]$ScriptArgs ) -$build_file = 'default.ps1' +[Reflection.Assembly]::LoadWithPartialName("System.Security") | Out-Null +function MD5HashFile([string] $filePath) +{ + if ([string]::IsNullOrEmpty($filePath) -or !(Test-Path $filePath -PathType Leaf)) + { + return $null + } + + [System.IO.Stream] $file = $null; + [System.Security.Cryptography.MD5] $md5 = $null; + try + { + $md5 = [System.Security.Cryptography.MD5]::Create() + $file = [System.IO.File]::OpenRead($filePath) + return [System.BitConverter]::ToString($md5.ComputeHash($file)) + } + finally + { + if ($file -ne $null) + { + $file.Dispose() + } + } +} + +Write-Host "Preparing to run build script..." + +if(!$PSScriptRoot){ + $PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent +} + +$TOOLS_DIR = Join-Path $PSScriptRoot "tools" +$NUGET_EXE = Join-Path $TOOLS_DIR "nuget.exe" +$CAKE_EXE = Join-Path $TOOLS_DIR "Cake/Cake.exe" +$NUGET_URL = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" +$PACKAGES_CONFIG = Join-Path $TOOLS_DIR "packages.config" +$PACKAGES_CONFIG_MD5 = Join-Path $TOOLS_DIR "packages.config.md5sum" -# Properties for the psake build script -$properties = @{ +# Should we use mono? +$UseMono = ""; +if($Mono.IsPresent) { + Write-Verbose -Message "Using the Mono based scripting engine." + $UseMono = "-mono" +} - # Build configuration to use - "configuration" = "Release"; +# Should we use the new Roslyn? +$UseExperimental = ""; +if($Experimental.IsPresent -and !($Mono.IsPresent)) { + Write-Verbose -Message "Using experimental version of Roslyn." + $UseExperimental = "-experimental" +} - # Version number to use if running the Publish build task. - # This will be read from the command line args - "version" = $version; +# Is this a dry run? +$UseDryRun = ""; +if($WhatIf.IsPresent) { + $UseDryRun = "-dryrun" +} - # Path to the solution file - "solution" = 'Nancy.CustomErrors.sln'; +# Make sure tools folder exists +if ((Test-Path $PSScriptRoot) -and !(Test-Path $TOOLS_DIR)) { + Write-Verbose -Message "Creating tools directory..." + New-Item -Path $TOOLS_DIR -Type directory | out-null +} - # Folder containing source code - "source_folder" = ''; +# Make sure that packages.config exist. +if (!(Test-Path $PACKAGES_CONFIG)) { + Write-Verbose -Message "Downloading packages.config..." + try { (New-Object System.Net.WebClient).DownloadFile("http://cakebuild.net/download/bootstrapper/packages", $PACKAGES_CONFIG) } catch { + Throw "Could not download packages.config." + } +} - # Folder to output deployable packages to. This folder should be ignored - # from any source control, as we dont commit build artifacts to source - # control - "deploy_folder" = 'deploy'; +# Try find NuGet.exe in path if not exists +if (!(Test-Path $NUGET_EXE)) { + Write-Verbose -Message "Trying to find nuget.exe in PATH..." + $existingPaths = $Env:Path -Split ';' | Where-Object { (![string]::IsNullOrEmpty($_)) -and (Test-Path $_ -PathType Container) } + $NUGET_EXE_IN_PATH = Get-ChildItem -Path $existingPaths -Filter "nuget.exe" | Select -First 1 + if ($NUGET_EXE_IN_PATH -ne $null -and (Test-Path $NUGET_EXE_IN_PATH.FullName)) { + Write-Verbose -Message "Found in PATH at $($NUGET_EXE_IN_PATH.FullName)." + $NUGET_EXE = $NUGET_EXE_IN_PATH.FullName + } +} - # Build number metadata that will be appended to semver numers - "build_meta" = $BuildMetaData; - - "projects" = @( - "Nancy.CustomErrors") +# Try download NuGet.exe if not exists +if (!(Test-Path $NUGET_EXE)) { + Write-Verbose -Message "Downloading NuGet.exe..." + try { + (New-Object System.Net.WebClient).DownloadFile($NUGET_URL, $NUGET_EXE) + } catch { + Throw "Could not download NuGet.exe." + } +} + +# Save nuget.exe path to environment to be available to child processed +$ENV:NUGET_EXE = $NUGET_EXE + +# Restore tools from NuGet? +if(-Not $SkipToolPackageRestore.IsPresent) { + Push-Location + Set-Location $TOOLS_DIR + # Check for changes in packages.config and remove installed tools if true. + [string] $md5Hash = MD5HashFile($PACKAGES_CONFIG) + if((!(Test-Path $PACKAGES_CONFIG_MD5)) -Or + ($md5Hash -ne (Get-Content $PACKAGES_CONFIG_MD5 ))) { + Write-Verbose -Message "Missing or changed package.config hash..." + Remove-Item * -Recurse -Exclude packages.config,nuget.exe,settingsUtils.cake,versionUtils.cake + } + + Write-Verbose -Message "Restoring tools from NuGet..." + $NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion -OutputDirectory `"$TOOLS_DIR`"" + + if ($LASTEXITCODE -ne 0) { + Throw "An error occured while restoring NuGet tools." + } + else + { + $md5Hash | Out-File $PACKAGES_CONFIG_MD5 -Encoding "ASCII" + } + Write-Verbose -Message ($NuGetOutput | out-string) + Pop-Location } -import-module .\packages\psake.4.4.2\tools\psake.psm1 +# Make sure that Cake has been installed. +if (!(Test-Path $CAKE_EXE)) { + Throw "Could not find Cake.exe at $CAKE_EXE" +} -invoke-psake $build_file $task_list -Properties $properties \ No newline at end of file +# Start Cake +Write-Host "Running build script..." +Invoke-Expression "& `"$CAKE_EXE`" `"$Script`" -target=`"$Target`" -configuration=`"$Configuration`" -verbosity=`"$Verbosity`" $UseMono $UseDryRun $UseExperimental $ScriptArgs" +exit $LASTEXITCODE \ No newline at end of file diff --git a/default.ps1 b/default.ps1 deleted file mode 100644 index f28e2e3..0000000 --- a/default.ps1 +++ /dev/null @@ -1,68 +0,0 @@ -properties { - $projects = $null - $configuration = "Release" - $source_folder = $null - $solution = $null - $build_meta = $null -} - -Task Default -Depends Build - -Task RestorePackages { - Exec { nuget restore -PackagesDirectory .\packages } -} - -Task Publish -Depends Package { - $version = getVersionBase - - $projects | % { - Get-ChildItem | Where-Object -FilterScript { - ($_.Name.Contains("$project.$version")) -and !($_.Name.Contains(".symbols")) -and ($_.Extension -eq '.nupkg') - } | % { - exec { nuget push $_.Fullname } - } - } -} - -Task Package -Depends Test { - $projects | % { - Get-ChildItem -Path "$_\*.csproj" | % { - exec { nuget pack -sym $_.Fullname -Prop Configuration=$configuration } - } - } -} - -Task Test -Depends Build { - Get-ChildItem $source_folder -Recurse -Include *Tests.csproj | % { - Exec { & ".\packages\xunit.runner.console.2.0.0\tools\xunit.console.exe" "$($_.DirectoryName)\bin\$configuration\$($_.BaseName).dll" } - } -} - -Task Build -Depends Clean,Set-Versions,RestorePackages { - Exec { msbuild "$solution" /t:Build /p:Configuration=$configuration } -} - -Task Clean { - Exec { msbuild "$solution" /t:Clean /p:Configuration=$configuration } -} - -Task Set-Versions { - $version = getVersionBase - - if ($build_meta) { - "##teamcity[buildNumber '$version+$build_meta']" | Write-Host - } else { - "##teamcity[buildNumber '$version']" | Write-Host - } - - Get-ChildItem -Recurse -Force | Where-Object { $_.Name -eq "AssemblyInfo.cs" } | ForEach-Object { - (Get-Content $_.FullName) | ForEach-Object { - ($_ -replace 'AssemblyVersion\(.*\)', ('AssemblyVersion("' + $version + '")')) -replace 'AssemblyFileVersion\(.*\)', ('AssemblyFileVersion("' + $version + '")') - } | Set-Content $_.FullName -Encoding UTF8 - } -} - -function getVersionBase { - $versionInfo = (Get-Content "version.json") -join "`n" | ConvertFrom-Json - "$($versionInfo.major).$($versionInfo.minor).$($versionInfo.patch)"; -} \ No newline at end of file diff --git a/nuspec/Nancy.CustomErrors.nuspec b/nuspec/Nancy.CustomErrors.nuspec index 16870ad..467e82d 100644 --- a/nuspec/Nancy.CustomErrors.nuspec +++ b/nuspec/Nancy.CustomErrors.nuspec @@ -4,12 +4,12 @@ Nancy.CustomErrors 2.0.0-pre01 Nancy Custom Errors - ravensorb - ravensorb + Brendan ravensorb + Brendan McMahon https://github.com/bernos/Nancy.CustomErrors Adds exception handling for cases when custom error views cannot be found false - Nancy Custom Errors + Simple custom error handling for Nancyfx projects Copyright 2017 Nancyfx @@ -22,6 +22,10 @@ + + + + diff --git a/settings.json b/settings.json new file mode 100644 index 0000000..3d57486 --- /dev/null +++ b/settings.json @@ -0,0 +1,37 @@ +{ + "version": { + "VersionFile": "./version.json", + "AssemblyInfoFile": "./Nancy.CustomErrors/Properties/AssemblyInfo.cs", + "LoadFrom": "versionfile", + "AutoIncrementVersion": false + }, + "build": { + "SourcePath": "./src", + "SolutionFileSpec": "./*.sln", + "TreatWarningsAsErrors": false + }, + "xamarin":{ + "EnableXamarinIOS": false, + "MacAgentIPAddress": "", + "MacAgentUserName": "", + "MacAgentUserPassword": "" + }, + "test": { + "SourcePath": "./tests", + "ResultsPath": "./artifacts", + "AssemblyFileSpec": "*.Tests.dll", + "Framework": "XUnit2" + }, + "nuget": { + "NuGetConfig": "./.nuget/NuGet.config", + "FeedUrl": "", + "FeedAPIKey": "", + "ArtifactsPath": "./artifacts/packages", + "NuspecPath": "./nuspec", + "UpdateVersion": true, + "UpdateLibraryDependencies": false, + "VersionDependencyForLibrary": "greaterthanorequal", + "LibraryNamespaceBase": "", + "LibraryMinVersionDependency": "" + } +} \ No newline at end of file diff --git a/src/AssemblyInfo.Shared.cs b/src/AssemblyInfo.Shared.cs new file mode 100644 index 0000000..b7c94c4 --- /dev/null +++ b/src/AssemblyInfo.Shared.cs @@ -0,0 +1,36 @@ +// *********************************************************************** +// +// Copyright (c) . All rights reserved. +// +// +// +// *********************************************************************** +// + +using System.Reflection; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyCompany("Brendan McMahon")] +[assembly: AssemblyProduct("Nancy.CustomErrors")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyConfiguration("")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +[assembly: AssemblyVersion("2.0.0")] +//[assembly: AssemblyFileVersion("2.0.0")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +//[assembly: ComVisible(false)] diff --git a/src/Nancy.CustomErrors.NetStandard1.6/Nancy.CustomErrors.NetStandard1.6.csproj b/src/Nancy.CustomErrors.NetStandard1.6/Nancy.CustomErrors.NetStandard1.6.csproj new file mode 100644 index 0000000..e5a42d3 --- /dev/null +++ b/src/Nancy.CustomErrors.NetStandard1.6/Nancy.CustomErrors.NetStandard1.6.csproj @@ -0,0 +1,15 @@ + + + + netstandard1.6 + Nancy.CustomErrors + Nancy.CustomErrors + + + + + + + + + \ No newline at end of file diff --git a/src/Nancy.CustomErrors.Shared/CustomErrors.cs b/src/Nancy.CustomErrors.Shared/CustomErrors.cs index 4601403..61253f7 100644 --- a/src/Nancy.CustomErrors.Shared/CustomErrors.cs +++ b/src/Nancy.CustomErrors.Shared/CustomErrors.cs @@ -12,7 +12,7 @@ public static CustomErrorsConfiguration Configuration get { return _configuration ?? (_configuration = new CustomErrorsConfiguration()); } } - public static void Enable(IPipelines pipelines, CustomErrorsConfiguration configuration, ISerializer serializer) + public static void Enable(IPipelines pipelines, CustomErrorsConfiguration configuration, ISerializer serializer) { if (pipelines == null) { diff --git a/src/Nancy.CustomErrors.Shared/Nancy.CustomErrors.Shared.projitems b/src/Nancy.CustomErrors.Shared/Nancy.CustomErrors.Shared.projitems index f8b5cab..01be28a 100644 --- a/src/Nancy.CustomErrors.Shared/Nancy.CustomErrors.Shared.projitems +++ b/src/Nancy.CustomErrors.Shared/Nancy.CustomErrors.Shared.projitems @@ -9,5 +9,12 @@ Nancy.CustomErrors.Shared + + + + + + + - + \ No newline at end of file diff --git a/src/Nancy.CustomErrors/Nancy.CustomErrors.csproj b/src/Nancy.CustomErrors/Nancy.CustomErrors.csproj index d8e0139..ba25d4e 100644 --- a/src/Nancy.CustomErrors/Nancy.CustomErrors.csproj +++ b/src/Nancy.CustomErrors/Nancy.CustomErrors.csproj @@ -36,7 +36,7 @@ - ..\packages\Nancy.2.0.0-clinteastwood\lib\net452\Nancy.dll + ..\..\packages\Nancy.2.0.0-clinteastwood\lib\net452\Nancy.dll @@ -47,18 +47,17 @@ - - - - - - - + + Properties\AssemblyInfo.Shared.cs + - + + Designer + + diff --git a/src/Nancy.CustomErrors/Properties/AssemblyInfo.cs b/src/Nancy.CustomErrors/Properties/AssemblyInfo.cs index 6459a65..662817a 100644 --- a/src/Nancy.CustomErrors/Properties/AssemblyInfo.cs +++ b/src/Nancy.CustomErrors/Properties/AssemblyInfo.cs @@ -7,11 +7,6 @@ // associated with an assembly. [assembly: AssemblyTitle("Nancy.CustomErrors")] [assembly: AssemblyDescription("Simple custom error handling for Nancyfx projects")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Brendan McMahon")] -[assembly: AssemblyProduct("Nancy.CustomErrors")] -[assembly: AssemblyCopyright("Copyright © 2014")] -[assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] // Setting ComVisible to false makes the types in this assembly not visible @@ -32,5 +27,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("2.0.0")] -[assembly: AssemblyVersion("2.0.0")] -[assembly: AssemblyFileVersion("2.0.0")] +//[assembly: AssemblyVersion("2.0.0")] +//[assembly: AssemblyFileVersion("2.0.0")] diff --git a/tests/Nancy.CustomErrors.Example/Nancy.CustomErrors.Example.csproj b/tests/Nancy.CustomErrors.Example/Nancy.CustomErrors.Example.csproj index 9502ce6..7476b1d 100644 --- a/tests/Nancy.CustomErrors.Example/Nancy.CustomErrors.Example.csproj +++ b/tests/Nancy.CustomErrors.Example/Nancy.CustomErrors.Example.csproj @@ -34,10 +34,10 @@ - ..\packages\Nancy.2.0.0-clinteastwood\lib\net452\Nancy.dll + ..\..\packages\Nancy.2.0.0-clinteastwood\lib\net452\Nancy.dll - ..\packages\Nancy.Hosting.Self.2.0.0-clinteastwood\lib\net452\Nancy.Hosting.Self.dll + ..\..\packages\Nancy.Hosting.Self.2.0.0-clinteastwood\lib\net452\Nancy.Hosting.Self.dll @@ -59,13 +59,13 @@ - + {cd7a7211-6563-499b-913d-8e5af649bfe7} Nancy.CustomErrors - +