From 083b18139a21e44d97586ef277ee6c7e91e86c32 Mon Sep 17 00:00:00 2001 From: Shannon Deminick Date: Tue, 25 Sep 2012 11:20:05 +0700 Subject: [PATCH] Adds code to RenderViewEngine to ensure the /Views folder exists and also that the razor web.config file exists there too. I've also added this web.config file to the sln so it should output in the build by default though it will still be created automatically if its not there. --- src/Umbraco.Web.UI/Umbraco.Web.UI.csproj | 2 +- src/Umbraco.Web.UI/Web.config | 503 ++++++++++++----------- src/Umbraco.Web/Mvc/RenderViewEngine.cs | 21 + src/Umbraco.Web/Mvc/Strings.Designer.cs | 78 ++++ src/Umbraco.Web/Mvc/Strings.resx | 124 ++++++ src/Umbraco.Web/Mvc/web.config.template | 58 +++ src/Umbraco.Web/Umbraco.Web.csproj | 10 + 7 files changed, 559 insertions(+), 237 deletions(-) create mode 100644 src/Umbraco.Web/Mvc/Strings.Designer.cs create mode 100644 src/Umbraco.Web/Mvc/Strings.resx create mode 100644 src/Umbraco.Web/Mvc/web.config.template diff --git a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj index 96bbeb685e..5e840610a5 100644 --- a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj +++ b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj @@ -1662,6 +1662,7 @@ + Web.Template.config Designer @@ -2195,7 +2196,6 @@ - diff --git a/src/Umbraco.Web.UI/Web.config b/src/Umbraco.Web.UI/Web.config index df98fa6eee..a860662208 100644 --- a/src/Umbraco.Web.UI/Web.config +++ b/src/Umbraco.Web.UI/Web.config @@ -1,249 +1,280 @@  - -
-
-
- -
- -
-
-
-
- - -
-
- - - - - - - - - + +
+ +
+
+ + +
+ + +
+
+
+
+ + + +
+
+ + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Umbraco.Web/Mvc/RenderViewEngine.cs b/src/Umbraco.Web/Mvc/RenderViewEngine.cs index 53de5e7180..2ebca40323 100644 --- a/src/Umbraco.Web/Mvc/RenderViewEngine.cs +++ b/src/Umbraco.Web/Mvc/RenderViewEngine.cs @@ -1,7 +1,9 @@ using System.Collections.Generic; +using System.IO; using System.Linq; using System.Web.Mvc; using Umbraco.Core; +using Umbraco.Core.IO; namespace Umbraco.Web.Mvc { @@ -31,6 +33,25 @@ namespace Umbraco.Web.Mvc AreaPartialViewLocationFormats = new string[] { }; AreaViewLocationFormats = new string[] { }; + + EnsureFolderAndWebConfig(); + } + + /// + /// Ensures that the correct web.config for razor exists in the /Views folder. + /// + private void EnsureFolderAndWebConfig() + { + var viewFolder = IOHelper.MapPath(Constants.ViewLocation); + //ensure the web.config file is in the ~/Views folder + Directory.CreateDirectory(viewFolder); + if (!File.Exists(Path.Combine(viewFolder, "web.config"))) + { + using (var writer = File.CreateText(Path.Combine(viewFolder, "web.config"))) + { + writer.Write(Strings.web_config); + } + } } public override ViewEngineResult FindView(ControllerContext controllerContext, string viewName, string masterName, bool useCache) diff --git a/src/Umbraco.Web/Mvc/Strings.Designer.cs b/src/Umbraco.Web/Mvc/Strings.Designer.cs new file mode 100644 index 0000000000..4848bc4806 --- /dev/null +++ b/src/Umbraco.Web/Mvc/Strings.Designer.cs @@ -0,0 +1,78 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.544 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Umbraco.Web.Mvc { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Strings { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Strings() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Umbraco.Web.Mvc.Strings", typeof(Strings).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to <?xml version="1.0"?> + /// + ///<configuration> + /// <configSections> + /// <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"> + /// <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" /> + /// <section name="page [rest of string was truncated]";. + /// + internal static string web_config { + get { + return ResourceManager.GetString("web_config", resourceCulture); + } + } + } +} diff --git a/src/Umbraco.Web/Mvc/Strings.resx b/src/Umbraco.Web/Mvc/Strings.resx new file mode 100644 index 0000000000..270e6fc616 --- /dev/null +++ b/src/Umbraco.Web/Mvc/Strings.resx @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + web.config.template;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8 + + \ No newline at end of file diff --git a/src/Umbraco.Web/Mvc/web.config.template b/src/Umbraco.Web/Mvc/web.config.template new file mode 100644 index 0000000000..4c30ef2275 --- /dev/null +++ b/src/Umbraco.Web/Mvc/web.config.template @@ -0,0 +1,58 @@ + + + + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 5c54122f58..7ce6953df8 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -271,6 +271,11 @@ + + True + True + Strings.resx + @@ -1959,6 +1964,7 @@ + Reference.map @@ -2096,6 +2102,10 @@ MSDiscoCodeGenerator Reference.cs + + ResXFileCodeGenerator + Strings.Designer.cs + database.ascx.cs Designer